From a9d1564714edcda51b9d582d60afd317ae8032e2 Mon Sep 17 00:00:00 2001 From: Michael Lange Date: Mon, 13 Nov 2023 10:39:15 +0000 Subject: [PATCH 1/2] Scheduler: Allow wildcards in `disable` configure option --- loki/bulk/item.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/loki/bulk/item.py b/loki/bulk/item.py index 53f7761a0..9d0d5f3f6 100644 --- a/loki/bulk/item.py +++ b/loki/bulk/item.py @@ -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: @@ -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)) From 74b6ac4afa3bdaad7a94b4fb1f564e942cd1a6fd Mon Sep 17 00:00:00 2001 From: Michael Lange Date: Sun, 26 Nov 2023 04:08:33 +0000 Subject: [PATCH 2/2] Scheduler: Add small test for wildcard use in `disable` exclusion --- tests/test_scheduler.py | 70 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/tests/test_scheduler.py b/tests/test_scheduler.py index 33ea720bf..b3192285b 100644 --- a/tests/test_scheduler.py +++ b/tests/test_scheduler.py @@ -2190,3 +2190,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