Skip to content

Instantly share code, notes, and snippets.

@jasongrout
Last active July 7, 2018 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasongrout/e7d1784f8f4972129fbe4699854b7286 to your computer and use it in GitHub Desktop.
Save jasongrout/e7d1784f8f4972129fbe4699854b7286 to your computer and use it in GitHub Desktop.
import sys
import json
import os
import collections
pkgs = {}
for f in os.listdir(os.path.join(sys.prefix, 'conda-meta')):
path = os.path.join(sys.prefix, 'conda-meta', f)
if path.endswith('.json'):
with open(path) as fp:
data = json.load(fp)
pkgs[data['name']] = [i.split()[0] for i in data['depends']]
revpkgs = collections.defaultdict(list)
for n in pkgs:
revpkgs[n] = []
for n,d in pkgs.items():
for p in d:
revpkgs[p].append(n)
# packages that don't depend on anything else
leaves = sorted([n for n,d in pkgs.items() if len(d)==0])
print('Packages not depending on any others: %s'%' '.join(leaves))
# packages that nobody else depends on (minimal set needed to create environment)
roots = sorted([n for n,d in revpkgs.items() if len(d)==0])
print('Package roots, no others depend on: %s'%' '.join(roots))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment