summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAdam J. Stewart <ajstewart426@gmail.com>2022-01-13 20:11:16 -0600
committerGitHub <noreply@github.com>2022-01-13 20:11:16 -0600
commite0f044561e9b3cb384bfb0f364555e5875b1a492 (patch)
treec5919577db37f1d3dc9772d9b8e453fe3d6882b5 /lib
parent2e238307c7b06bbc14b6a9287d2054a5d8c8c83b (diff)
downloadspack-e0f044561e9b3cb384bfb0f364555e5875b1a492.tar.gz
spack-e0f044561e9b3cb384bfb0f364555e5875b1a492.tar.bz2
spack-e0f044561e9b3cb384bfb0f364555e5875b1a492.tar.xz
spack-e0f044561e9b3cb384bfb0f364555e5875b1a492.zip
Python: improve site_packages_dir handling (#28346)
* Python: improve site_packages_dir handling * Replace all site_packages_dir with purelib/platlib
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/bootstrap.py11
-rw-r--r--lib/spack/spack/build_systems/python.py43
-rw-r--r--lib/spack/spack/build_systems/sip.py6
3 files changed, 27 insertions, 33 deletions
diff --git a/lib/spack/spack/bootstrap.py b/lib/spack/spack/bootstrap.py
index 16195ff381..bdf69303c6 100644
--- a/lib/spack/spack/bootstrap.py
+++ b/lib/spack/spack/bootstrap.py
@@ -78,13 +78,10 @@ def _try_import_from_store(module, query_spec, query_info=None):
for candidate_spec in installed_specs:
pkg = candidate_spec['python'].package
- purelib = pkg.config_vars['python_lib']['false']['false']
- platlib = pkg.config_vars['python_lib']['true']['false']
-
- module_paths = [
- os.path.join(candidate_spec.prefix, purelib),
- os.path.join(candidate_spec.prefix, platlib),
- ]
+ module_paths = {
+ os.path.join(candidate_spec.prefix, pkg.purelib),
+ os.path.join(candidate_spec.prefix, pkg.platlib),
+ }
sys.path.extend(module_paths)
try:
diff --git a/lib/spack/spack/build_systems/python.py b/lib/spack/spack/build_systems/python.py
index 2d003f38e3..59fd057c6a 100644
--- a/lib/spack/spack/build_systems/python.py
+++ b/lib/spack/spack/build_systems/python.py
@@ -128,22 +128,24 @@ class PythonPackage(PackageBase):
list: list of strings of module names
"""
modules = []
- root = os.path.join(
- self.prefix,
- self.spec['python'].package.config_vars['python_lib']['true']['false'],
- )
+ pkg = self.spec['python'].package
+
+ # Packages may be installed in platform-specific or platform-independent
+ # site-packages directories
+ for directory in {pkg.platlib, pkg.purelib}:
+ root = os.path.join(self.prefix, directory)
- # Some Python libraries are packages: collections of modules
- # distributed in directories containing __init__.py files
- for path in find(root, '__init__.py', recursive=True):
- modules.append(path.replace(root + os.sep, '', 1).replace(
- os.sep + '__init__.py', '').replace('/', '.'))
+ # Some Python libraries are packages: collections of modules
+ # distributed in directories containing __init__.py files
+ for path in find(root, '__init__.py', recursive=True):
+ modules.append(path.replace(root + os.sep, '', 1).replace(
+ os.sep + '__init__.py', '').replace('/', '.'))
- # Some Python libraries are modules: individual *.py files
- # found in the site-packages directory
- for path in find(root, '*.py', recursive=False):
- modules.append(path.replace(root + os.sep, '', 1).replace(
- '.py', '').replace('/', '.'))
+ # Some Python libraries are modules: individual *.py files
+ # found in the site-packages directory
+ for path in find(root, '*.py', recursive=False):
+ modules.append(path.replace(root + os.sep, '', 1).replace(
+ '.py', '').replace('/', '.'))
modules = [mod for mod in modules if re.match('[a-zA-Z0-9._]+$', mod)]
@@ -258,18 +260,13 @@ class PythonPackage(PackageBase):
# Get all relative paths since we set the root to `prefix`
# We query the python with which these will be used for the lib and inc
# directories. This ensures we use `lib`/`lib64` as expected by python.
- pure_site_packages_dir = spec['python'].package.config_vars[
- 'python_lib']['false']['false']
- plat_site_packages_dir = spec['python'].package.config_vars[
- 'python_lib']['true']['false']
- inc_dir = spec['python'].package.config_vars['python_inc']['true']
-
+ pkg = spec['python'].package
args += ['--root=%s' % prefix,
- '--install-purelib=%s' % pure_site_packages_dir,
- '--install-platlib=%s' % plat_site_packages_dir,
+ '--install-purelib=%s' % pkg.purelib,
+ '--install-platlib=%s' % pkg.platlib,
'--install-scripts=bin',
'--install-data=',
- '--install-headers=%s' % inc_dir
+ '--install-headers=%s' % pkg.include,
]
return args
diff --git a/lib/spack/spack/build_systems/sip.py b/lib/spack/spack/build_systems/sip.py
index 49fdd621ee..def333d8e6 100644
--- a/lib/spack/spack/build_systems/sip.py
+++ b/lib/spack/spack/build_systems/sip.py
@@ -67,7 +67,7 @@ class SIPPackage(PackageBase):
modules = []
root = os.path.join(
self.prefix,
- self.spec['python'].package.config_vars['python_lib']['true']['false'],
+ self.spec['python'].package.platlib,
)
# Some Python libraries are packages: collections of modules
@@ -114,7 +114,7 @@ class SIPPackage(PackageBase):
'--sip-incdir', join_path(spec['py-sip'].prefix.include,
python_include_dir),
'--bindir', prefix.bin,
- '--destdir', inspect.getmodule(self).site_packages_dir,
+ '--destdir', inspect.getmodule(self).python_platlib,
])
self.python(configure, *args)
@@ -167,7 +167,7 @@ class SIPPackage(PackageBase):
module = self.spec['py-sip'].variants['module'].value
if module != 'sip':
module = module.split('.')[0]
- with working_dir(inspect.getmodule(self).site_packages_dir):
+ with working_dir(inspect.getmodule(self).python_platlib):
with open(os.path.join(module, '__init__.py'), 'a') as f:
f.write('from pkgutil import extend_path\n')
f.write('__path__ = extend_path(__path__, __name__)\n')