r/Python • • 25d ago

News Pip 26.3 - Extended Pylock Support, Build Backend Warnings, and a caution on wheel installation

Today I got to be the release manager for pip 26.3! There are two big features, and one documentation update, that I think worth talking about:

Extended Pylock Support

You can now install extras and non-default groups from a pylock file, e.g. pip install -r "pylock.toml[extra1,extra2]" and pip install --group pylock.toml:dev

This supports the installation part of a workflow that generates a single lock file for multiple situations. For example, using a universal pylock file generator, such as a tool I built called nab, you might want to specify "I want a lock file with two mutually exclusive extras for different versions of SqlAlchemy and a dev dependency group", e.g.:

[project.optional-dependencies]
sa14 = ["sqlalchemy==1.4.*"]
sa20 = ["sqlalchemy==2.0.*"]

[dependency-groups]
dev = ["pytest"]

[tool.nab]
conflicts = [[{ extra = "sa14" }, { extra = "sa20" }]]

And now pip can pick which extra and group it wants to install from the output lock file, e.g. pip install --group 'pylock.toml[sa14]:dev' . This works with any tool that outputs standard pylock.toml files.

Build backends warnings for local builds

This one has been a long time coming, when you build a package from some kind of source, you invoke a build backend (e.g. setuptools, hatchling, flit-core, uv-build, poetry-core, etc.). That build backend can emit warnings to tell you something isn't configured correctly, or a feature will be dropped in the future. But for historical reasons, pip has never displayed those warnings (uv has inherited this and also doesn't display these warnings).

Now, when building locally, e.g. pip install ., or pip install -e ., the build backend warning will be logged by default (and for non-local builds it will be in the -vv output).

For example, if in setuptools you specify a README.mdfile but setuptools can't find it, you will get the warning:

$ pip install .
...
  .../setuptools/config/expand.py:128: BuildBackendWarning: File '.../README.md' cannot be found

A caution on installing untrusted wheels

There have been a lot of supply chain attacks recently, and this has led to a lot of people learning about source distributions (sdists) which are built from source and can run arbitrary code on installation, as well as .pth files which after being installed run at the beginning of every Python execution.

This has led a lot people to turn to only using binary distributions (with pip --only-binary :all: or slightly weaker --prefer-binary), otherwise known as wheels. What is great about wheels is they are just glorified zip files, and they are installed by unzipping the different parts of the wheel into the different Python installation locations.

However, a word of caution, Python's import system is dynamic, and the moment a Python file exists in a location that can be imported, it can be imported even in a running Python processes. So while pip 26.3 includes significant hardening against untrusted wheels, we cannot guarantee installing a malicious wheel won't execute third party code.

I can't speak for other tools, but I am fairly confident this applies to all other Python package installers (even those written in other languages).

I will continue to do more hardening in pip where issues come up, and propose fixes in Python to improve the situation there. (Also, a possible future is lock files only first, where the locker refuses to install anything and refuses to execute third party code by default, then exact distributions can be validated/inspected before install, that's part of my pitch for nab which does the first step).

Official Links

The official announcement post is at: https://discuss.python.org/t/announcement-pip-26-3-release/109822

The full change log: https://pip.pypa.io/en/stable/news/#v26-3

89 Upvotes

10 comments sorted by

3

u/Vegetable-Tennis1570 24d ago

Should I use `uv` or stick pip now. After `uv` acquisition feeling bad. Please share your stance now guys.

3

u/zurtex 24d ago

Use what is best for you! uv is a great a tool, and I'm friends with some of the Astral folks. And one of the great things is they are committed to packaging standards, so it's fairly easy to transfer between tools.

But yeah, I do think we need to make sure we have quality tools alive and healthy outside uv, I don't think Python Packaging can exactly be described as an OpenAI core mission.

1

u/Nanotheslayer 23d ago

If your concern is being able to leave uv later, I'd test that separately from deciding whether to switch today. Export with uv export --format pylock.toml --output-file pylock.toml, then try python -m pip install -r pylock.toml in a fresh environment and run your tests. Use the same Python version and OS as deployment, and check the extras, dependency groups and local packages you rely on. pip's pylock support is still marked experimental, so I'd treat this as a portability check for your actual project rather than assume every uv workflow transfers unchanged.

16

u/Khavel_dev 24d ago

The --group flag is the one I've been waiting for. We had a few separate requirements-*.txt files for different CI stages and keeping them in sync was always annoying. Named groups in one lockfile is way nicer.

4

u/MIDNIGHTcairn 24d ago

The Pylock improvements sound especially useful. Dependency management could definitely use more of this

1

u/danielmartinez22 23d ago

build backend warnings finally showing on local installs is a bigger deal than it sounds, deprecations wont catch people out as late

1

u/zurtex 23d ago edited 23d ago

Indeed! I started this discussion about a year and a half ago after a couple of breaking changes from setuptools. It required community discussion, discussion if we needed to change the standards, updates and a release in pypyoject-hooks, and then vendoring that release in pip and making changes there so not to spam everyone on every sdist install.

I'm not a build backend maintainer myself, so I can only sympathize that they are in a difficult position of wanting to modernize, but their behavior being relied on by ancient packages. One thing we've done on pip side is to have build-constraints (a few releases ago) so users can pin to older backends where they need to without affecting their regular install: https://pip.pypa.io/en/stable/cli/pip_install/#cmdoption-build-constraint

2

u/raks1991 14d ago

The --no-binary fix with pylock is worth a mention too. Previously pip could fetch the sdist from the index instead of the locked URL. That's a fairly important detail if the reason you're using a lockfile is to control exactly which artifact gets installed.