gauge-sh/tach

Cannot exclude sub-packages with a wildcard

glujan opened this issue · 4 comments

Hi! This tool looks very promising to my use case but I've stumbled upon what I believe is a bug.

I have a directory layout which looks similar to this one:

my_project/
├── package1
│   └── tests
└── package2
    └── tests

expect I have many more sub-packages. Let's say package1 cannot import anything from package2, but I want to allow all imports in every tests package. I provided the following values to the exclude setting in my tach.yml:

exclude:
- my_project/*/tests/
- tests

But tach is still reporting illegal imports from package2 in package1.tests.

This definitely looks like a bug, I'm looking into it now!

Can you try replacing my_project/*/tests with my_project/.*/tests? (adding a dot to the wildcard)

I think the issue here is we are assuming regex, which would mean your current pattern would match my_project////tests but not my_project/<anything>/tests.

I will add a task on my end to support file globbing, since it's a reasonable expectation that your pattern would work here. Thanks for raising this and let me know if the new pattern works for you!

Thanks for quick reply!

Yes, I thought exclude accepts globs the same way as for instance .gitignore. Documentation says:

exclude accepts a list of directory patterns to exclude from checking.

Provided example indeed uses a regex, I see it now, but one needs to read carefully:

exclude:
- .*__pycache__/

From my point of view, if it's clear from docs that exclude expects a path regex, it's all good!

Great, glad it worked! I will update the documentation to be more clear in the meantime.