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

Pre-release dependencies breaking parsing #959

Closed
dbbvitor opened this issue Mar 23, 2023 · 5 comments
Closed

Pre-release dependencies breaking parsing #959

dbbvitor opened this issue Mar 23, 2023 · 5 comments

Comments

@dbbvitor
Copy link

Describe the bug

Trying to install a package with a pre-release dependency fails at parsing.

How to reproduce

  1. pipx install <some-package>
    Where some package have some pre-release dependency like kubernetes>=9.0.0a1.0
pipx install <some-package> --verbose
pipx >(setup:801): pipx version is 1.2.0
pipx >(setup:802): Default python interpreter is '/opt/homebrew/Cellar/pipx/1.2.0/libexec/bin/python3.11'
pipx >(package_name_from_spec:322): Determined package name: <some-package>
pipx >(package_name_from_spec:323): Package name determined in 0.0s
creating virtual environment...
pipx >(run_subprocess:173): running /opt/homebrew/Cellar/pipx/1.2.0/libexec/bin/python3.11 -m venv --without-pip /Users/bi002708/.local/pipx/venvs/<some-package>
pipx >(run_subprocess:173): running /Users/bi002708/.local/pipx/venvs/<some-package>/bin/python -c import sysconfig; print(sysconfig.get_path('purelib'))
pipx >(run_subprocess:173): running /Users/bi002708/.local/pipx/shared/bin/python -c import sysconfig; print(sysconfig.get_path('purelib'))
pipx >(run_subprocess:173): running /Users/bi002708/.local/pipx/venvs/<some-package>/bin/python --version
pipx >(_parsed_package_to_package_or_url:147): cleaned package spec: <some-package>
installing <some-package>...
pipx >(run_subprocess:173): running /Users/bi002708/.local/pipx/venvs/<some-package>/bin/python -m pip install <some-package>
pipx >(run_subprocess:173): running <fetch_info_in_venv commands>

pipx >(rmdir:55): removing directory /Users/bi002708/.local/pipx/venvs/<some-package>
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/pipx/1.2.0/libexec/lib/python3.11/site-packages/packaging/requirements.py", line 35, in __init__
    parsed = parse_requirement(requirement_string)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/pipx/1.2.0/libexec/lib/python3.11/site-packages/packaging/_parser.py", line 64, in parse_requirement
    return _parse_requirement(Tokenizer(source, rules=DEFAULT_RULES))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/pipx/1.2.0/libexec/lib/python3.11/site-packages/packaging/_parser.py", line 82, in _parse_requirement
    url, specifier, marker = _parse_requirement_details(tokenizer)
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/pipx/1.2.0/libexec/lib/python3.11/site-packages/packaging/_parser.py", line 120, in _parse_requirement_details
    specifier = _parse_specifier(tokenizer)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/pipx/1.2.0/libexec/lib/python3.11/site-packages/packaging/_parser.py", line 206, in _parse_specifier
    with tokenizer.enclosing_tokens("LEFT_PARENTHESIS", "RIGHT_PARENTHESIS"):
  File "/opt/homebrew/Cellar/python@3.11/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/contextlib.py", line 144, in __exit__
    next(self.gen)
  File "/opt/homebrew/Cellar/pipx/1.2.0/libexec/lib/python3.11/site-packages/packaging/_tokenizer.py", line 183, in enclosing_tokens
    self.raise_syntax_error(
  File "/opt/homebrew/Cellar/pipx/1.2.0/libexec/lib/python3.11/site-packages/packaging/_tokenizer.py", line 163, in raise_syntax_error
    raise ParserSyntaxError(
packaging._tokenizer.ParserSyntaxError: Expected closing RIGHT_PARENTHESIS
    kubernetes (>=9.0.0a1.0) ; extra == 'all_extras'
               ~~~~~~~~~~^

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

Traceback (most recent call last):
  File "/opt/homebrew/bin/pipx", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/opt/homebrew/Cellar/pipx/1.2.0/libexec/lib/python3.11/site-packages/pipx/main.py", line 863, in cli
    return run_pipx_command(parsed_pipx_args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/pipx/1.2.0/libexec/lib/python3.11/site-packages/pipx/main.py", line 214, in run_pipx_command
    return commands.install(
           ^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/pipx/1.2.0/libexec/lib/python3.11/site-packages/pipx/commands/install.py", line 60, in install
    venv.install_package(
  File "/opt/homebrew/Cellar/pipx/1.2.0/libexec/lib/python3.11/site-packages/pipx/venv.py", line 257, in install_package
    self._update_package_metadata(
  File "/opt/homebrew/Cellar/pipx/1.2.0/libexec/lib/python3.11/site-packages/pipx/venv.py", line 331, in _update_package_metadata
    venv_package_metadata = self.get_venv_metadata_for_package(
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/pipx/1.2.0/libexec/lib/python3.11/site-packages/pipx/venv.py", line 313, in get_venv_metadata_for_package
    venv_metadata = inspect_venv(
                    ^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/pipx/1.2.0/libexec/lib/python3.11/site-packages/pipx/venv_inspect.py", line 251, in inspect_venv
    app_paths_of_dependencies = _dfs_package_apps(
                                ^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/pipx/1.2.0/libexec/lib/python3.11/site-packages/pipx/venv_inspect.py", line 142, in _dfs_package_apps
    app_paths_of_dependencies = _dfs_package_apps(
                                ^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/pipx/1.2.0/libexec/lib/python3.11/site-packages/pipx/venv_inspect.py", line 121, in _dfs_package_apps
    dependencies = get_package_dependencies(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/pipx/1.2.0/libexec/lib/python3.11/site-packages/pipx/venv_inspect.py", line 54, in get_package_dependencies
    for req in map(Requirement, dist.requires or []):
  File "/opt/homebrew/Cellar/pipx/1.2.0/libexec/lib/python3.11/site-packages/packaging/requirements.py", line 37, in __init__
    raise InvalidRequirement(str(e)) from e
packaging.requirements.InvalidRequirement: Expected closing RIGHT_PARENTHESIS
    kubernetes (>=9.0.0a1.0) ; extra == 'all_extras'
               ~~~~~~~~~~^

Expected behavior

Pipx should not properly parse dependencies like >=9.0.0a1.0.

@dukecat0
Copy link
Member

Probably a duplicate of #924?

@uranusjr
Copy link
Member

uranusjr commented Mar 24, 2023

Seems to be the case. I tested and packaging 21.3 seems to parse this correctly. Reportedly packaging 23.0 also fixed this, see pypa/packaging#629

@uranusjr uranusjr closed this as not planned Won't fix, can't repro, duplicate, stale Mar 24, 2023
@dbbvitor
Copy link
Author

Sorry, I haven't found the #924 issue as the wording was a little different.

@uranusjr Is there something I can do to fix it? Or I need to wait for an update?

@uranusjr
Copy link
Member

Upgrade packaging in the pipx environment. How that can be done depends on how you installed pipx.

@dukecat0
Copy link
Member

I guess /opt/homebrew/Cellar/pipx/1.2.0/libexec/bin/python3.11 -m pip install -U packaging==23.0 should work.

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

3 participants