madpah / requirements-parser

A Pip requirements file parser.
https://requirements-parser.readthedocs.io
Apache License 2.0
128 stars 42 forks source link

-e in requirements.txt not handled properly #84

Closed szabgab closed 7 months ago

szabgab commented 1 year ago
>>> import requirements
>>> for req in requirements.parse("-e ."): print(req)
... 

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.9/site-packages/requirements/parser.py", line 87, in parse
    yield Requirement.parse(line)
  File "/usr/local/lib/python3.9/site-packages/requirements/requirement.py", line 251, in parse
    return cls.parse_editable(
  File "/usr/local/lib/python3.9/site-packages/requirements/requirement.py", line 157, in parse_editable
    assert local_match is not None, 'This should match everything'
AssertionError: This should match everything

Also

>> for req in requirements.parse("-e abc"): print(req)
... 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.9/site-packages/requirements/parser.py", line 87, in parse
    yield Requirement.parse(line)
  File "/usr/local/lib/python3.9/site-packages/requirements/requirement.py", line 251, in parse
    return cls.parse_editable(
  File "/usr/local/lib/python3.9/site-packages/requirements/requirement.py", line 157, in parse_editable
    assert local_match is not None, 'This should match everything'
AssertionError: This should match everything

The first example can be found in https://github.com/jerryjliu/llama_index and pip seems to allow https://pip.pypa.io/en/stable/reference/requirements-file-format/

simahawk commented 1 year ago

I have the same issue. In fact this REGEX does not cover the simplest case: -e path/to/package . Of course, in such case we cannot get metadata. However, all we need is the pkg name (last bit of the path).

g-carre commented 1 year ago

I would have proposed a different fix for this:

I believe the regular expression from https://github.com/madpah/requirements-parser/blob/1ce923617147dd984c280d56cb1f02fcd3589a7c/requirements/requirement.py#L41

should be corrected to LOCAL_REGEX = re.compile(r'^((?P<scheme>file)://)?(?P<path>[^#]+)(#(?P<fragment>\S+))?')