summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMassimiliano Culpo <massimiliano.culpo@gmail.com>2021-05-04 07:26:48 +0200
committerTodd Gamblin <tgamblin@llnl.gov>2021-05-22 11:51:20 -0700
commit0d173bb32bebd2eb6b907268b6dfdf4982cc2f1b (patch)
tree107823dba42a62f48ce602b4030074ccc1fb9438 /lib
parent8a7bfe97c31b5c5b16dc5a79dba6adbb91c618ea (diff)
downloadspack-0d173bb32bebd2eb6b907268b6dfdf4982cc2f1b.tar.gz
spack-0d173bb32bebd2eb6b907268b6dfdf4982cc2f1b.tar.bz2
spack-0d173bb32bebd2eb6b907268b6dfdf4982cc2f1b.tar.xz
spack-0d173bb32bebd2eb6b907268b6dfdf4982cc2f1b.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 3c1f9ffa44..85e0275a29 100644
--- a/lib/spack/spack/compilers/__init__.py
+++ b/lib/spack/spack/compilers/__init__.py
@@ -22,11 +22,10 @@ import spack.error
import spack.spec
import spack.config
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',
@@ -470,17 +469,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