Packages having a name starting with "http" are interpreted as URL and incorrrectly parsed from requirements.txt
mmtevelde opened this issue · 0 comments
Describe the bug
My project uses requirements.txt to define dependencies. We use the httpx
library. When running deptry, it incorrectly parses this entry as a dependency specified from URL:
$ grep httpx requirements.txt
httpx==0.25.2
$ pre-commit run --all-files
Could not parse dependency name from url httpx==0.25.2
The dependency parser incorrectly interprets the line as containing a URL.
Subsequently it throws a DEP003 because the dependency is imported but not detected as being specified in the requirements.txt (even though it is there): sample.py:1:0: DEP003 'httpx' imported but it is a transitive dependency
.
As a workaround, I have added an ignore to my pyproject.toml:
[tool.deptry.per_rule_ignores]
DEP003 = ["httpx"]
I think a fix would be to improve the _line_is_url
function or its regex here
Maybe changing the matcher from http|https
to http://|https://
would fix the problem without impacting the intended functionality.
To Reproduce
Steps to reproduce the behavior:
- Specify requirements.txt dependency starting with http
- Optional - Import this dependency somewhere in your code
- Run deptry
Expected behavior
System [please complete the following information]:
- OS: macOS Sonoma
- Language Version: Python 3.11
- Poetry version: N/A, using pip
Additional context
N/A