Skip to content

Instantly share code, notes, and snippets.

@Hosuke
Last active July 18, 2023 10:06
Show Gist options
  • Save Hosuke/e5b2ca1a5fc8c2bd960b55e260a98b24 to your computer and use it in GitHub Desktop.
Save Hosuke/e5b2ca1a5fc8c2bd960b55e260a98b24 to your computer and use it in GitHub Desktop.
import json
def get_model_dependencies(manifest_file, model_name):
with open(manifest_file, 'r') as f:
manifest = json.load(f)
def get_dependencies(full_model_name, indent=0):
if full_model_name.startswith('model.'):
model = manifest['nodes'].get(full_model_name)
if model is None:
print(f"{' ' * indent}Model {full_model_name} not found.")
return
print(f"{' ' * indent}Model {full_model_name}:")
dependencies = model['depends_on']['nodes']
elif full_model_name.startswith('source.'):
# Skip sources
return
else:
print(f"{' ' * indent}Unknown type {full_model_name}")
return
for ref in dependencies:
print(f"{' ' * (indent + 2)}Depends on: {ref}")
get_dependencies(ref, indent + 4)
get_dependencies('model.' + model_name)
# Replace 'manifest.json' with the path to your manifest file
# Replace 'my_model' with the name of your model
get_model_dependencies('manifest.json', 'my_model')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment