From 59d0a1850ce4e4ec1ff2b96280b4a0b770f71cbf Mon Sep 17 00:00:00 2001 From: Frithjof Gressmann Date: Thu, 8 Oct 2020 08:32:00 +0100 Subject: [PATCH] Support static host info methods in project registration --- CHANGELOG.md | 1 + src/machinable/storage/views/__init__.py | 2 +- src/machinable/utils/host.py | 3 ++- tests/storage/storage_test.py | 5 ++++- tests/test_project/_machinable.py | 4 ++++ 5 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d6e8851..330ca7d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ # Unreleased +- Support static host info methods in Registration - New `find_experiments` method to simplify recursive search for experiments in a given directory ## v2.5.2 diff --git a/src/machinable/storage/views/__init__.py b/src/machinable/storage/views/__init__.py index f776a9b8..1c29733f 100644 --- a/src/machinable/storage/views/__init__.py +++ b/src/machinable/storage/views/__init__.py @@ -1 +1 @@ -from .views import StorageExperimentView, StorageComponentView, StorageView +from .views import StorageComponentView, StorageExperimentView, StorageView diff --git a/src/machinable/utils/host.py b/src/machinable/utils/host.py index 67dcfec7..2355fa97 100644 --- a/src/machinable/utils/host.py +++ b/src/machinable/utils/host.py @@ -21,7 +21,8 @@ def get_host_info(registration=True): if registration: registration = Registration.get() for name, method in inspect.getmembers( - registration, predicate=inspect.ismethod + registration, + predicate=lambda x: inspect.isfunction(x) or inspect.ismethod(x), ): if name.startswith("host_"): _getters[name[5:]] = method diff --git a/tests/storage/storage_test.py b/tests/storage/storage_test.py index 3aea8ff9..68bac597 100644 --- a/tests/storage/storage_test.py +++ b/tests/storage/storage_test.py @@ -30,6 +30,9 @@ def test_storage_experiment(): assert o.project_name == "test_project" assert o.url == "osfs://./_test_data/storage/tttttt" assert o.components.first().config.test + assert o.host.test_info == "test_info" + assert o.host.test_info_static == "static_test_info" + assert len(o.host) == 10 assert len(o.components) == 4 experiments = o.experiments @@ -51,7 +54,7 @@ def test_component_storage(): assert comp.store("key") == "value" assert "test" in comp.store() assert len(comp.store()["__files"]) - assert len(comp.host) == 9 + assert len(comp.host) == 10 assert len(comp.get_records()) == 2 comp = get_experiment(get_path("subdirectory/TTTTTT")) diff --git a/tests/test_project/_machinable.py b/tests/test_project/_machinable.py index 1b1559be..55bf32eb 100644 --- a/tests/test_project/_machinable.py +++ b/tests/test_project/_machinable.py @@ -7,6 +7,10 @@ class Project(Registration): def config_global_conf(self, works=False): return works + @staticmethod + def host_test_info_static(): + return "static_test_info" + def host_test_info(self): return "test_info"