PEP 771: Default Extras for Python Software Packages (Round 3)

I like the PEP. I wanted to bring up one more downside of the rejected meta-package idea, pertaining to command-line tools, that I hadn’t seen mentioned before in the PEP or in this discussion thread.

Tool installers like pipx or uv tool usually ignore scripts declared by dependencies, for good reasons (if I pipx install sphinx, I want sphinx-build in my ~/.local/bin, but I don’t want rst2pseudoxml or a bunch of other random scripts that docutils ships). Therefore if you split a hypothetical mytool package into mytool (with recommended extras) and mytool-core, you end up in a situation where pipx install mytool will leave the user with no executable scripts, requiring them to research the magical incantations asking for the scripts from some particular dependency to be installed.

Users of Ansible suffer from this today.

1 Like

What makes you think that? What’s the difference between an unneeded recommended dependency that a library doesn’t know it suddenly needs to opt out of versus an application?

OK, as PyInstaller maintainer I can definitely debunk this assumption. You’d be suprised – I see them used together very rarely.

Lockfiles aren’t actually that useful when the expectation isn’t for the end user to use pip. On a platform with a system package manager (including macOS+homebrew) it’s more efficient to pretend PyPI doesn’t exist and install everything via the system package manager[1] – these package managers rarely even support pinned versions and have no idea what to do with a pylock.toml.

For similar reasons, any application that wants to be say apt-get install-able has to be compatible with a wide range of whatever versions are out there., including Python versions. Maintaining a multi-python-version lockfile that you can never enforce when it matters is a lot of work for very little gain.

And to many, the bundled application is itself the lock. Why add another… [2]

I suppose it’s a hint that something is happening but the lock file format doesn’t even include the dependency graph, let alone which branches of said graph are opt-out-able.

But they shouldn’t have to be. Doing the right thing should not be the hard path. Good package scoping works out the box for any user. Recommended dependencies are easy only for those who don’t care, require micro management at best for those that do, offer no solution when a package itself is significantly bloated by code it can’t use without its recommended dependencies and are unusable outside of Python’s own packaging ecosystem.


  1. be that installing the dependencies at build time to bundle them or declaring them as dependencies for the end user to install ↩︎

  2. I don’t agree with this way of thinking but I hear it often enough ↩︎

4 Likes

I just want to echo this sentiment. I don’t see that the gains of this proposal outweigh the disruption to what tools have to accept, and the gap that will inevitably now arise between old tools that don’t support it and new ones that do. In addition, it still seems to me that the only gain of this proposal is making things more convenient for people who want to type pip install blah and expect it to do “the right thing” without ever looking at the package documentation or readme for something that says “to install our package, type <whatever they should type>”. I simply don’t think that is worth bothering about. If someone types pip install blah and it doesn’t do what they want then they can look at the readme and see that they should have typed something else instead and then they can type that instead.

This is another proposal to which my response is “I would accept more disruption for a greater benefit, but not this smaller disruption for this smaller benefit.” In my mind that greater disruption would be a full-fledged namespace system so that people publishing packages can have total freedom to name things as they choose under their own namespace. Then tool install mynamespace::blah can mean whatever they want it to mean and there is no need for extras at all. Currently that is not totally viable because of the possibility of name collisions, and even when possible it can feel a bit awkward. But I think that’s the way to go eventually, and until we can do that, I’d rather not create more wrinkles with something like this.

4 Likes

I made a local implementation of this PEP in nab, naively it makes all resolves slower (nab is based on the pubgrub algorithm). But I was able to implement various optimizations that got the cost to < 0.1% slower on resolves not involving a default extra, and about ~1% cost on resolves involving non-trivial default extas, which I think is fine.

However, one thing I consider missing from this PEP is updating the pylock standard to add a root default-extras. When a pyproject.toml has a default-optional-dependencies there’s no clean way to represent that in a pylock.toml. A locker could use a synthetic extra name, but that’s pretty messy as it adds a extra markers and marker resolution.

1 Like