exclude config option in pyproject.toml can't reach sub directories
ariffjeff opened this issue · 4 comments
Describe the bug
Context: this is a potential bug I found after creating a project with cookiecutter-poetry
I am simply trying to get deptry (via make check
) to ignore a sub directory in my project when doing a check because it has some python files in it that are just learning material that aren't really a part of the project in any way, but I need them to be there for convenience. I have referenced the documentation directly to try to ignore sub folders but I can't seem to get it to work.
When trying to match sub directories with the exclude
config option under [tool.deptry]
in pyproject.toml
, they will not be recognized when poetry run deptry .
is run.
To Reproduce
With a project directory like this...
/my-project
/my_project
/subdir
/x.py
/y.py
/pyproject.toml
and with this in pyproject.toml
...
[tool.deptry]
exclude = ["my_project/subdir"]
...and where x.py
is importing y.py
with something like from y import ...
(this import obviously isn't going to be listed in pyproject.toml as a dependency, which is causing deptry to recognize this as a missing dependency, which is probably a bug in and of itself?)
... and then doing poetry run deptry .
will always produce this warning:
There are dependencies missing from the project's list of dependencies:
y
Consider adding them to your project's dependencies.
...
Expected behavior
I am expecting to run poetry run deptry .
and ultimately get Success! No dependency issues found.
... and I can actually get this to occur if I do the CLI version poetry run deptry . --exclude "my_project\\subdir"
which works successfully.
... or it works if do this: I change the info in pyproject.toml
from exclude = ["my_project/subdir"]
to exclude = ["my_project"]
which predictable and successfully ignores that whole folder, but of course it doesn't isolate just /subdir
which is what I want.
So I'm not sure if this is a bug or I'm just entering in the wrong string into exclude = ...
I have tried various combinations of relative paths for /subdir
but none of them get recognized when running poetry run deptry .
. deptry always detects missing dependencies.
System
- OS: Windows 10
- Language Version: Python 3.11.2
- Poetry version: Poetry 1.3.2
Additional context
Hi @ariffjeff, thanks for raising the issue! I tried to reproduce it locally, but I was unsuccessful. Can you try running
poetry run deptry . --exclude my_project/subdir
If that does not work, maybe you could create an example repository, so I can investigate further. Thanks!
@fpgmaas Thanks for responding.
I just tried that command and I am still getting the same issue of y
being detected as a missing dependency, although this time deptry also scans all 2211 files that get installed by cookiecutter-poetry since im assuming --exclude
is overwriting the pre config'ed command.
So I switched to poetry run deptry . --extend-exclude my_project/subdir
and I get the same error but just for y
like I was initially.
I've created an example repo here for you to take a look at where you can just run poetry run deptry .
. Please let me know what I've messed up. Much appreciated, thank you!
https://github.com/ariffjeff/my_project
All I've done is go through ccp
, push to a new remote repo, then push the two latest commits of the .py files and the deptry config change.
Thanks for creating the example repository! It is good practice to use absolute imports. So the import statement should be:
from my_project.subdir.y import thing
Then it should work as expected. Hope this helps!