pyinfra
pyinfra copied to clipboard
pip.venv and pip.packages - should package names be lowercased?
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
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.
Oh good catch! Thank you.
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...