Skip to content

Commit

Permalink
Merge pull request #194 from ecmwf-ifs/naml-scheduler-disable-wildcard
Browse files Browse the repository at this point in the history
Allow wildcards in `disable` list for scheduler
  • Loading branch information
reuterbal authored Nov 29, 2023
2 parents 04b7c1c + 74b6ac4 commit 955a9da
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
4 changes: 3 additions & 1 deletion loki/bulk/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# nor does it submit to any jurisdiction.

from abc import abstractmethod
from fnmatch import fnmatch
try:
from functools import cached_property
except ImportError:
Expand Down Expand Up @@ -326,7 +327,8 @@ def children(self):

# Filter out local members and disabled sub-branches
children = [c for c in children if c not in self.members]
children = [c for c in children if c not in disabled]
for d in disabled:
children = [c for c in children if not fnmatch(c, d)]

# Remove duplicates
return as_tuple(dict.fromkeys(children))
Expand Down
70 changes: 70 additions & 0 deletions tests/test_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2265,3 +2265,73 @@ def test_scheduler_unqualified_imports(config):

assert item.enable_imports
assert item.children == ('other_routine',)


def test_scheduler_disable_wildcard(here, config):

fcode_mod = """
module field_mod
type field2d
contains
procedure :: init => field_init
end type
type field3d
contains
procedure :: init => field_init
end type
contains
subroutine field_init()
end subroutine
end module
"""

fcode_driver = """
subroutine my_driver
use field_mod, only: field2d, field3d, field_init
implicit none
type(field2d) :: a, b
type(field3d) :: c, d
call a%init()
call b%init()
call c%init()
call field_init(d)
end subroutine my_driver
"""

# Set up the test files
dirname = here/'test_scheduler_disable_wildcard'
dirname.mkdir(exist_ok=True)
modfile = dirname/'field_mod.F90'
modfile.write_text(fcode_mod)
testfile = dirname/'test.F90'
testfile.write_text(fcode_driver)

config['default']['disable'] = ['*%init']

scheduler = Scheduler(paths=dirname, seed_routines=['my_driver'], config=config)

expected_items = [
'#my_driver', 'field_mod#field_init',
]
expected_dependencies = [
('#my_driver', 'field_mod#field_init'),
]

assert all(n in scheduler.items for n in expected_items)
assert all(e in scheduler.dependencies for e in expected_dependencies)

assert 'field_mod#field2d%init' not in scheduler.items
assert 'field_mod#field3d%init' not in scheduler.items

# Clean up
try:
modfile.unlink()
testfile.unlink()
dirname.rmdir()
except FileNotFoundError:
pass

0 comments on commit 955a9da

Please sign in to comment.