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

Doesn't support local paths to wheels

Abierto
#26 0 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Python
Estrellas
20
Forks
13
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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)

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.