#!/usr/bin/env python

import json
from pip.req import parse_requirements
from pip.download import PipSession
from pip._vendor import pkg_resources
from pip._vendor.six import print_

requirements = [pkg_resources.Requirement(str(req.req)) for req
                in parse_requirements('requirements.txt', session=PipSession())]

transform = lambda dist: {
        'name': dist.project_name,
        'version': dist.version,
        'location': dist.location,
        'dependencies': list(map(lambda dependency: dependency.project_name, dist.requires())),
        }

packages = [transform(dist) for dist
            in pkg_resources.working_set.resolve(requirements)]

print_(json.dumps(packages))

#!/usr/bin/env python

import json
from pip.req import parse_requirements
from pip.download import PipSession
from pip._vendor import pkg_resources
from pip._vendor.six import print_

requirements = [pkg_resources.Requirement.parse(str(req.req)) for req
                in parse_requirements('requirements.txt', session=PipSession())]

transform = lambda dist: {
        'name': dist.project_name,
        'version': dist.version,
        'location': dist.location,
        'dependencies': list(map(lambda dependency: dependency.project_name, dist.requires())),
        }

packages = [transform(dist) for dist
            in pkg_resources.working_set.resolve(requirements)]

print_(json.dumps(packages))

Use parse() method to instantiate Requirement
Use parse() method to instantiate Requirement

[Fix #224]

Signed-off-by: Tony Wong <3261da024e85c36767bb9324ced93ba4333a2c77@pivotal.io>
