From a145ff2b3506cc8ebebfa4b19950b9d187c7f486 Mon Sep 17 00:00:00 2001 From: Marvin Poul Date: Sat, 20 Jul 2024 21:57:36 +0200 Subject: [PATCH] Instantiate QueueAdapter only once per folder In case both clusters.yaml and queues.yaml are present in a resource folder, the old code created two (equivalent) queue adapters. --- pyiron_base/state/queue_adapter.py | 8 ++++---- tests/unit/state/test_queue_adapter.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pyiron_base/state/queue_adapter.py b/pyiron_base/state/queue_adapter.py index f613de550..1eb69a849 100644 --- a/pyiron_base/state/queue_adapter.py +++ b/pyiron_base/state/queue_adapter.py @@ -46,13 +46,13 @@ def __init__(self): def construct_adapters(self) -> None: """Read through the resources and construct queue adapters for all the queue configuration files found.""" - queue_files = ResourceResolver( + queue_folders = set(map(os.path.dirname, ResourceResolver( settings.resource_paths, "queues", - ).search(["queue.yaml", "clusters.yaml"]) + ).search(["queue.yaml", "clusters.yaml"]))) self._adapters = [ - PySQAAdpter(directory=os.path.dirname(queue_file)) - for queue_file in queue_files + PySQAAdpter(directory=queue_folder) + for queue_folder in queue_folders ] @property diff --git a/tests/unit/state/test_queue_adapter.py b/tests/unit/state/test_queue_adapter.py index f5251763d..f071fc196 100644 --- a/tests/unit/state/test_queue_adapter.py +++ b/tests/unit/state/test_queue_adapter.py @@ -57,7 +57,7 @@ def tearDownClass(cls) -> None: def test_construction(self): self.assertEqual( - 3, + 2, len(queue_adapters._adapters), msg="The zeroth resource does not have yaml files and should not produce a queue", )