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

Some pre-release spellings cannot be used in requirements #653

Closed
di opened this issue Jan 5, 2023 · 2 comments
Closed

Some pre-release spellings cannot be used in requirements #653

di opened this issue Jan 5, 2023 · 2 comments

Comments

@di
Copy link
Member

di commented Jan 5, 2023

The following are valid versions:

>>> packaging.version.Version('1.0.0b1')
<Version('1.0.0b1')>
>>> packaging.version.Version('1.0.0-b1')
<Version('1.0.0b1')>
>>> packaging.version.Version('1.0.0-beta1')
<Version('1.0.0b1')>
>>> packaging.version.Version('1.0.0-beta.1')
<Version('1.0.0b1')>

The following are valid specifiers:

>>> packaging.specifiers.Specifier('>=1.0.0b1')
<Specifier('>=1.0.0b1')>
>>> packaging.specifiers.Specifier('>=1.0.0-b1')
<Specifier('>=1.0.0-b1')>
>>> packaging.specifiers.Specifier('>=1.0.0-beta1')
<Specifier('>=1.0.0-beta1')>
>>> packaging.specifiers.Specifier('>=1.0.0-beta.1')
<Specifier('>=1.0.0-beta.1')>

The following requirements work:

>>> packaging.requirements.Requirement("eth-utils<2.0.0,>=1.0.0b1")
<Requirement('eth-utils<2.0.0,>=1.0.0b1')>
>>> packaging.requirements.Requirement("eth-utils<2.0.0,>=1.0.0-b1")
<Requirement('eth-utils<2.0.0,>=1.0.0-b1')>

The following do not:

>>> packaging.requirements.Requirement("eth-utils<2.0.0,>=1.0.0-beta1")
Traceback (most recent call last):
  File "/home/di/.pyenv/versions/3.11.1/lib/python3.11/site-packages/packaging/requirements.py", line 35, in __init__
    parsed = parse_requirement(requirement_string)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/di/.pyenv/versions/3.11.1/lib/python3.11/site-packages/packaging/_parser.py", line 64, in parse_requirement
    return _parse_requirement(Tokenizer(source, rules=DEFAULT_RULES))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/di/.pyenv/versions/3.11.1/lib/python3.11/site-packages/packaging/_parser.py", line 82, in _parse_requirement
    url, specifier, marker = _parse_requirement_details(tokenizer)
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/di/.pyenv/versions/3.11.1/lib/python3.11/site-packages/packaging/_parser.py", line 122, in _parse_requirement_details
    marker = _parse_requirement_marker(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/di/.pyenv/versions/3.11.1/lib/python3.11/site-packages/packaging/_parser.py", line 143, in _parse_requirement_marker
    tokenizer.raise_syntax_error(
  File "/home/di/.pyenv/versions/3.11.1/lib/python3.11/site-packages/packaging/_tokenizer.py", line 161, in raise_syntax_error
    raise ParserSyntaxError(
packaging._tokenizer.ParserSyntaxError: Expected end or semicolon (after version specifier)
    eth-utils<2.0.0,>=1.0.0-beta1
             ~~~~~~~~~~~~~~~~^

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/di/.pyenv/versions/3.11.1/lib/python3.11/site-packages/packaging/requirements.py", line 37, in __init__
    raise InvalidRequirement(str(e)) from e
packaging.requirements.InvalidRequirement: Expected end or semicolon (after version specifier)
    eth-utils<2.0.0,>=1.0.0-beta1
             ~~~~~~~~~~~~~~~~^
>>> packaging.requirements.Requirement("eth-utils<2.0.0,>=1.0.0-beta.1")
Traceback (most recent call last):
  File "/home/di/.pyenv/versions/3.11.1/lib/python3.11/site-packages/packaging/requirements.py", line 35, in __init__
    parsed = parse_requirement(requirement_string)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/di/.pyenv/versions/3.11.1/lib/python3.11/site-packages/packaging/_parser.py", line 64, in parse_requirement
    return _parse_requirement(Tokenizer(source, rules=DEFAULT_RULES))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/di/.pyenv/versions/3.11.1/lib/python3.11/site-packages/packaging/_parser.py", line 82, in _parse_requirement
    url, specifier, marker = _parse_requirement_details(tokenizer)
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/di/.pyenv/versions/3.11.1/lib/python3.11/site-packages/packaging/_parser.py", line 122, in _parse_requirement_details
    marker = _parse_requirement_marker(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/di/.pyenv/versions/3.11.1/lib/python3.11/site-packages/packaging/_parser.py", line 143, in _parse_requirement_marker
    tokenizer.raise_syntax_error(
  File "/home/di/.pyenv/versions/3.11.1/lib/python3.11/site-packages/packaging/_tokenizer.py", line 161, in raise_syntax_error
    raise ParserSyntaxError(
packaging._tokenizer.ParserSyntaxError: Expected end or semicolon (after version specifier)
    eth-utils<2.0.0,>=1.0.0-beta.1
             ~~~~~~~~~~~~~~~~^

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/di/.pyenv/versions/3.11.1/lib/python3.11/site-packages/packaging/requirements.py", line 37, in __init__
    raise InvalidRequirement(str(e)) from e
packaging.requirements.InvalidRequirement: Expected end or semicolon (after version specifier)
    eth-utils<2.0.0,>=1.0.0-beta.1
             ~~~~~~~~~~~~~~~~^

This is true for alpha, beta, and preview but not other pre-release spellings specified in PEP 440.

@pradyunsg
Copy link
Member

Duplicate of #629

@pradyunsg pradyunsg marked this as a duplicate of #629 Jan 5, 2023
@di
Copy link
Member Author

di commented Jan 5, 2023

Ah, thanks. I saw that had been merged but missed that it hadn't been released and hadn't looked closely enough.

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

No branches or pull requests

2 participants