Skip to content

Instantly share code, notes, and snippets.

@willkg
Created August 5, 2014 17:34
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 willkg/2b7814b54ce6a20e72e3 to your computer and use it in GitHub Desktop.
Save willkg/2b7814b54ce6a20e72e3 to your computer and use it in GitHub Desktop.
goes through a vendor/lib/ dir and generates requirements.txt for what's there
import argparse
import os
def get_python_packages(packages_dir):
os.chdir(packages_dir)
paths = [path for path in os.listdir('.') if os.path.isdir(path)]
packages = {}
for package_name in paths:
print 'Working on {0}'.format(package_name)
version = ''
try:
with open(os.path.join(package_name, 'PKG-INFO'), 'rb') as fp:
version = [line for line in fp.readlines() if line.startswith('Version: ')]
if version:
# Grab the first line and nix the Version: label
version = version[0].replace('Version: ', '').strip()
except Exception as exc:
print package_name, exc
packages[package_name] = version
return packages
if __name__ == '__main__':
parser = argparse.ArgumentParser(prog='peepify')
parser.add_argument('--packages-dir', required=True,
help='Top level directory for python packages.')
args = parser.parse_args()
cwd = os.getcwd()
packages = get_python_packages(args.packages_dir)
missing_versions = []
for name, version in packages.items():
if not version:
missing_versions.append(name)
continue
print '{0}=={1}'.format(name, version)
print ''
if missing_versions:
print 'These are missing version information:'
for name in missing_versions:
print name
@willkg
Copy link
Author

willkg commented Aug 5, 2014

I wrote enough of this to migrate the vendor/packages/ directory in fjord to a requirements.txt file format. It's likely there are things that don't work. It doesn't figure out the shas for anything.

Feel free to use it as you so desire.

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