Skip to content

Commit

Permalink
Add run_id independent function to get the dependencies datat_type (
Browse files Browse the repository at this point in the history
#892)

* Add `run_id`  independent function to get the dependencies `datat_type`

* Add test of `get_dependencies`
  • Loading branch information
dachengx committed Sep 15, 2024
1 parent d4964b6 commit 0cfe543
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
18 changes: 17 additions & 1 deletion strax/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions tests/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

0 comments on commit 0cfe543

Please sign in to comment.