`pip install --upgrade ` behaves differently for pyproject.toml and requirements.txt
Asked Answered
V

1

6

If I have a venv with black==22.12.0 installed and I run pip install --U black then pip will update to the newest version of black. I will see same behavior if black is listed in a requirements.txt and I run pip install -U -r requirements.txt. In this case pip eagerly updates if a new version is available.

Now suppose I have a venv with and editable install created with pip install -e . from a pyproject.toml (example below). If this has black==22.12.0 installed and if I then run pip install -U -e . then black is not updated to the latest version. If I pin in the version of black in pyproject.toml to say black>=23" then pip install -U -e .` will update black. In this case pip only updates if the current version does not satisfy the requirements.

I cannot find anything in the docs describing this behavior. Is it intentional or a fault that pip install -U behaves differently in these two contexts?

Tests are made pip version 23.0.1 and python 3.10.10

[build-system]
requires = ["setuptools>=65.5"]
build-backend = "setuptools.build_meta"

[project]
name = "packaging_example"
version = "0.0.7"

description = "python packaging example"
requires-python = "==3.10"

dependencies = [
  "black"
]

[tool.setuptools.packages.find]
where = ["src"]

Verticillate answered 9/4, 2023 at 8:43 Comment(1)
It's not entirely clear to me why you expect these things to work the same way. When you supply a requirements.txt file you are explicitly listing (via the file contents) packages to upgrade. But pyproject.toml just contains information about the current project's dependencies. If you upgrade the current project, and the existing dependency installations meet the project's requirements even in the new version, then why should the dependencies get upgraded? (And, of course, with pip install -e, the current project's version number hasn't changed unless you updated pyproject.toml.)Inhuman
F
0

I believe I got the result you're looking for by adding the -I/--ignore-installed flag to pip install -e '.', which must go before the -e/--editable flag.

pip install -I -e '.'

From pip install -h:

-I, --ignore-installed      Ignore the installed packages, overwriting them. 
                            This can break your system if the existing package 
                            is of a different version or was installed with a
                            different package manager!

Note the warning: This can break your system if the existing package is of a different version or was installed with a different package manager!".

So, use with caution outside of a dev environment.

Funiculus answered 8/10 at 16:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.