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

ERROR: Invalid requirement: 'transformers[sentencepiece,torch]<4.26>=4.23.0': Expected end or semicolon (after version specifier) #812

Open
xkszltl opened this issue Jun 25, 2024 · 6 comments

Comments

@xkszltl
Copy link

xkszltl commented Jun 25, 2024

Context

This was initially filed to pip side for 24.1 and PEP440, and they mentioned it may be a packaging issue:

According to this issue it may be related to PEP508 as well?

Description

We found with pip 24.1 it rejects the multi-constraint version that was working a few days ago.
I don't know if this is the issue with PEP440 enforcement, but the error msg is certainly misleading.

Repro

Have transformers[sentencepiece,torch]<4.26>=4.23.0 in requirements.txt and python3 -m pip install -Ur requirements.txt.

@notatallshaw
Copy link
Member

Sorry, I wasn't clear on the pip issue, yes all requirements have to conform to PEP440 enforcement and that's why you have an error, because it doesn't conform, otherwise you wouldn't have an error.

but the error msg is certainly misleading

How exactly? As I posted over there, the error shows you exactly where the requirement is wrong.

@notatallshaw
Copy link
Member

notatallshaw commented Jun 25, 2024

Btw, for comparison, this is what pip gives as the error message (as provided by packaging):

ERROR: Invalid requirement: 'transformers[sentencepiece,torch]<4.26>=4.23.0': Expected end or semicolon (after version specifier)
    transformers[sentencepiece,torch]<4.26>=4.23.0
                                     ~~~~~^ (from line 1 of requirements.txt)

And this is what uv gives as the error (I think using pep440_rs):

error: Couldn't parse requirement in `requirements.txt` at position 0
  Caused by: after parsing '4.26', found '>=4.23.0', which is not part of a valid version
transformers[sentencepiece,torch]<4.26>=4.23.0
                                 ^^^^^^^^^^^^^

I do like uv's "after parsing", but I prefer packaging's arrow pointing to exactly where it failed.

@xkszltl
Copy link
Author

xkszltl commented Jun 25, 2024

  • Msg is correct about there's a "parsing error" and the error position, but that's not necessarily clear to the user as to why that's an error.
  • It does not provide migration suggestion on a commonly used pattern which was considered correct previously.
  • Msg asks for eol or semicolon, without covering the possibility of comma. The explicit 2-choice part implies there's no other choice and is confusing.

@notatallshaw
Copy link
Member

notatallshaw commented Jun 25, 2024

Previously wrote something, but realized there was an issue with it, so deleted it.

One data point that might be useful is the uv project, that apply "fixups" before parsing as pep440, I beleive they have done extensive checks, and often update based on user requirements. Perhaps someone could document these common patterns: https://github.com/astral-sh/uv/blob/ddacede7db4f0502c3e1430502baa77bdc71f088/crates/pypi-types/src/lenient_requirement.rs#L35-L72

It looks like they handle >=x<y, but not your case of <y>=x, and I don't see any user reports of this scenario.

@xkszltl
Copy link
Author

xkszltl commented Jun 25, 2024

Although they only comment about >=x<y, their code does not seem to care about the order. It looks more like simple dividing by operator and re-compose.

@brettcannon
Copy link
Member

Marking this as a feature request.

@xkszltl I edited one of your comments to come off as a bit nicer and less judgemental.

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

No branches or pull requests

3 participants