Skip to content

Instantly share code, notes, and snippets.

@stephenmcd
Created June 18, 2012 00:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephenmcd/2946195 to your computer and use it in GitHub Desktop.
Save stephenmcd/2946195 to your computer and use it in GitHub Desktop.
Build a report of Python requirements for multiple repositories.
#!/usr/bin/env python
"""
Given the current directory contains multiple repositories, each with a
requirements/project.txt file, build a report of all requirements.
"""
import os
reqs = {}
for repo in os.listdir("."):
if not os.path.isdir(repo) or repo == "site-packages":
continue
for proj in os.listdir(repo):
reqs_path = os.path.join(repo, proj, "requirements/project.txt")
if not os.path.exists(reqs_path):
continue
with open(reqs_path, "r") as f:
lines = f.readlines()
for line in lines:
line = line.strip()
version = ""
if not line or line.startswith("#") or line.startswith("--"):
continue
if line.startswith("-e"):
req = line.split("/")[-1].split("@")[0].split("#")[0].split(".git")[0]
try:
version = line.split("/")[-1].split("@")[1].split("#")[0]
except IndexError:
pass
else:
try:
req, version = line.split("==")
except ValueError:
req = line
if not version:
version = "unversioned"
print repo.ljust(25), "|".ljust(5), req.ljust(25), "|".ljust(5), version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment