I’m working on a plugin for `import-linter` , and ...
# development
s
I’m working on a plugin for
import-linter
, and trying to debug rule graph errors in the integration tests. I basically copy-paste-adjusted the setups from
mypy
and
flake8
to set things up. the errors I’m seeing look like:
Copy code
No source of dependency ImportLinter for @rule(pants.backend.python.lint.import_linter.rules:88:import_linter_lint_partition(ImportLinterPartition, ImportLinterConfigFile, ImportLinterCustomContracts, ImportLinter) -> LintResult, gets=[Get(PythonSourceFiles, PythonSourceFilesRequest), Get(Pex, RequirementsPexRequest), Get(VenvPex, PexRequest), Get(Digest, MergeDigests), Get(FallibleProcessResult, VenvPexProcess)]). All potential sources were eliminated: []
there’s a separate error like ^^^ for every input type to
import_linter_lint_partition
. the stacktrace is coming out of my
pytest.fixture
for setting up a rule runner:
Copy code
@pytest.fixture
def rule_runner() -> RuleRunner:
    return RuleRunner(
        rules=[
            *import_linter_rules(),
            *import_linter_subsystem_rules(),
            *dependency_inference_rules.rules(),
            *config_files.rules(),
            *target_types_rules.rules(),
            QueryRule(LintResults, [ImportLinterRequest]),
        ],
        target_types=[PythonSourcesGeneratorTarget, PythonRequirementTarget, PythonSourceTarget],
    )
any tips to help me debug what’s wrong with the setup? I keep wondering if the empty array in
All potential sources were eliminated: []
is a sign that the rules aren’t getting collected properly
w
and
ImportLinter
is a subsystem that you’re expecting to be able to consume? is it registered with
SubsystemRule
…? that’s sometimes necessary when it’s in its own file.
s
yes, it’s the new subsystem I’m adding for the plugin. will check that
SubsystemRule
👀
w
yea, there is some (annoying) magic around subsystems. they’re supposed to be registered if they’re in the argument list of a
@rule
without the
SubsystemRule
, but that can fail
but, to be clear: rule graph error messages are terrible right now, so that might be a red herring. if you post a draft i can take a look.
👍 1
s
I think it might be a bigger-picture problem because there are a handful of other errors, including for types that pre-exist my changes (i.e.
Get(VenvPex, PexRequest)
). will make the draft
w
(this confusingly named ticket covers improving rule graph error messages: https://github.com/pantsbuild/pants/issues/11269)
👀 1
s
I did my best to extract the relevant patterns from the
mypy
and
flake8
plugins - if you see any puzzling choices in the draft, it’s likely caused by me not quite knowing what I’m doing 🙂
w
there were some missing dependency rules: have pushed a fix. sorry for the trouble there. will definitely be working on the errors before stabilization
s
Thank you!