Last active
July 7, 2018 15:30
-
-
Save jasongrout/e7d1784f8f4972129fbe4699854b7286 to your computer and use it in GitHub Desktop.
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 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