Skip to content

Commit

Permalink
Fix xtrigger get_func bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
hjoliver committed Jan 26, 2024
1 parent 8ad68b9 commit f20559b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
1 change: 1 addition & 0 deletions cylc/flow/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1795,6 +1795,7 @@ def generate_triggers(self, lexpression, left_nodes, right, seq,
)

if self.xtrigger_mgr is None:
# Validation only.
XtriggerManager.validate_xtrigger(label, xtrig, self.fdir)
else:
self.xtrigger_mgr.add_trig(label, xtrig, self.fdir)
Expand Down
8 changes: 4 additions & 4 deletions cylc/flow/subprocpool.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ def get_func(mod_name, func_name, src_dir):
AttributeError, if the function is not found in the module
"""
if func_name in _XTRIG_FUNCS:
if (mod_name, func_name) in _XTRIG_FUNCS:
# Found and cached already.
return _XTRIG_FUNCS[func_name]
return _XTRIG_FUNCS[(mod_name, func_name)]

# 1. look in <src-dir>/lib/python.
sys.path.insert(0, os.path.join(src_dir, 'lib', 'python'))
Expand All @@ -94,8 +94,8 @@ def get_func(mod_name, func_name, src_dir):

# Module found and imported, return the named function.

_XTRIG_FUNCS[func_name] = getattr(mod_by_name, func_name)
return _XTRIG_FUNCS[func_name]
_XTRIG_FUNCS[(mod_name, func_name)] = getattr(mod_by_name, func_name)
return _XTRIG_FUNCS[(mod_name, func_name)]


def run_function(func_name, json_args, json_kwargs, src_dir):
Expand Down
3 changes: 1 addition & 2 deletions cylc/flow/xtriggers/wall_clock.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,11 @@ def validate_config(f_args, f_kwargs, f_signature):
wall_clock(PT1H)
wall_clock(offset=PT1H)
And offset must be a valid ISO 8601 interval.
The offset must be a valid ISO 8601 interval.
If f_args used, convert to f_kwargs for clarity.
"""

n_args = len(f_args)
n_kwargs = len(f_kwargs)

Expand Down
14 changes: 6 additions & 8 deletions tests/unit/test_subprocpool.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,20 +167,18 @@ def test_xfunction_cache(self):
python_dir.mkdir(parents=True)
amandita_file = python_dir / "amandita.py"
with amandita_file.open(mode="w") as f:
f.write("""amandita = lambda: 'chocolate'""")
f.write("""choco = lambda: 'chocolate'""")
f.flush()
f_name = "amandita"
fn = get_func(f_name, f_name, temp_dir)
m_name = "amandita" # module
f_name = "choco" # function
fn = get_func(m_name, f_name, temp_dir)
result = fn()
self.assertEqual('chocolate', result)

# is in the cache
self.assertTrue('amandita' in _XTRIG_FUNCS)
self.assertTrue((m_name, f_name) in _XTRIG_FUNCS)
# returned from cache
self.assertEqual(fn, get_func(f_name, f_name, temp_dir))
del _XTRIG_FUNCS['amandita']
# is not in the cache
self.assertFalse('amandita' in _XTRIG_FUNCS)
self.assertEqual(fn, get_func(m_name, f_name, temp_dir))

def test_xfunction_import_error(self):
"""Test for error on importing a xtrigger function.
Expand Down

0 comments on commit f20559b

Please sign in to comment.