pyinfra icon indicating copy to clipboard operation
pyinfra copied to clipboard

pip.venv and pip.packages - should package names be lowercased?

Open sebastianelsner opened this issue 1 year ago • 3 comments

Describe the bug

Please consider the following code snippet. When run multiple times, installing the packages via pip.packages is reported as "changed" every run.

To Reproduce

from pyinfra.api import deploy
from pyinfra.operations import pip

@deploy("Venv")
def venv():
    pip.venv(
        python="python3",
        path="/tmp/clientvenv",
    )

    pip.packages(
        name="Install packages",
        packages=["boto3==1.26.27", "lucidity==1.6.0"],
        virtualenv="/tmp/clientvenv",
    )

venv()

Run via

pyinfra inventory_client.py deploy_client.py

All involved systems are Ubuntu 22.04.

Expected behavior

The packages are found in the given venv and not reported as changed every time. Please tell me I am just not seeing something basic here... I feel dumb, this should be easy :D

Meta

    System: Linux
      Platform: Linux-5.15.0-56-generic-x86_64-with-glibc2.35
      Release: 5.15.0-56-generic
      Machine: x86_64
    pyinfra: v2.5.2
    Executable: /home/grndgdnke/lidl_render_backend/lidl_render_backend_venv/bin/pyinfra
    Python: 3.10.6 (CPython, GCC 11.3.0)
  • How was pyinfra installed (source/pip)?

venv + pip install

sebastianelsner avatar Dec 13 '22 21:12 sebastianelsner

The reason this operation keeps showing as changed is because the package name in pypi is actually Lucidity.

Your deployment is using a lowercase version of the name so it's always returning that it needs to be installed.

The quick fix here is to change your deployment to use the actual package name:

    pip.packages(
        name="Install packages",
        packages=["boto3==1.26.27", "Lucidity==1.6.0"],
        virtualenv="/tmp/clientvenv",
    )

Whether or not this is a bug, or something that should be fixed is another discussion.

sysadmin75 avatar Dec 17 '22 15:12 sysadmin75

Oh good catch! Thank you.

sebastianelsner avatar Dec 26 '22 12:12 sebastianelsner

So pyinfra did used to, depending on package manager, lowercase package names. However this behaviour was confusing and resulted in other bugs. That said PyPi's own pep-0426 clearly states package names should be compared insensitively, this would probably require lowercasing input names and fact names...

Fizzadar avatar Jan 15 '23 16:01 Fizzadar