Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add run_id independent function to get the dependencies datat_type #892

Merged
merged 2 commits into from
Sep 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")