Thanks. If you’re curious for specifics on why I’m asking, the motivation for the post is this PR in Spack:
Spack is (I think?) unique in that it:
- has one prefix per package installation, including python extensions (this is like Nix),
- has a potentially impure build environment, in that users can register external packages, including Python, and
- will often build packages for the python that’s running Spack (these are mostly for bootstrapping Spack’s dependencies).
So we want build isolation so that things like setuptools
can build from source, and so that we can isolate spack from the butchered sysconfig
on Ubuntu that inserts a random local
directory in most pip
installs.
We already use pip
to do most of the heavy lifting for Python builds. These are the arguments we invoke it with:
return [
# Verbose
"-vvv",
# Disable prompting for input
"--no-input",
# Disable the cache
"--no-cache-dir",
# Don't check to see if pip is up-to-date
"--disable-pip-version-check",
# Install packages
"install",
# Don't install package dependencies
"--no-deps",
# Overwrite existing packages
"--ignore-installed",
# Use env vars like PYTHONPATH
"--no-build-isolation",
# Don't warn that prefix.bin is not in PATH
"--no-warn-script-location",
# Ignore the PyPI package index
"--no-index",
]
We rely on PYTHONPATH because there is one prefix per installation, and we set up the build environment carefully to include dependencies of the thing being built. If the user decides to use their own python and not have Spack build it, the site packages of that python and any distro patching (ala Debian, sigh) can pollute the build environment.
The solution we’re likely going to go with that seems to solve all of these issues (for the price of some nastiness in lower-level Spack packages) is to shim a venv in front of python
when it’s used for building python packages. If it’s simply a build dependency (for running scripts), this isn’t needed, but for anything that is going to run pip
, cmake
, meson
, etc. and install python
modules, we’re relying on the venv
.
Eventually we can hide this behind a virtual python
package (currently python
in Spack is cpython
) and there is some discussion about how that might work if you’re interested.
Anyway, I think the PR is consistent with yours and @pf_moore’s advice. Other attempts, like making a temporary venv
just during build (like pip
does), had other problems, and we landed on using a tiny persistent venv
for isolation after a number of false starts. The prior attempts are linked above as well.
I am not sure how useful this is for the packaging folks here but maybe it’s an interesting use case.