summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMassimiliano Culpo <massimiliano.culpo@gmail.com>2021-05-04 07:26:48 +0200
committerGitHub <noreply@github.com>2021-05-03 22:26:48 -0700
commit10389b2b515080d0bd7756e0a96b1fb58ac4c66c (patch)
treed446f49fbee83295d37f396f07f49bc4810b3a64 /lib
parent88b30090efb83a5edc6b241b31e1871b5eb3ca77 (diff)
downloadspack-10389b2b515080d0bd7756e0a96b1fb58ac4c66c.tar.gz
spack-10389b2b515080d0bd7756e0a96b1fb58ac4c66c.tar.bz2
spack-10389b2b515080d0bd7756e0a96b1fb58ac4c66c.tar.xz
spack-10389b2b515080d0bd7756e0a96b1fb58ac4c66c.zip
Use Python's built-in machinery to import compilers (#23290)
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/compilers/__init__.py15
1 files changed, 7 insertions, 8 deletions
diff --git a/lib/spack/spack/compilers/__init__.py b/lib/spack/spack/compilers/__init__.py
index 83503f09ed..817d21add6 100644
--- a/lib/spack/spack/compilers/__init__.py
+++ b/lib/spack/spack/compilers/__init__.py
@@ -24,11 +24,10 @@ import spack.spec
import spack.config
import spack.compiler
import spack.architecture
-import spack.util.imp as simp
+
from spack.util.environment import get_path
from spack.util.naming import mod_to_class
-_imported_compilers_module = 'spack.compilers'
_path_instance_vars = ['cc', 'cxx', 'f77', 'fc']
_flags_instance_vars = ['cflags', 'cppflags', 'cxxflags', 'fflags']
_other_instance_vars = ['modules', 'operating_system', 'environment',
@@ -472,17 +471,17 @@ def get_compiler_duplicates(compiler_spec, arch_spec):
@llnl.util.lang.memoized
def class_for_compiler_name(compiler_name):
"""Given a compiler module name, get the corresponding Compiler class."""
- assert(supported(compiler_name))
+ assert supported(compiler_name)
# Hack to be able to call the compiler `apple-clang` while still
# using a valid python name for the module
- module_name = compiler_name
+ submodule_name = compiler_name
if compiler_name == 'apple-clang':
- module_name = compiler_name.replace('-', '_')
+ submodule_name = compiler_name.replace('-', '_')
- file_path = os.path.join(spack.paths.compilers_path, module_name + ".py")
- compiler_mod = simp.load_source(_imported_compilers_module, file_path)
- cls = getattr(compiler_mod, mod_to_class(compiler_name))
+ module_name = '.'.join(['spack', 'compilers', submodule_name])
+ module_obj = __import__(module_name, fromlist=[None])
+ cls = getattr(module_obj, mod_to_class(compiler_name))
# make a note of the name in the module so we can get to it easily.
cls.name = compiler_name