Open fraser-langton opened 1 week ago
Thanks for the issue!
I don't this this would work. Import Linter contracts aren't really about individual files (usually), they are more about the relationships between files.
Example: a contract specifies that blue
should not import green
, even indirectly. A change made to a different file could introduce a chain of imports between blue
and green
. So we'd need to check all files anyway. Does that make sense?
Out of interest, what problem are you trying to solve here? Is it speeding up the linter? If so I am actively working on rewriting much of it in Rust, which I hope will make a big impact.
Thanks for the prompt reply!
It would be for reviewing only files files changed in the PR, ie so the rules can be introduced so and no code violates the contracts in new PRs.
Similar to how you might introduce mypy but not for the entire repo to allow time to migrate/update code.
It's not a speed thing because as you say all the files need to be graphed to find chained dependencies
It would be for reviewing only files files changed in the PR, ie so the rules can be introduced so and no code violates the contracts in new PRs.
The way we achieve this at my workplace is by adding a list of ignored_imports
and then treating that as a burn down list which we're not allowed to grow. Could that work for you?
I can have stab at it if you want
I don't think it needs a contribution to Import Linter, you should just be able to use the project as-is. Let me know if you're unsure how!
Specify subset of files to run import-linter on
eg
lint-imports path/to/file_a.py path/to/file_b.py ...
Our pipelines all make use of git diff output to run checks ie
CHANGED_FILES=$(git diff --name-only $BITBUCKET_BRANCH..origin/$BITBUCKET_PR_DESTINATION_BRANCH | grep '.py$')
black, isort, mypy all accept that output as arguments eg
If this were to be added to import-linter, I think the goal would be to still calculate the entire import graph (grimp won't work well with partial modules) but only report on / fail on imports originating from
[files ...]
There needs to some translation between filepaths and import expressions then maybe some functions in helpers.py can filter out "ignored" like you can from the config?