Last active
August 12, 2016 12:39
-
-
Save kormat/bc51c158044dbd37b16dc13b90334120 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
# Small script to automate finding all external dependencies of a Go directory | |
# Example use: | |
# go get -v $(godeps.py) | |
import json | |
import subprocess | |
def main(): | |
top = subprocess.check_output(["go", "list", "-e"], | |
universal_newlines=True).strip() | |
raw = subprocess.check_output(["go", "list", "-json", "./..."], | |
universal_newlines=True) | |
def impFilter(dep): | |
return not dep.startswith(top) and "/" in dep | |
decoder = json.JSONDecoder() | |
deps = set() | |
while raw: | |
data, index = decoder.raw_decode(raw) | |
raw = raw[index+1:] # Skip trailing newline | |
deps.update(filter(impFilter, data.get("Imports", []))) | |
deps.update(filter(impFilter, data.get("TestImports", []))) | |
for dep in sorted(deps): | |
print("%s/..." % dep) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://plus.google.com/u/0/111618288042013846231/posts/NeFpeWDGy3E for context.