Skip to content

Commit

Permalink
Modify config.yaml modules option to add module dirs to MODULEPATH
Browse files Browse the repository at this point in the history
  • Loading branch information
Jo Basevi committed Aug 3, 2023
1 parent c8e7424 commit 8c8c691
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 3 deletions.
6 changes: 5 additions & 1 deletion payu/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def load_modules(self):
envmod.module('load', mod)

# User-defined modules
user_modules = self.config.get('modules', [])
user_modules = self.config.get('modules', {}).get('load', [])
for mod in user_modules:
envmod.module('load', mod)

Expand Down Expand Up @@ -457,6 +457,10 @@ def run(self, *user_flags):

# XXX: This was previously done in reversion
envmod.setup()

# Add any user-defined module dir(s) to MODULEPATH
for module_dir in self.config.get('modules', {}).get('use', []):
envmod.module('use', module_dir)

self.load_modules()

Expand Down
6 changes: 6 additions & 0 deletions payu/fsops.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ def read_config(config_fname=None):

config['collate'] = collate_config

# Transform legacy modules config options
modules_config = config.pop('modules', {})
if type(modules_config) is list:
modules_config = {'load': modules_config}
config['modules'] = modules_config

# Local "control" path. Must be set here so it can be
# scanned for storage points
config["control_path"] = config.get('control',
Expand Down
3 changes: 3 additions & 0 deletions test/resources/config_legacy_modules.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
modules:
- module_1
- module_2
7 changes: 7 additions & 0 deletions test/resources/config_modules.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
modules:
use:
- path/to/module/dir/1
- path/to/module/dir/2
load:
- module_1
- module_2
File renamed without changes.
27 changes: 25 additions & 2 deletions test/test_payu.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def test_movetree():


def test_read_config():
config_path = os.path.join('test', 'config_mom5.yaml')
config_path = os.path.join('test', 'resources', 'config_mom5.yaml')
config = payu.fsops.read_config(config_path)

# Test control_path is not set in read_config
Expand All @@ -148,11 +148,34 @@ def test_read_config():

assert(config.pop('collate') == {})
assert(config.pop('control_path') == os.getcwd())
assert(config.pop('modules') == {})
assert(config == {})

os.remove(config_tmp)


def test_read_config_modules_legacy_option():
# Test transform legacy modules option
config_path = os.path.join('test', 'resources', 'config_legacy_modules.yaml')

config = payu.fsops.read_config(config_path)
modules_config = config.get('modules', {})

assert(modules_config.get('load', []) == ['module_1', 'module_2'])
assert(modules_config.get('use', []) == [])


def test_read_config_modules_option():
# Test modules with load/use options is unchanged
config_path = os.path.join('test', 'resources', 'config_modules.yaml')

config = payu.fsops.read_config(config_path)
modules_config = config.get('modules', {})

assert(modules_config.get('load', []) == ['module_1', 'module_2'])
assert(modules_config.get('use', []) == ['path/to/module/dir/1', 'path/to/module/dir/2'])


def test_make_symlink():
tmp_path = 'tmp_file'
tmp_sym = 'tmp_sym'
Expand Down Expand Up @@ -222,7 +245,7 @@ def test_parse_ldd_output():
with open(ldd_output_path, 'r') as f:
ldd_output = f.read()
required_libs = payu.fsops.parse_ldd_output(ldd_output)
assert(len(required_libs), 4)
assert(len(required_libs), 4)
assert(required_libs['libmpi.so.40'], '/apps/openmpi/4.0.2/lib/libmpi.so.40')


Expand Down

0 comments on commit 8c8c691

Please sign in to comment.