Repository navigation
Closed
Labels
enhancementNew feature or request
Description
As per issue #284 raised by @Jonas-vdb.
Some development teams add local references to other packages in their requirements.txt files. This is currently causing an exception:
Traceback (most recent call last):
File "/home/jvdb/repos/venv-tmp/lib/python3.6/site-packages/pkg_resources/_vendor/packaging/requirements.py", line 98, in __init__
req = REQUIREMENT.parseString(requirement_string)
File "/home/jvdb/repos/venv-tmp/lib/python3.6/site-packages/pkg_resources/_vendor/pyparsing.py", line 1654, in parseString
raise exc
File "/home/jvdb/repos/venv-tmp/lib/python3.6/site-packages/pkg_resources/_vendor/pyparsing.py", line 1644, in parseString
loc, tokens = self._parse( instring, 0 )
File "/home/jvdb/repos/venv-tmp/lib/python3.6/site-packages/pkg_resources/_vendor/pyparsing.py", line 1402, in _parseNoCache
loc,tokens = self.parseImpl( instring, preloc, doActions )
File "/home/jvdb/repos/venv-tmp/lib/python3.6/site-packages/pkg_resources/_vendor/pyparsing.py", line 3417, in parseImpl
loc, exprtokens = e._parse( instring, loc, doActions )
File "/home/jvdb/repos/venv-tmp/lib/python3.6/site-packages/pkg_resources/_vendor/pyparsing.py", line 1402, in _parseNoCache
loc,tokens = self.parseImpl( instring, preloc, doActions )
File "/home/jvdb/repos/venv-tmp/lib/python3.6/site-packages/pkg_resources/_vendor/pyparsing.py", line 3739, in parseImpl
return self.expr._parse( instring, loc, doActions, callPreParse=False )
File "/home/jvdb/repos/venv-tmp/lib/python3.6/site-packages/pkg_resources/_vendor/pyparsing.py", line 1402, in _parseNoCache
loc,tokens = self.parseImpl( instring, preloc, doActions )
File "/home/jvdb/repos/venv-tmp/lib/python3.6/site-packages/pkg_resources/_vendor/pyparsing.py", line 3400, in parseImpl
loc, resultlist = self.exprs[0]._parse( instring, loc, doActions, callPreParse=False )
File "/home/jvdb/repos/venv-tmp/lib/python3.6/site-packages/pkg_resources/_vendor/pyparsing.py", line 1406, in _parseNoCache
loc,tokens = self.parseImpl( instring, preloc, doActions )
File "/home/jvdb/repos/venv-tmp/lib/python3.6/site-packages/pkg_resources/_vendor/pyparsing.py", line 2711, in parseImpl
raise ParseException(instring, loc, self.errmsg, self)
pkg_resources._vendor.pyparsing.ParseException: Expected W:(abcd...) (at char 0), (line:1, col:1)
Metadata
Metadata
Labels
enhancementNew feature or request
Activity
madpah commentedon Dec 15, 2021
Root Cause:
pkg_resourcesagain does not support parsing requirements of this format (similar to requirements with hashes included) - see here.Also - worth stating that given the example provided, we will not be able to determine the version for any locally referenced requirements through a
requirements.txtmethod. Other methods such asEnvironmentParserwould pick them up.test: added test to prove issue #96
jkowalleck commentedon Dec 20, 2021
@madpah i dont see an actual urge for this feature, and i dont see it as a bug.
relative paths are not to be expected to be output of
pip freezebut it is a convenient feature, no doubt.
madpah commentedon Dec 21, 2021
I agree @jkowalleck - will remove the bug label.
mostafa commentedon Feb 17, 2022
@madpah
I was thinking about making a PR to replace
pkg_resourceswith requirements-parser because the latter can parse all sorts of requirements. WDYT?madpah commentedon Feb 18, 2022
Hey @mostafa - thanks for getting involved.
This was absolutely my plan. However, since this ticket was created, the logic/classes that use
pkg_resourcesnow live in an upstream projectcyclonedx-python- so I'll first relocate this issue (back) there.Would be great to get a PR from you to make this change, but worth nothing we have a large(ish) release due to land probably next week now, so you might want to wait until that is merged before you branch.
madpah commentedon Feb 18, 2022
This issue was moved back to
cyclonedx-pythonas since version2.0.0ofcyclonedx-python-lib, Python specific parsers now reside incyclonedx-pythonproject.mostafa commentedon Feb 18, 2022
Perfect! Just give me a nod when you release next week. Alternatively, I can start working on the feature off the branch you want to merge and then rebase from the default branch after merging. Up to you! 🙂
madpah commentedon Feb 21, 2022
Hey @mostafa - we've released
cyclonedx-python3.0.0today. Would be awesome to get a PR to move torequirements-parseras you suggested.Thanks!
1 remaining item
madpah commentedon Feb 22, 2022
@mostafa - not aware of this issue, and concerned as tests are passing in CI too. If you can raise an Issue for this, I’ll investigate later today.
Thanks again 🙏
madpah commentedon Feb 22, 2022
Tests passing here: https://github.com/CycloneDX/cyclonedx-python/runs/5277735507?check_suite_focus=true
mostafa commentedon Feb 22, 2022
@madpah I saw the passing tests, which is why I am confused, but I'll create a separate issue for it.
mostafa commentedon Feb 22, 2022
@madpah It's a dependency issue on my machine. So, my bad. 🤦
llamahunter commentedon Feb 22, 2022
We don't have locally referenced packages, but we do have a private pypi repo, and it appears that the
pkg_resourceslibrary simply isn't up to the task of parsing a full piprequirements.txtfile, including the--index-urldirectives.#318
jkowalleck commentedon Feb 23, 2022
Tool might not supports all the features people use in their
requirements.txt.the capability is a file that is created by
pip freeze. @llamahunterplease open another issue, if you want to request another feature for the requirements parser.
this issue is about local packages.
[-]Support for locally referenced packages in `requirements.txt`[/-][+]feat: `requirements.txt` with locally referenced packages[/+][-]feat: `requirements.txt` with locally referenced packages[/-][+]feat: parse `requirements.txt` with locally referenced packages[/+]mostafa commentedon Feb 23, 2022
@madpah @jkowalleck
I had some issues with a test (
test_example_multiline_with_comments) not passing after using the requirements-parser project because it doesn't support either the hashes or multiline requirements (either or both) and I found that there's a more mature alternative, the pip-requirements-parser. WDYT? As you're the maintainer/developer, do you strictly want to use and develop therequirements-parserpackage?Also, the
pip-requirements-parserpackage has only one API, which isRequirementsFile.from_file, and if we want to parse requirements file as a string, we need to make our own API using internal APIs of the package or get rid of our string processing altogether.jkowalleck commentedon Feb 23, 2022
just for the record: I do not have any opinion about a particular requirements-file-parser. Unlike @madpah I never dug deep into this topic.
regarding
For string input we could create a temp file and run
RequirementsFile.parse/RequirementsFile.from_fileon the temp file withinclude_nested=False, as all relative paths would be bare assumptions out of thin air based on current working dir and stuff.For direct file input we would set
include_nested=true, as relative paths from that file could be resolved.llamahunter commentedon Feb 23, 2022
I already did. See my post above and #318
jkowalleck commentedon Feb 23, 2022
for discussions, feel free to switch to #319
mostafa commentedon Feb 23, 2022
One more thing that's definitely off-topic:
I see lots of
<file>.close()lines throughout the project inside context managers, which is redundant because the file itself is actually being opened inside the body of awithstatement that is a context manager and will close the file automatically, even if an exception occurs inside the body.