From 0cfe5439db62a2e68310ad6b9d6efb1023af05e4 Mon Sep 17 00:00:00 2001 From: Dacheng Xu Date: Sun, 15 Sep 2024 07:30:20 -0400 Subject: [PATCH] Add `run_id` independent function to get the dependencies `datat_type` (#892) * Add `run_id` independent function to get the dependencies `datat_type` * Add test of `get_dependencies` --- strax/context.py | 18 +++++++++++++++++- tests/test_context.py | 7 +++++++ 2 files changed, 24 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 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")