feat: parse `requirements.txt` with locally referenced packages
See original GitHub issueAs per issue https://github.com/CycloneDX/cyclonedx-python/issues/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)
Issue Analytics
- State:
- Created 2 years ago
- Comments:20 (13 by maintainers)
Top Results From Across the Web
API to parse requirements.txt for setup.py #1080 - GitHub
txt contains comments and references to other requirements files, which seem to be incompatible with install_requires (reference needed). It ...
Read more >Proper way to parse requirements file after pip upgrade to pip ...
First, I believe parsing requirements.txt from within setup.py is not a good idea. It should be the other way around, install_requires in ...
Read more >3. How to package a Python
It contains everything you need to know to create a Python package and can be used as a reference sheet when creating packages...
Read more >Manage dependencies using requirements.txt | IntelliJ IDEA ...
In the Package requirements file field, type the name of the requirements file or click the browse button and locate the desired file....
Read more >The Python Requirements File and How to Create it
It is a simple text file that saves a list of the modules and packages required by your project. By creating a Python...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey @mostafa - we’ve released
cyclonedx-python
3.0.0
today. Would be awesome to get a PR to move torequirements-parser
as you suggested.Thanks!
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 awith
statement that is a context manager and will close the file automatically, even if an exception occurs inside the body.