Skip to content

Instantly share code, notes, and snippets.

@tbreeds
Created June 22, 2016 05:09
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 tbreeds/f250b964383922bdea4645740ae4b195 to your computer and use it in GitHub Desktop.
Save tbreeds/f250b964383922bdea4645740ae4b195 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from __future__ import print_function
import os
import packaging.utils
import packaging.requirements
import sys
try:
gr = sys.argv[1]
except IndexError:
gr = '~/projects/openstack/openstack/requirements/global-requirements.txt'
with open(os.path.expanduser(gr)) as gr:
for line in gr:
if line.startswith('#') or line == '\n':
print(line, end='')
else:
if '#' in line:
(line, _, license) = line.partition('#')
requirement = line.rstrip().lstrip()
r = packaging.requirements.Requirement(requirement)
r.name = packaging.utils.canonicalize_name(r.name)
print("%s #%s" %(r, license), end='')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment