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

pipx --preinstall ignores dependency version specifier #1377

Closed
davidpeckham opened this issue Apr 26, 2024 · 2 comments · Fixed by #1379
Closed

pipx --preinstall ignores dependency version specifier #1377

davidpeckham opened this issue Apr 26, 2024 · 2 comments · Fixed by #1379
Labels
bug Something isn't working

Comments

@davidpeckham
Copy link
Contributor

davidpeckham commented Apr 26, 2024

When I use pipx --preinstall to install a specific version of a dependency before installing the main package, pipx installs the latest version of the dependency instead.

How to reproduce

Ask pipx to install a dependency with a specific version before installing the main package:

% pipx install --preinstall virtualenv==20.25.3 tox --verbose
pipx >(setup:924): pipx version is 1.5.0
pipx >(setup:925): Default python interpreter is '/Library/Frameworks/Python.framework/Versions/3.11/bin/python3'
pipx >(package_name_from_spec:379): Determined package name: tox
pipx >(package_name_from_spec:380): Package name determined in 0.0s
creating virtual environment...
pipx >(run_subprocess:174): running /Library/Frameworks/Python.framework/Versions/3.11/bin/python3 -m venv --without-pip /Users/foo/.local/pipx/venvs/tox
pipx >(run_subprocess:174): running <checking pip's availability>
pipx >(run_subprocess:174): running /Users/foo/.local/pipx/venvs/tox/bin/python -c import sysconfig; print(sysconfig.get_path('purelib'))
pipx >(run_subprocess:174): running /Users/foo/.local/pipx/shared/bin/python -c import sysconfig; print(sysconfig.get_path('purelib'))
pipx >(run_subprocess:174): running /Users/foo/.local/pipx/venvs/tox/bin/python --version
pipx >(package_name_from_spec:379): Determined package name: virtualenv
pipx >(package_name_from_spec:380): Package name determined in 0.0s
upgrading virtualenv...
pipx >(run_subprocess:174): running /Users/foo/.local/pipx/venvs/tox/bin/python -m pip --no-input install --upgrade virtualenv
Looking in indexes: https://nexusrepo.app.mycompany.net/repository/pypilocal/simple/
Collecting virtualenv
  ERROR: HTTP error 403 while getting https://nexusrepo.app.mycompany.net/repository/pypilocal/packages/virtualenv/20.26.0/virtualenv-20.26.0-py3-none-any.whl#sha256=0846377ea76e818daaa3e00a4365c018bc3ac9760cbb3544de542885aad61fb3 (from https://nexusrepo.app.mycompany.net/repository/pypilocal/simple/virtualenv/) (requires-python:>=3.7)
ERROR: Could not install requirement virtualenv from https://nexusrepo.app.mycompany.net/repository/pypilocal/packages/virtualenv/20.26.0/virtualenv-20.26.0-py3-none-any.whl#sha256=0846377ea76e818daaa3e00a4365c018bc3ac9760cbb3544de542885aad61fb3 because of HTTP error 403 Client Error: Requested item is quarantined, please visit https://nexusiq.app.mycompany.net/ui/links/repository/da36ea0ecef64a9199ff614f6d56291c/result to investigate the reason(s) for url: https://nexusrepo.app.mycompany.net/repository/pypilocal/packages/virtualenv/20.26.0/virtualenv-20.26.0-py3-none-any.whl for URL https://nexusrepo.app.mycompany.net/repository/pypilocal/packages/virtualenv/20.26.0/virtualenv-20.26.0-py3-none-any.whl#sha256=0846377ea76e818daaa3e00a4365c018bc3ac9760cbb3544de542885aad61fb3 (from https://nexusrepo.app.mycompany.net/repository/pypilocal/simple/virtualenv/) (requires-python:>=3.7)

pipx >(rmdir:55): removing directory /Users/foo/.local/pipx/venvs/tox
'/Users/foo/.local/pipx/venvs/tox/bin/python -m pip --no-input install --upgrade virtualenv' failed

Notice that pipx tried to install the latest virtualenv (20.26.0). I use a local PyPI mirror that quarantined 20.26.0, so it failed to install.

Expected behavior

I expected pipx to install virtualenv==20.25.3 instead of the latest version.

Note that pipx install --pip-args='virtualenv==20.25.3' tox --verbose correctly installs the specified version before installing the main package.

% pipx install --pip-args='virtualenv==20.25.3' tox --verbose
pipx >(setup:924): pipx version is 1.5.0
pipx >(setup:925): Default python interpreter is '/Library/Frameworks/Python.framework/Versions/3.11/bin/python3'
pipx >(package_name_from_spec:379): Determined package name: tox
pipx >(package_name_from_spec:380): Package name determined in 0.0s
creating virtual environment...
pipx >(run_subprocess:174): running /Library/Frameworks/Python.framework/Versions/3.11/bin/python3 -m venv --without-pip /Users/foo/.local/pipx/venvs/tox
pipx >(run_subprocess:174): running <checking pip's availability>
pipx >(run_subprocess:174): running /Users/foo/.local/pipx/venvs/tox/bin/python -c import sysconfig; print(sysconfig.get_path('purelib'))
pipx >(run_subprocess:174): running /Users/foo/.local/pipx/shared/bin/python -c import sysconfig; print(sysconfig.get_path('purelib'))
pipx >(run_subprocess:174): running /Users/foo/.local/pipx/venvs/tox/bin/python --version
pipx >(_parsed_package_to_package_or_url:137): cleaned package spec: tox
installing tox...
pipx >(run_subprocess:174): running /Users/foo/.local/pipx/venvs/tox/bin/python -m pip --no-input install virtualenv==20.25.3 tox
pipx >(run_subprocess:174): running <fetch_info_in_venv commands>
pipx >(get_venv_metadata_for_package:348): get_venv_metadata_for_package: 60ms
pipx >(_parsed_package_to_package_or_url:137): cleaned package spec: tox
  installed package tox 4.14.2, installed using Python 3.11.6
  These apps are now globally available
    - tox
done! ✨ 🌟 ✨
@chrysle
Copy link
Contributor

chrysle commented Apr 26, 2024

Thanks for raising this! Apparently the package_name_from_spec function is run over the packages to preinstall, which shouldn't be:

dep_name = package_name_from_spec(dep, python, pip_args=pip_args, verbose=verbose)

Would you like to submit a quick fix?

@chrysle chrysle added the bug Something isn't working label Apr 26, 2024
@davidpeckham
Copy link
Contributor Author

You're welcome. Yes, I'll do that.

davidpeckham added a commit to davidpeckham/pipx that referenced this issue Apr 26, 2024
chrysle pushed a commit that referenced this issue Apr 29, 2024
…f latest version (#1379)

* pipx --preinstall ignores dependency version specifier #1377

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* parses dependency bofore installing it

* removed last commit

* removedc call to parse_specifier_for_install

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants