modules: allow user to remove arch dir (#24156)

* allow no arch-dir modules

* add tests for modules with no arch

* document arch-specific module roots
This commit is contained in:
Greg Becker 2021-10-26 13:26:09 -07:00 committed by GitHub
parent 444e156685
commit 9a637bbd09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 58 additions and 11 deletions

View File

@ -213,6 +213,18 @@ location). The set ``my_custom_lmod_modules`` will install its lmod
modules to ``/path/to/install/custom/lmod/modules`` (and still install
its tcl modules, if any, to the default location).
By default, an architecture-specific directory is added to the root
directory. A module set may override that behavior by setting the
``arch_folder`` config value to ``False``.
.. code-block:: yaml
modules:
default:
roots:
tcl: /path/to/install/tcl/modules
arch_folder: false
Obviously, having multiple module sets install modules to the default
location could be confusing to users of your modules. In the next
section, we will discuss enabling and disabling module types (module

View File

@ -620,9 +620,14 @@ def filename(self):
if self.extension:
filename = '{0}.{1}'.format(self.use_name, self.extension)
# Architecture sub-folder
arch_folder = str(self.spec.architecture)
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 = str(self.spec.architecture)
filename = os.path.join(arch_folder, filename)
# Return the absolute path
return os.path.join(self.dirname(), arch_folder, filename)
return os.path.join(self.dirname(), filename)
class BaseContext(tengine.Context):

View File

@ -222,15 +222,18 @@ class LmodFileLayout(BaseFileLayout):
@property
def arch_dirname(self):
"""Returns the root folder for THIS architecture"""
arch_folder = '-'.join([
str(self.spec.platform),
str(self.spec.os),
str(self.spec.target.family)
])
return os.path.join(
self.dirname(), # root for lmod module files
arch_folder, # architecture relative path
)
# Architecture sub-folder
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)
])
return os.path.join(self.dirname(), arch_folder)
return self.dirname()
@property
def filename(self):

View File

@ -126,6 +126,7 @@
{'type': 'string'},
{'type': 'boolean'}
]},
'arch_folder': {'type': 'boolean'},
'prefix_inspections': {
'type': 'object',
'additionalProperties': False,

View File

@ -0,0 +1,6 @@
enable:
- lmod
arch_folder: false
lmod:
core_compilers:
- 'clang@3.3'

View File

@ -0,0 +1,6 @@
enable:
- tcl
arch_folder: false
tcl:
projections:
all: ''

View File

@ -354,3 +354,10 @@ def test_modules_relative_to_view(
# point to the right one
assert any(expected in line for line in content)
assert not any(spec.prefix in line for line in content)
def test_modules_no_arch(self, factory, module_configuration):
module_configuration('no_arch')
module, spec = factory(mpileaks_spec_string)
path = module.layout.filename
assert str(spec.os) not in path

View File

@ -404,3 +404,10 @@ def test_config_backwards_compat(self, mutable_config):
assert old_format == new_format
assert old_format == settings['tcl']
def test_modules_no_arch(self, factory, module_configuration):
module_configuration('no_arch')
module, spec = factory(mpileaks_spec_string)
path = module.layout.filename
assert str(spec.os) not in path