Python: set default config_vars (#28290)
* Python: set default config_vars * Add missing commas * dso_suffix not present for some reason * Remove use of default_site_packages_dir * Use config_vars during bootstrapping too * Catch more errors * Fix unit tests * Catch more errors * Update docstring
This commit is contained in:
		| @@ -77,17 +77,13 @@ def _try_import_from_store(module, query_spec, query_info=None): | |||||||
|     installed_specs = spack.store.db.query(query_spec, installed=True) |     installed_specs = spack.store.db.query(query_spec, installed=True) | ||||||
| 
 | 
 | ||||||
|     for candidate_spec in installed_specs: |     for candidate_spec in installed_specs: | ||||||
|         python_spec = candidate_spec['python'] |         pkg = candidate_spec['python'].package | ||||||
|         lib_spd = python_spec.package.default_site_packages_dir |         purelib = pkg.config_vars['python_lib']['false']['false'] | ||||||
|         lib64_spd = lib_spd.replace('lib/', 'lib64/') |         platlib = pkg.config_vars['python_lib']['true']['false'] | ||||||
|         lib_debian_derivative = os.path.join( |  | ||||||
|             'lib', 'python{0}'.format(python_spec.version.up_to(1)), 'dist-packages' |  | ||||||
|         ) |  | ||||||
| 
 | 
 | ||||||
|         module_paths = [ |         module_paths = [ | ||||||
|             os.path.join(candidate_spec.prefix, lib_debian_derivative), |             os.path.join(candidate_spec.prefix, purelib), | ||||||
|             os.path.join(candidate_spec.prefix, lib_spd), |             os.path.join(candidate_spec.prefix, platlib), | ||||||
|             os.path.join(candidate_spec.prefix, lib64_spd) |  | ||||||
|         ] |         ] | ||||||
|         sys.path.extend(module_paths) |         sys.path.extend(module_paths) | ||||||
| 
 | 
 | ||||||
|   | |||||||
| @@ -7,12 +7,15 @@ | |||||||
| import os | import os | ||||||
| import platform | import platform | ||||||
| import re | import re | ||||||
|  | import sys | ||||||
| 
 | 
 | ||||||
| import llnl.util.tty as tty | import llnl.util.tty as tty | ||||||
| from llnl.util.filesystem import get_filetype, path_contains_subdirectory | from llnl.util.filesystem import get_filetype, path_contains_subdirectory | ||||||
| from llnl.util.lang import match_predicate | from llnl.util.lang import match_predicate | ||||||
| 
 | 
 | ||||||
| from spack import * | from spack import * | ||||||
|  | from spack.build_environment import dso_suffix | ||||||
|  | from spack.compilers import NoCompilerForSpecError | ||||||
| from spack.util.environment import is_system_path | from spack.util.environment import is_system_path | ||||||
| from spack.util.prefix import Prefix | from spack.util.prefix import Prefix | ||||||
| 
 | 
 | ||||||
| @@ -752,11 +755,61 @@ def config_vars(self): | |||||||
| """ % self.print_string("json.dumps(config)") | """ % self.print_string("json.dumps(config)") | ||||||
| 
 | 
 | ||||||
|         dag_hash = self.spec.dag_hash() |         dag_hash = self.spec.dag_hash() | ||||||
|  | 
 | ||||||
|         if dag_hash not in self._config_vars: |         if dag_hash not in self._config_vars: | ||||||
|  |             # Default config vars | ||||||
|  |             version = self.version.up_to(2) | ||||||
|             try: |             try: | ||||||
|                 config = json.loads(self.command('-c', cmd, output=str)) |                 cc = self.compiler.cc | ||||||
|  |                 cxx = self.compiler.cxx | ||||||
|  |             except (TypeError, NoCompilerForSpecError): | ||||||
|  |                 cc = 'cc' | ||||||
|  |                 cxx = 'c++' | ||||||
|  | 
 | ||||||
|  |             config = { | ||||||
|  |                 'CC': cc, | ||||||
|  |                 'CXX': cxx, | ||||||
|  |                 'INCLUDEPY': self.prefix.include.join('python{}').format(version), | ||||||
|  |                 'LIBDEST': self.prefix.lib.join('python{}').format(version), | ||||||
|  |                 'LIBDIR': self.prefix.lib, | ||||||
|  |                 'LIBPL': self.prefix.lib.join('python{0}').join( | ||||||
|  |                     'config-{0}-{1}').format(version, sys.platform), | ||||||
|  |                 'LDLIBRARY': 'libpython{}.{}'.format(version, dso_suffix), | ||||||
|  |                 'LIBRARY': 'libpython{}.a'.format(version), | ||||||
|  |                 'LDSHARED': cc, | ||||||
|  |                 'LDCXXSHARED': cxx, | ||||||
|  |                 'PYTHONFRAMEWORKPREFIX': '/System/Library/Frameworks', | ||||||
|  |                 'prefix': self.prefix, | ||||||
|  |                 'config_h_filename': self.prefix.include.join('python{}').join( | ||||||
|  |                     'pyconfig.h').format(version), | ||||||
|  |                 'makefile_filename': self.prefix.lib.join('python{0}').join( | ||||||
|  |                     'config-{0}-{1}').Makefile.format(version, sys.platform), | ||||||
|  |                 'python_inc': { | ||||||
|  |                     # plat_specific | ||||||
|  |                     'true': os.path.join('include64', 'python{}'.format(version)), | ||||||
|  |                     'false': os.path.join('include', 'python{}'.format(version)), | ||||||
|  |                 }, | ||||||
|  |                 'python_lib': { | ||||||
|  |                     # plat_specific | ||||||
|  |                     'true': { | ||||||
|  |                         # standard_lib | ||||||
|  |                         'true': os.path.join('lib64', 'python{}'.format(version)), | ||||||
|  |                         'false': os.path.join( | ||||||
|  |                             'lib64', 'python{}'.format(version), 'site-packages'), | ||||||
|  |                     }, | ||||||
|  |                     'false': { | ||||||
|  |                         # standard_lib | ||||||
|  |                         'true': os.path.join('lib', 'python{}'.format(version)), | ||||||
|  |                         'false': os.path.join( | ||||||
|  |                             'lib', 'python{}'.format(version), 'site-packages'), | ||||||
|  |                     }, | ||||||
|  |                 }, | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             try: | ||||||
|  |                 config.update(json.loads(self.command('-c', cmd, output=str))) | ||||||
|             except (ProcessError, RuntimeError): |             except (ProcessError, RuntimeError): | ||||||
|                 config = {} |                 pass | ||||||
|             self._config_vars[dag_hash] = config |             self._config_vars[dag_hash] = config | ||||||
|         return self._config_vars[dag_hash] |         return self._config_vars[dag_hash] | ||||||
| 
 | 
 | ||||||
| @@ -784,14 +837,9 @@ def home(self): | |||||||
|         and symlinks it to ``/usr/local``. Users may not know the actual |         and symlinks it to ``/usr/local``. Users may not know the actual | ||||||
|         installation directory and add ``/usr/local`` to their |         installation directory and add ``/usr/local`` to their | ||||||
|         ``packages.yaml`` unknowingly. Query the python executable to |         ``packages.yaml`` unknowingly. Query the python executable to | ||||||
|         determine exactly where it is installed. Fall back on |         determine exactly where it is installed. | ||||||
|         ``spec['python'].prefix`` if that doesn't work.""" |         """ | ||||||
| 
 |         return Prefix(self.config_vars['prefix']) | ||||||
|         if 'prefix' in self.config_vars: |  | ||||||
|             prefix = self.config_vars['prefix'] |  | ||||||
|         else: |  | ||||||
|             prefix = self.prefix |  | ||||||
|         return Prefix(prefix) |  | ||||||
| 
 | 
 | ||||||
|     @property |     @property | ||||||
|     def libs(self): |     def libs(self): | ||||||
| @@ -846,14 +894,9 @@ def libs(self): | |||||||
| 
 | 
 | ||||||
|     @property |     @property | ||||||
|     def headers(self): |     def headers(self): | ||||||
|         if 'config_h_filename' in self.config_vars: |  | ||||||
|         config_h = self.config_vars['config_h_filename'] |         config_h = self.config_vars['config_h_filename'] | ||||||
| 
 | 
 | ||||||
|             if not os.path.exists(config_h): |         if os.path.exists(config_h): | ||||||
|                 includepy = self.config_vars['INCLUDEPY'] |  | ||||||
|                 msg = 'Unable to locate {0} headers in {1}' |  | ||||||
|                 raise RuntimeError(msg.format(self.name, includepy)) |  | ||||||
| 
 |  | ||||||
|             headers = HeaderList(config_h) |             headers = HeaderList(config_h) | ||||||
|         else: |         else: | ||||||
|             headers = find_headers( |             headers = find_headers( | ||||||
| @@ -876,10 +919,7 @@ def python_include_dir(self): | |||||||
|         Returns: |         Returns: | ||||||
|             str: include files directory |             str: include files directory | ||||||
|         """ |         """ | ||||||
|         try: |  | ||||||
|         return self.config_vars['python_inc']['false'] |         return self.config_vars['python_inc']['false'] | ||||||
|         except KeyError: |  | ||||||
|             return os.path.join('include', 'python{0}'.format(self.version.up_to(2))) |  | ||||||
| 
 | 
 | ||||||
|     @property |     @property | ||||||
|     def python_lib_dir(self): |     def python_lib_dir(self): | ||||||
| @@ -900,10 +940,7 @@ def python_lib_dir(self): | |||||||
|         Returns: |         Returns: | ||||||
|             str: standard library directory |             str: standard library directory | ||||||
|         """ |         """ | ||||||
|         try: |  | ||||||
|         return self.config_vars['python_lib']['false']['true'] |         return self.config_vars['python_lib']['false']['true'] | ||||||
|         except KeyError: |  | ||||||
|             return os.path.join('lib', 'python{0}'.format(self.version.up_to(2))) |  | ||||||
| 
 | 
 | ||||||
|     @property |     @property | ||||||
|     def site_packages_dir(self): |     def site_packages_dir(self): | ||||||
| @@ -924,15 +961,7 @@ def site_packages_dir(self): | |||||||
|         Returns: |         Returns: | ||||||
|             str: site-packages directory |             str: site-packages directory | ||||||
|         """ |         """ | ||||||
|         try: |         return self.config_vars['python_lib']['false']['false'] | ||||||
|             return self.config_vars['python_lib']['true']['false'] |  | ||||||
|         except KeyError: |  | ||||||
|             return self.default_site_packages_dir |  | ||||||
| 
 |  | ||||||
|     @property |  | ||||||
|     def default_site_packages_dir(self): |  | ||||||
|         python_dir = 'python{0}'.format(self.version.up_to(2)) |  | ||||||
|         return os.path.join('lib', python_dir, 'site-packages') |  | ||||||
| 
 | 
 | ||||||
|     @property |     @property | ||||||
|     def easy_install_file(self): |     def easy_install_file(self): | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Adam J. Stewart
					Adam J. Stewart