aboutcode-org / aboutcode-org/pip-requirements-parser

Doesn't support local paths to wheels

オープン
#26 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Python
スター
20
フォーク
13
PR マージ指標
30日以内にマージされた PR はありません

説明

If a requirements.txt file contains a local path with "/", `requirements.parse` throws rather than parsing it as a local path. Here's a complete example showing that this is a valid file that works with pip:

```
$ python3.11 -m venv test-venv
$ ./test-venv/bin/pip download humanize
Collecting humanize
Using cached humanize-4.14.0-py3-none-any.whl.metadata (7.8 kB)
Using cached humanize-4.14.0-py3-none-any.whl (132 kB)
Saved ./humanize-4.14.0-py3-none-any.whl
Successfully downloaded humanize
$ echo ./humanize-4.14.0-py3-none-any.whl > req.txt
$ ./test-venv/bin/pip install -r req.txt
Processing ./humanize-4.14.0-py3-none-any.whl (from -r req.txt (line 1))
Installing collected packages: humanize
Successfully installed humanize-4.14.0
$ ./test-venv/bin/python -c 'import humanize'
$ ./test-venv/bin/pip install requirements-parser==0.13.0
Collecting requirements-parser==0.13.0
Using cached requirements_parser-0.13.0-py3-none-any.whl.metadata (4.7 kB)
Collecting packaging>=23.2 (from requirements-parser==0.13.0)
Using cached packaging-25.0-py3-none-any.whl.metadata (3.3 kB)
Using cached requirements_parser-0.13.0-py3-none-any.whl (14 kB)
Using cached packaging-25.0-py3-none-any.whl (66 kB)
Installing collected packages: packaging, requirements-parser
Successfully installed packaging-25.0 requirements-parser-0.13.0
$ cat < test.py
import sys
import requirements

with open(sys.argv[1]) as f:
for r in requirements.parse(f):
print(r)
EOF
$ ./test-venv/bin/python test.py req.txt
Traceback (most recent call last):
File "/Users/dborowitz/w/test-venv/lib/python3.11/site-packages/packaging/requirements.py", line 36, in __init__
parsed = _parse_requirement(requirement_string)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/dborowitz/w/test-venv/lib/python3.11/site-packages/packaging/_parser.py", line 62, in parse_requirement
return _parse_requirement(Tokenizer(source, rules=DEFAULT_RULES))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/dborowitz/w/test-venv/lib/python3.11/site-packages/packaging/_parser.py", line 71, in _parse_requirement
name_token = tokenizer.expect(
^^^^^^^^^^^^^^^^^
File "/Users/dborowitz/w/test-venv/lib/python3.11/site-packages/packaging/_tokenizer.py", line 143, in expect
raise self.raise_syntax_error(f"Expected {expected}")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/dborowitz/w/test-venv/lib/python3.11/site-packages/packaging/_tokenizer.py", line 168, in raise_syntax_error
raise ParserSyntaxError(
packaging._tokenizer.ParserSyntaxError: Expected package name at the start of dependency specifier
./humanize-4.14.0-py3-none-any.whl
^

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/Users/dborowitz/w/test.py", line 5, in
for r in requirements.parse(f):
File "/Users/dborowitz/w/test-venv/lib/python3.11/site-packages/requirements/parser.py", line 90, in parse
yield Requirement.parse(line)
^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/dborowitz/w/test-venv/lib/python3.11/site-packages/requirements/requirement.py", line 274, in parse
return cls.parse_line(line)
^^^^^^^^^^^^^^^^^^^^
File "/Users/dborowitz/w/test-venv/lib/python3.11/site-packages/requirements/requirement.py", line 240, in parse_line
pkg_req = Req(line_without_comment)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/dborowitz/w/test-venv/lib/python3.11/site-packages/packaging/requirements.py", line 38, in __init__
raise InvalidRequirement(str(e)) from e
packaging.requirements.InvalidRequirement: Expected package name at the start of dependency specifier
./humanize-4.14.0-py3-none-any.whl
^
```

* requirements-parser version: 0.13.0
* OS: macOS 26
* Python: 3.11.14 (Homebrew)

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。