Last active
August 29, 2015 14:26
-
-
Save kaidokert/9437f666fc19f86fb742 to your computer and use it in GitHub Desktop.
Use pip to find all available and matching versions of a package
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 logging | |
import pip | |
log = logging.getLogger(__name__) | |
def check_package(package): | |
requirement = pip.req.InstallRequirement.from_line(package) | |
finder = pip.index.PackageFinder([], | |
index_urls=[pip.models.PyPI.simple_url], | |
session=pip.download.PipSession(cache=( | |
pip.locations.USER_CACHE_DIR)) | |
) | |
all_of_the_things = finder._find_all_versions(requirement.name) | |
latest_thing = finder.find_requirement(requirement, None) | |
versions = [x.version.public for x in all_of_the_things] | |
log.info('Available versions {!r}'.format(versions)) | |
log.info('Match {!r}'.format(latest_thing.filename)) | |
logging.basicConfig(format='%(asctime)s %(module)s %(message)s', | |
level=logging.INFO) | |
logging.getLogger('pip').setLevel(logging.INFO) | |
for p in ['django', 'requests', 'nose']: | |
check_package(p) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment