Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comment in requirements file cause failed check #5

Open
janusheide opened this issue Oct 7, 2020 · 4 comments
Open

Comment in requirements file cause failed check #5

janusheide opened this issue Oct 7, 2020 · 4 comments
Assignees
Labels

Comments

@janusheide
Copy link

Checking a requirements file with a comment (e.g. #comment) causes the following error:

not enough values to unpack (expected 1, got 0)

Comments should be allowed according to this:
https://pip.pypa.io/en/latest/reference/pip_install/#requirements-file-format

And it looks like the official example files also currently fails
https://pip.pypa.io/en/latest/reference/pip_install/#example-requirements-file

@cjwelborn
Copy link
Member

You are totally correct. I haven't been working on my projects lately. I see that some of them are starting to show their age. I'll see what I can do this week to rectify some of that. Also, I always accept pull requests that don't break backward compatibility. Thank you for the report.

@cjwelborn cjwelborn self-assigned this Jan 24, 2021
@cjwelborn cjwelborn added the bug label Jan 24, 2021
@janusheide
Copy link
Author

Thanks! Will keep that in mind.

@cjwelborn
Copy link
Member

I managed to look into this today, and it seems the problem is in requirements-parser itself (not mine). If i have time I will see what I can do to fix it. This is the actual traceback:

Traceback (most recent call last):                                                                                                                                          
  File "/home/cj/scripts/requirementz/requirementz/__main__.py", line 275, in entry_point                                                                                   
    mainret = main(docopt(USAGESTR, version=VERSIONSTR, script=SCRIPT))                                                                                                     
  File "/home/cj/scripts/requirementz/requirementz/__main__.py", line 175, in main                                                                                          
    location=argd['--location'],                                                                                                                                            
  File "/home/cj/scripts/requirementz/requirementz/__main__.py", line 225, in check_requirements                                                                            
    reqs = Requirementz.from_file(filename=filename)                                                                                                                        
  File "/home/cj/scripts/requirementz/requirementz/tools.py", line 543, in from_file                                                                                        
    reqs = cls.from_lines(f.readlines())                                                                                                                                    
  File "/home/cj/scripts/requirementz/requirementz/tools.py", line 553, in from_lines                                                                                       
    for l in sorted(lines) if l.strip()                                                                                                                                     
  File "/home/cj/scripts/requirementz/requirementz/tools.py", line 482, in __init__                                                                                         
    super(Requirementz, self).__init__(requirements or tuple())                                                                                                             
  File "/usr/lib/python3.6/collections/__init__.py", line 1039, in __init__                                                                                                 
    self.data = list(initlist)                                                                                                                                              
  File "/home/cj/scripts/requirementz/requirementz/tools.py", line 553, in <genexpr>                                                                                        
    for l in sorted(lines) if l.strip()                                                                                                                                     
  File "/home/cj/.local/lib/python3.6/site-packages/requirements/requirement.py", line 220, in parse                                                                        
    return cls.parse_line(line)                                                                                                                                             
  File "/home/cj/.local/lib/python3.6/site-packages/requirements/requirement.py", line 198, in parse_line                                                                   
    pkg_req = Req.parse(line)                                                                                                                                               
  File "/usr/local/lib/python3.6/dist-packages/pkg_resources/__init__.py", line 3155, in parse                                                                              
    req, = parse_requirements(s)                                                                                                                                            
ValueError: not enough values to unpack (expected 1, got 0)

I'm depending on requirements-parser to do the actual parsing, so I may end up having to drop that dependency.

@janusheide
Copy link
Author

Thanks for having a look, yes it does appear that requirements-parser have a problem and its not likely that it will get updated, but you can of course ask the maintainer :)

I also regularly use a tool called "pur" https://pypi.org/project/pur/ but it seems they implemented their own parser
https://github.com/alanhamlett/pip-update-requirements/blob/master/pur/packages/pip/_internal/cli/parser.py

You could also consider creating a new file object in memory and just strip all comment lines, not exactly elegant approach but easy and should fix the problem for now. But personally I dont like to depend on unmaintained projects, its just pushing some unavoidable work ahead of you.

I also had a quick look in pip
https://github.com/pypa/pip/blob/7ec0fa5142466f8402bb866a1dcfb8ca6ffdc66b/src/pip/_vendor/pkg_resources/__init__.py#L3075
kinda a funny, they also just drop comment lines... ane then processed to make a call that their documentation says they should not make, and its in all caps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants