Created
August 5, 2014 17:34
-
-
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
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 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.