Last active
April 30, 2016 14:38
-
-
Save nycynik/dfdfb220186716e8cd008ae77ffe47e5 to your computer and use it in GitHub Desktop.
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 sys | |
try: | |
import xmlrpclib # Python 2 | |
except ImportError: | |
import xmlrpc.client as xmlrpclib # Python 3 | |
# | |
# Python script to create a document of your requirements for a | |
# python project. Prints the home page of each project | |
# | |
# TODO: Have it use the correct version during the search, right now | |
# script is throwing it away. | |
# | |
# | |
# get reqs | |
# | |
reqFiles = ['requirements.txt'] | |
requirements = [] | |
# read one requirements file | |
def do_requirements_file(req_file): | |
global reqFiles, requirements | |
print "Gathering requirements from %s" % req_file | |
with open(req_file, "r") as ins: | |
reqs = [] | |
for line in ins: | |
req = line.split() | |
# skip blank lines | |
if len(req) == 0: | |
continue | |
# skip comments | |
if req[0][0] == '#': | |
continue | |
# add child requirements files | |
if req[0] == '-r': | |
print " Adding %s." % req[1] | |
reqFiles.append(req[1]) | |
continue | |
requirements.append(req[0]) | |
def do_requirements_files(): | |
while len(reqFiles) > 0: | |
do_requirements_file(reqFiles.pop(0)) | |
def removeVersion(req): | |
req = req.replace('=', '>') | |
req = req.replace('<', '>') | |
req = req.replace('+', '>') | |
just_req = req.split('>') | |
if len(just_req) > 0: | |
if just_req[0] != 'git': | |
return just_req[0] | |
return "" | |
# create output doc file | |
def doc_packages(): | |
pypi = xmlrpclib.ServerProxy('http://pypi.python.org/pypi') | |
for req in requirements: | |
package_name = removeVersion(req) | |
if (package_name != ""): | |
try: | |
packages = pypi.search({"name": package_name}) | |
package = next(package for package in packages if package["name"] == package_name) | |
release_data = pypi.release_data(package_name, package["version"]) | |
print "Name: %s" % package_name | |
print "Version: %s" % package["version"] | |
print "Summary: %s" % release_data["summary"] | |
print "Home Page: %s" % release_data["home_page"] | |
except StopIteration: | |
print "Name: %s" % package_name | |
print "** Information not found **\n" | |
else: | |
print "Package '%s' not found\n" % req | |
do_requirements_files() | |
doc_packages() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment