diff options
author | Todd Gamblin <tgamblin@llnl.gov> | 2022-07-30 15:19:18 -0700 |
---|---|---|
committer | Todd Gamblin <tgamblin@llnl.gov> | 2022-07-31 13:29:20 -0700 |
commit | f52f6e99dbf1131886a80112b8c79dfc414afb7c (patch) | |
tree | 05cb7d64b2395922f2f24683da49f472075be12c /lib/spack/spack/modules/lmod.py | |
parent | 549ba1ed32372c67fc57271cde3797d58b7dec6e (diff) | |
download | spack-f52f6e99dbf1131886a80112b8c79dfc414afb7c.tar.gz spack-f52f6e99dbf1131886a80112b8c79dfc414afb7c.tar.bz2 spack-f52f6e99dbf1131886a80112b8c79dfc414afb7c.tar.xz spack-f52f6e99dbf1131886a80112b8c79dfc414afb7c.zip |
black: reformat entire repository with black
Diffstat (limited to 'lib/spack/spack/modules/lmod.py')
-rw-r--r-- | lib/spack/spack/modules/lmod.py | 126 |
1 files changed, 59 insertions, 67 deletions
diff --git a/lib/spack/spack/modules/lmod.py b/lib/spack/spack/modules/lmod.py index a64c05e880..54add9563d 100644 --- a/lib/spack/spack/modules/lmod.py +++ b/lib/spack/spack/modules/lmod.py @@ -23,11 +23,11 @@ from .common import BaseConfiguration, BaseContext, BaseFileLayout, BaseModuleFi #: lmod specific part of the configuration def configuration(module_set_name): - config_path = 'modules:%s:lmod' % module_set_name + config_path = "modules:%s:lmod" % module_set_name config = spack.config.get(config_path, {}) - if not config and module_set_name == 'default': + if not config and module_set_name == "default": # return old format for backward compatibility - return spack.config.get('modules:lmod', {}) + return spack.config.get("modules:lmod", {}) return config @@ -41,12 +41,11 @@ def make_configuration(spec, module_set_name): try: return configuration_registry[key] except KeyError: - return configuration_registry.setdefault( - key, LmodConfiguration(spec, module_set_name)) + return configuration_registry.setdefault(key, LmodConfiguration(spec, module_set_name)) def make_layout(spec, module_set_name): - """Returns the layout information for spec """ + """Returns the layout information for spec""" conf = make_configuration(spec, module_set_name) return LmodFileLayout(conf) @@ -70,15 +69,16 @@ def guess_core_compilers(name, store=False): core_compilers = [] for compiler_config in spack.compilers.all_compilers_config(): try: - compiler = compiler_config['compiler'] + compiler = compiler_config["compiler"] # A compiler is considered to be a core compiler if any of the # C, C++ or Fortran compilers reside in a system directory is_system_compiler = any( os.path.dirname(x) in spack.util.environment.system_dirs - for x in compiler['paths'].values() if x is not None + for x in compiler["paths"].values() + if x is not None ) if is_system_compiler: - core_compilers.append(str(compiler['spec'])) + core_compilers.append(str(compiler["spec"])) except (KeyError, TypeError, AttributeError): continue @@ -87,23 +87,21 @@ def guess_core_compilers(name, store=False): # in the default modify scope (i.e. within the directory hierarchy # of Spack itself) modules_cfg = spack.config.get( - 'modules:' + name, {}, scope=spack.config.default_modify_scope() - ) - modules_cfg.setdefault('lmod', {})['core_compilers'] = core_compilers - spack.config.set( - 'modules:' + name, modules_cfg, - scope=spack.config.default_modify_scope() + "modules:" + name, {}, scope=spack.config.default_modify_scope() ) + modules_cfg.setdefault("lmod", {})["core_compilers"] = core_compilers + spack.config.set("modules:" + name, modules_cfg, scope=spack.config.default_modify_scope()) return core_compilers or None class LmodConfiguration(BaseConfiguration): """Configuration class for lmod module files.""" + # Note: Posixpath is used here as well as below as opposed to # os.path.join due to spack.spec.Spec.format # requiring forward slash path seperators at this stage - default_projections = {'all': posixpath.join('{name}', '{version}')} + default_projections = {"all": posixpath.join("{name}", "{version}")} @property def core_compilers(self): @@ -114,9 +112,9 @@ class LmodConfiguration(BaseConfiguration): specified in the configuration file or the sequence is empty """ - value = configuration(self.name).get( - 'core_compilers' - ) or guess_core_compilers(self.name, store=True) + value = configuration(self.name).get("core_compilers") or guess_core_compilers( + self.name, store=True + ) if not value: msg = 'the key "core_compilers" must be set in modules.yaml' @@ -126,28 +124,26 @@ class LmodConfiguration(BaseConfiguration): @property def core_specs(self): """Returns the list of "Core" specs""" - return configuration(self.name).get('core_specs', []) + return configuration(self.name).get("core_specs", []) @property def hierarchy_tokens(self): """Returns the list of tokens that are part of the modulefile hierarchy. 'compiler' is always present. """ - tokens = configuration(self.name).get('hierarchy', []) + tokens = configuration(self.name).get("hierarchy", []) # Check if all the tokens in the hierarchy are virtual specs. # If not warn the user and raise an error. - not_virtual = [t for t in tokens - if t != 'compiler' and - not spack.repo.path.is_virtual(t)] + not_virtual = [t for t in tokens if t != "compiler" and not spack.repo.path.is_virtual(t)] if not_virtual: msg = "Non-virtual specs in 'hierarchy' list for lmod: {0}\n" msg += "Please check the 'modules.yaml' configuration files" - msg = msg.format(', '.join(not_virtual)) + msg = msg.format(", ".join(not_virtual)) raise NonVirtualInHierarchyError(msg) # Append 'compiler' which is always implied - tokens.append('compiler') + tokens.append("compiler") # Deduplicate tokens in case duplicates have been coded tokens = list(lang.dedupe(tokens)) @@ -161,13 +157,12 @@ class LmodConfiguration(BaseConfiguration): requirements. """ # If it's a core_spec, lie and say it requires a core compiler - if any(self.spec.satisfies(core_spec) - for core_spec in self.core_specs): - return {'compiler': self.core_compilers[0]} + if any(self.spec.satisfies(core_spec) for core_spec in self.core_specs): + return {"compiler": self.core_compilers[0]} # Keep track of the requirements that this package has in terms # of virtual packages that participate in the hierarchical structure - requirements = {'compiler': self.spec.compiler} + requirements = {"compiler": self.spec.compiler} # For each virtual dependency in the hierarchy for x in self.hierarchy_tokens: # If I depend on it @@ -187,23 +182,23 @@ class LmodConfiguration(BaseConfiguration): # If it is in the list of supported compilers family -> compiler if self.spec.name in spack.compilers.supported_compilers(): - provides['compiler'] = spack.spec.CompilerSpec(str(self.spec)) + provides["compiler"] = spack.spec.CompilerSpec(str(self.spec)) # Special case for llvm - if self.spec.name == 'llvm': - provides['compiler'] = spack.spec.CompilerSpec(str(self.spec)) - provides['compiler'].name = 'clang' + if self.spec.name == "llvm": + provides["compiler"] = spack.spec.CompilerSpec(str(self.spec)) + provides["compiler"].name = "clang" # Special case for llvm-amdgpu - if self.spec.name == 'llvm-amdgpu': - provides['compiler'] = spack.spec.CompilerSpec(str(self.spec)) - provides['compiler'].name = 'rocmcc' + if self.spec.name == "llvm-amdgpu": + provides["compiler"] = spack.spec.CompilerSpec(str(self.spec)) + provides["compiler"].name = "rocmcc" # Special case for oneapi - if self.spec.name == 'intel-oneapi-compilers': - provides['compiler'] = spack.spec.CompilerSpec(str(self.spec)) - provides['compiler'].name = 'oneapi' + if self.spec.name == "intel-oneapi-compilers": + provides["compiler"] = spack.spec.CompilerSpec(str(self.spec)) + provides["compiler"].name = "oneapi" # Special case for oneapi classic - if self.spec.name == 'intel-oneapi-compilers-classic': - provides['compiler'] = spack.spec.CompilerSpec(str(self.spec)) - provides['compiler'].name = 'intel' + if self.spec.name == "intel-oneapi-compilers-classic": + provides["compiler"] = spack.spec.CompilerSpec(str(self.spec)) + provides["compiler"].name = "intel" # All the other tokens in the hierarchy must be virtual dependencies for x in self.hierarchy_tokens: @@ -233,21 +228,18 @@ class LmodFileLayout(BaseFileLayout): """File layout for lmod module files.""" #: file extension of lua module files - extension = 'lua' + extension = "lua" @property def arch_dirname(self): """Returns the root folder for THIS architecture""" # Architecture sub-folder - arch_folder_conf = spack.config.get( - 'modules:%s:arch_folder' % self.conf.name, True) + arch_folder_conf = spack.config.get("modules:%s:arch_folder" % self.conf.name, True) if arch_folder_conf: # include an arch specific folder between root and filename - arch_folder = '-'.join([ - str(self.spec.platform), - str(self.spec.os), - str(self.spec.target.family) - ]) + arch_folder = "-".join( + [str(self.spec.platform), str(self.spec.os), str(self.spec.target.family)] + ) return os.path.join(self.dirname(), arch_folder) return self.dirname() @@ -269,7 +261,7 @@ class LmodFileLayout(BaseFileLayout): fullname = os.path.join( self.arch_dirname, # root for lmod files on this architecture hierarchy_name, # relative path - '.'.join([self.use_name, self.extension]) # file name + ".".join([self.use_name, self.extension]), # file name ) return fullname @@ -284,16 +276,16 @@ class LmodFileLayout(BaseFileLayout): str: part of the path associated with the service """ # General format for the path part - path_part_fmt = os.path.join('{token.name}', '{token.version}') + path_part_fmt = os.path.join("{token.name}", "{token.version}") # If we are dealing with a core compiler, return 'Core' core_compilers = self.conf.core_compilers - if name == 'compiler' and str(value) in core_compilers: - return 'Core' + if name == "compiler" and str(value) in core_compilers: + return "Core" # CompilerSpec does not have an hash, as we are not allowed to # use different flavors of the same compiler - if name == 'compiler': + if name == "compiler": return path_part_fmt.format(token=value) # In case the hierarchy token refers to a virtual provider @@ -301,7 +293,7 @@ class LmodFileLayout(BaseFileLayout): # among flavors of the same library (e.g. openblas~openmp vs. # openblas+openmp) path = path_part_fmt.format(token=value) - path = '-'.join([path, value.dag_hash(length=7)]) + path = "-".join([path, value.dag_hash(length=7)]) return path @property @@ -314,8 +306,7 @@ class LmodFileLayout(BaseFileLayout): # List of services that are part of the hierarchy hierarchy = self.conf.hierarchy_tokens # Tokenize each part that is both in the hierarchy and available - parts = [self.token_to_path(x, available[x]) - for x in hierarchy if x in available] + parts = [self.token_to_path(x, available[x]) for x in hierarchy if x in available] return parts @property @@ -336,8 +327,8 @@ class LmodFileLayout(BaseFileLayout): # A compiler is always required. To avoid duplication pop the # 'compiler' item from required if we also **provide** one - if 'compiler' in provides_key: - requires_key.remove('compiler') + if "compiler" in provides_key: + requires_key.remove("compiler") # Compute the unique combinations of the services we provide combinations = [] @@ -404,7 +395,7 @@ class LmodContext(BaseContext): # In general we have conditional modifications if we have modifications # and we are not providing **only** a compiler provides = self.conf.provides - provide_compiler_only = 'compiler' in provides and len(provides) == 1 + provide_compiler_only = "compiler" in provides and len(provides) == 1 has_modifications = self.has_modulepath_modifications return has_modifications and not provide_compiler_only @@ -417,7 +408,7 @@ class LmodContext(BaseContext): def version_part(self): """Version of this provider.""" s = self.spec - return '-'.join([str(s.version), s.dag_hash(length=7)]) + return "-".join([str(s.version), s.dag_hash(length=7)]) @tengine.context_property def provides(self): @@ -445,15 +436,15 @@ class LmodContext(BaseContext): conditional_paths = layout.unlocked_paths conditional_paths.pop(None) for services_needed, list_of_path_parts in conditional_paths.items(): - condition = ' and '.join([x + '_name' for x in services_needed]) + condition = " and ".join([x + "_name" for x in services_needed]) for parts in list_of_path_parts: def manipulate_path(token): if token in self.conf.hierarchy_tokens: - return '{0}_name, {0}_version'.format(token) + return "{0}_name, {0}_version".format(token) return '"' + token + '"' - path = ', '.join([manipulate_path(x) for x in parts]) + path = ", ".join([manipulate_path(x) for x in parts]) value.append((condition, path)) return value @@ -461,7 +452,8 @@ class LmodContext(BaseContext): class LmodModulefileWriter(BaseModuleFileWriter): """Writer class for lmod module files.""" - default_template = posixpath.join('modules', 'modulefile.lua') + + default_template = posixpath.join("modules", "modulefile.lua") class CoreCompilersNotFoundError(spack.error.SpackError, KeyError): |