Python: improve site_packages_dir handling (#28346)

* Python: improve site_packages_dir handling

* Replace all site_packages_dir with purelib/platlib
This commit is contained in:
Adam J. Stewart
2022-01-13 20:11:16 -06:00
committed by GitHub
parent 2e238307c7
commit e0f044561e
46 changed files with 192 additions and 231 deletions

View File

@@ -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:

View File

@@ -128,22 +128,24 @@ def import_modules(self):
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
# 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('/', '.'))
# 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 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 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('/', '.'))
modules = [mod for mod in modules if re.match('[a-zA-Z0-9._]+$', mod)]
@@ -258,18 +260,13 @@ def install_args(self, spec, prefix):
# 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

View File

@@ -67,7 +67,7 @@ def import_modules(self):
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 @@ def configure(self, spec, prefix):
'--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 @@ def extend_path_setup(self):
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')