Can we finally add a minimal API to pip?

Starting this discussion was on my TODO list for a while, so let’s go:

CPython’s ensurepip uses pip’s internal API. It is kept updated of course, but it does cause problems when pip is unbundled, which we do in Fedora.
Unbundling allows updating the pip wheel and CPython independently. IMO, that is a good thing: with CPython+pip bundled, most new venvs will show warnings about out-of date pip.

Ensurepip needs to set up some state (sys.path) before calling pip. The same effect can’t be had with environment variables: PYTHONPATH is not appended to the very beginning of sys.path.

Note that ensurepip is* also a command-line tool – in sole control of the environment, with no other code to worry about. The reasons against using pip as a library don’t really apply in ensurepip’s case.
* actually: ensurepip should be only a CLI tool, IMO. The note in the docs should be updated to match reality.

Can we instead have an API to call pip with a list of CLI arguments in the current process (and perhaps: then exit, since the the process is in an unknown state)?

2 Likes