Last active
October 20, 2021 20:22
-
-
Save ericdill/9942ac55c2c9f6a550973dd2dc3653a4 to your computer and use it in GitHub Desktop.
Render the dependency graph for your conda environment (needs graphviz!)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import glob | |
import os | |
from os.path import join, basename | |
# install this with "conda install -c conda-forge python-graphviz" | |
import graphviz as gv | |
# path to your conda environment | |
path = os.environ.get('CONDA_PREFIX') | |
if path is None: | |
print("Not in a conda environment, activate a conda env or set CONDA_PREFIX to the conda env you want to render before calling this script") | |
sys.exit(1) | |
dg = gv.Digraph(filename='env-%s' % basename(path), format='svg') | |
for json_file in glob.glob(join(path, 'conda-meta', '*.json')): | |
print('reading', json_file) | |
j = json.load(open(json_file)) | |
dg.node(j['name']) | |
for dep in j.get('depends', []): | |
dg.edge(j['name'], dep.split(' ')[0]) | |
dg.render() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
expanded example that uses repodata.json instead of json in packages: https://gist.github.com/msarahan/f425082c67bd985cb4edd0edb4d50de0