pypa / pipx

Install and Run Python Applications in Isolated Environments
https://pipx.pypa.io
MIT License
10.66k stars 419 forks source link

Injecting VCS URL of package that is already installed does not install proper version #1545

Open aereaux opened 2 months ago

aereaux commented 2 months ago

Describe the bug

I am trying to install the version of gajim from git, which requires the version of python-nbxmpp from git. When I run the inject command it runs fine, but doesn't install the proper version.

When I run pipx runpip gajim install git+https://dev.gajim.org/gajim/python-nbxmpp/ --force-reinstall it seems to do what I need, so maybe a --force-reinstall or something is needed?

How to reproduce

$ pipx install git+https://dev.gajim.org/gajim/gajim/
  installed package gajim 1.9.3, installed using Python 3.12.6
  These apps are now globally available
    - gajim
    - gajim-remote
done! ✨ 🌟 ✨
$ pipx inject gajim git+https://dev.gajim.org/gajim/python-nbxmpp/ --force --verbose
pipx >(setup:1083): pipx version is 1.6.0
pipx >(setup:1084): Default python interpreter is '/usr/bin/python3.12'
pipx >(run_pipx_command:218): Virtual Environment location is /home/user/.local/pipx/venvs/gajim
pipx >(inject:135): Injecting packages: ['git+https://dev.gajim.org/gajim/python-nbxmpp/']
pipx >(run_subprocess:175): running <checking pip's availability>
pipx >(needs_upgrade:83): Time since last upgrade of shared libs, in seconds: 20057. Upgrade will be run by pipx if greater than 2592000.
pipx >(run_subprocess:175): running <checking pip's availability>
pipx >(_parsed_package_to_package_or_url:139): cleaned package spec: git+https://dev.gajim.org/gajim/python-nbxmpp/
pipx >(create_venv:162): Creating virtual environment
creating virtual environment...
pipx >(run_subprocess:175): running /home/user/.local/pipx/venvs/gajim/bin/python -m venv --without-pip /tmp/tmpr1myvwec
pipx >(run_subprocess:175): running <checking pip's availability>
pipx >(run_subprocess:175): running /tmp/tmpr1myvwec/bin/python -c import sysconfig; print(sysconfig.get_path('purelib'))
pipx >(run_subprocess:175): running /home/user/.local/pipx/shared/bin/python -c import sysconfig; print(sysconfig.get_path('purelib'))
pipx >(run_subprocess:175): running /tmp/tmpr1myvwec/bin/python --version
determining package name from 'git+https://dev.gajim.org/gajim/python-nbxmpp/'...
pipx >(run_subprocess:175): running /tmp/tmpr1myvwec/bin/python -m pip list --format=json
pipx >(run_subprocess:175): running /tmp/tmpr1myvwec/bin/python -m pip --no-input install --no-dependencies git+https://dev.gajim.org/gajim/python-nbxmpp/
pipx >(run_subprocess:175): running /tmp/tmpr1myvwec/bin/python -m pip list --format=json
pipx >(install_package_no_deps:333): Determined package name: nbxmpp
pipx >(package_name_from_spec:390): Package name determined in 6.8s
pipx >(_parsed_package_to_package_or_url:139): cleaned package spec: git+https://dev.gajim.org/gajim/python-nbxmpp/
pipx >(install_package:245): Installing nbxmpp from spec 'git+https://dev.gajim.org/gajim/python-nbxmpp/'
installing nbxmpp from spec 'git+https://dev.gajim.org/gajim/python-nbxmpp/'...
pipx >(run_subprocess:175): running /home/user/.local/pipx/venvs/gajim/bin/python -m pip --no-input install git+https://dev.gajim.org/gajim/python-nbxmpp/
pipx >(run_subprocess:175): running <fetch_info_in_venv commands>
pipx >(get_venv_metadata_for_package:349): get_venv_metadata_for_package: 84ms
pipx >(_parsed_package_to_package_or_url:139): cleaned package spec: git+https://dev.gajim.org/gajim/python-nbxmpp/
  injected package nbxmpp into venv gajim
done! ✨ 🌟 ✨$ pipx runpip gajim freeze
cffi==1.17.1
cryptography==43.0.1
css-parser==1.0.10
emoji==2.12.1
gajim @ git+https://dev.gajim.org/gajim/gajim/@7aa2fac6d6653333a5dfe08ed92295273c26e2ec
greenlet==3.1.0
idna==3.9
jaraco.classes==3.4.0
jaraco.context==6.0.1
jaraco.functools==4.0.2
jeepney==0.8.0
keyring==25.3.0
more-itertools==10.5.0
nbxmpp==5.0.3 # Should read nbxmpp @ git+https://dev.gajim.org/gajim/python-nbxmpp/@b44690dafeef45a0dcb9dd4561e65f20f94daf49
omemo-dr==1.0.1
packaging==24.1
pillow==10.4.0
precis-i18n==1.1.0
protobuf==5.28.1
pycairo==1.27.0
pycparser==2.22
PyGObject==3.50.0
pypng==0.20220715.0
qrcode==7.4.2
SecretStorage==3.3.3
SQLAlchemy==2.0.34
typing_extensions==4.12.2

Expected behavior

The pip freeze command should show the git version of nbxmpp.

huxuan commented 2 months ago

Hi @aereaux, seems the problem is caused by the ambigious configuration of nbxmpp. As it is shown here, the package version is set as the attribute value of nbxmpp.__version__ and it is always 5.0.3 for all the commits between 5.0.3 and 5.0.4. So I suppose you might need to integrate with setuptools-scm to make it work as expected. Would you like to have a try on it?

Actually, I tried to reproduce the issue by using another Python package repo with setuptools-scm integration and it works as expected.

$ pipx install pycowsay
$ pipx inject pycowsay git+https://github.com/serious-scaffold/ss-python/
$ pipx list --include-inject
...
   package pycowsay 0.0.0.2, installed using Python 3.12.6
    - pycowsay
    - man6/pycowsay.6
    Injected Packages:
      - ss-python 0.0.55.dev70+g5895610
...
$ pipx runpip pycowsay freeze
...
ss-python @ git+https://github.com/serious-scaffold/ss-python/@589561024c2d6ab2c52bd996ffd6a6bb3295ca55
...