예제 #1
0
def get_pypi_dependencies(package_name, calls=0):
    """ Return the list of dependencies of the given package name.

    How does it do this?

     - Check if the package is installed with pkg_resources.
     - If it's not installed, install it.
     - Check with pkg_resources again.
     - If it's not installed, give up.
     - If it is installed, use the pkg_resources module to find its
       dependencies, and their dependencies, and so on.
    """

    if calls > 2:
        raise Exception("I tried installing %s %i times.  Fail." %
                        (package_name, calls))
    try:
        return [
            r.project_name for r in
            pkg_resources.get_distribution(package_name).requires()
        ]
    except pkg_resources.DistributionNotFound as e:
        pipsupport.install_distributions([package_name])
        return get_pypi_dependencies(package_name, calls + 1)