Files
spack/var/spack/repos/builtin/packages/py-installer/package.py
Harmen Stoppels 125206d44d python: always use a venv (#40773)
This commit adds a layer of indirection to improve build isolation with 
and without external Python, as well as usability of environment views.

It adds `python-venv` as a dependency to all packages that `extends("python")`, 
which has the following advantages:

1. Build isolation: only `PYTHONPATH` is considered in builds, not 
   user / system packages
2. Stable install layout: fixes the problem on Debian, RHEL and Fedora where 
   external / system python produces `bin/local` subdirs in Spack install prefixes. 
3. Environment views are Python virtual environments (and if you add 
   `py-pip` things like `pip list` work)

Views work whether they're symlink, hardlink or copy type.

This commit additionally makes `spec["python"].command` return 
`spec["python-venv"].command`. The rationale is that packages in repos we do 
not own do not pass the underlying python to the build system, which could still 
result in incorrectly computed install layouts.

Other attributes like `libs`, `headers` should be on `python` anyways and need no change.
2024-05-06 16:17:35 +02:00

40 lines
1.5 KiB
Python

# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
import os
from spack.package import *
class PyInstaller(Package, PythonExtension):
"""A library for installing Python wheels."""
homepage = "https://github.com/pypa/installer"
url = (
"https://files.pythonhosted.org/packages/py3/i/installer/installer-0.6.0-py3-none-any.whl"
)
list_url = "https://pypi.org/simple/installer/"
version("0.7.0", sha256="05d1933f0a5ba7d8d6296bb6d5018e7c94fa473ceb10cf198a92ccea19c27b53")
version("0.6.0", sha256="ae7c62d1d6158b5c096419102ad0d01fdccebf857e784cee57f94165635fe038")
extends("python")
def install(self, spec, prefix):
# To build and install installer from source, you need flit-core, build, and installer
# already installed. We get around this by using a pre-built wheel to install itself.
# See https://github.com/pypa/installer/issues/150 for details.
# We can't do this in setup_build_environment because self.stage.archive_file is undefined
wheel = self.stage.archive_file
path = os.environ.get("PYTHONPATH", "")
os.environ["PYTHONPATH"] = os.pathsep.join([wheel, path])
args = ["-m", "installer", "--prefix", prefix, wheel]
python(*args)
def setup_dependent_package(self, module, dependent_spec):
setattr(module, "installer", python.with_default_args("-m", "installer"))