From 97afcc216d173f3ebc628e8051ec9ef8b0e92ed2 Mon Sep 17 00:00:00 2001 From: dachengx Date: Sat, 14 Sep 2024 18:33:37 -0500 Subject: [PATCH 1/2] Add `run_id` independent function to get the dependencies `datat_type` --- strax/context.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/strax/context.py b/strax/context.py index 3d6b5bda..5dfa502d 100644 --- a/strax/context.py +++ b/strax/context.py @@ -2641,12 +2641,28 @@ def provided_dtypes(self, runid="0"): for data_type, _hash, save_when, version in hashes } + def get_dependencies(self, data_type): + """Get the dependencies of a data_type.""" + dependencies = set() + + def _get_dependencies(_data_type): + if _data_type in self.root_data_types: + return + plugin = self._plugin_class_registry[_data_type]() + dependencies.update(plugin.depends_on) + for d in plugin.depends_on: + _get_dependencies(d) + + _get_dependencies(data_type) + return dependencies + @property def root_data_types(self): """Root data_type that does not depend on anything.""" _root_data_types = set() for k, v in self._plugin_class_registry.items(): - if not v.depends_on: + _v = v() + if not _v.depends_on: _root_data_types |= set((k,)) return _root_data_types From dcce6295e67ebf31b16fa61870c7e328fe0880a6 Mon Sep 17 00:00:00 2001 From: dachengx Date: Sat, 14 Sep 2024 18:42:45 -0500 Subject: [PATCH 2/2] Add test of `get_dependencies` --- tests/test_context.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/test_context.py b/tests/test_context.py index bd8ad10c..32de5f60 100644 --- a/tests/test_context.py +++ b/tests/test_context.py @@ -520,3 +520,10 @@ def test_get_data_kinds(self): "cut_peaks": "peaks", } assert data_type_collection == expected_data_type_collection + + def test_get_dependencies(self): + st = self.get_context(True) + st.register(Records) + st.register(Peaks) + st.register(self.get_dummy_peaks_dependency()) + assert "records" in st.get_dependencies("cut_peaks")