Skip to content

Instantly share code, notes, and snippets.

@kormat
Last active August 12, 2016 12:39
Show Gist options
  • Save kormat/bc51c158044dbd37b16dc13b90334120 to your computer and use it in GitHub Desktop.
Save kormat/bc51c158044dbd37b16dc13b90334120 to your computer and use it in GitHub Desktop.
# 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()
@kormat
Copy link
Author

kormat commented Aug 12, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment