seddonym / import-linter

Import Linter allows you to define and enforce rules for the internal and external imports within your Python project.
https://import-linter.readthedocs.io/
BSD 2-Clause "Simplified" License
683 stars 49 forks source link

Excluding tests directory from check #225

Open ashrub-holvi opened 5 months ago

ashrub-holvi commented 5 months ago

Hi! Thank you for cool project!

I am thinking about excluding test's directory from check because, at least on first steps, it's not that critical, tried to configure it in pre-commit hook

- repo: https://github.com/seddonym/import-linter/
  rev: "v2.0"
  hooks:
    - id: import-linter
      exclude: /tests/

but seems it doesn't work and probably it's expected as the tool is not file-based, is it possible to do now or, if not, do you have plans to implement something like that?

seddonym commented 5 months ago

Thanks for the issue! Could I clarify what you're expecting to happen? E.g. are you expecting the lint-imports command to behave differently, or do you want the command not to be called at all by precommit when you change something in the tests folder?

I'm guessing it's the first one - possibly the setting you're looking for is ignore_imports, see the docs.

ashrub-holvi commented 5 months ago

I would expect second - not checking excluded directories at all, because it probably will be too many imports to add to ignore_imports. I still have doubt about is it good idea or not, but at least on the first steps it will simplify introducing import-linter.

seddonym commented 5 months ago

it probably will be too many imports to add to ignore_imports

Ignored imports supports wildcards, so you would probably be able to achieve it with just a single line in your contract.

ashrub-holvi commented 5 months ago

it probably will be too many imports to add to ignore_imports

Ignored imports supports wildcards, so you would probably be able to achieve it with just a single line in your contract.

Yep, might be it will be enough, but I think it will ignore for all package's code, not for tests only.

ashrub-holvi commented 5 months ago

Although it might be possible to configure it separately for tests' dir, will need to try.