Commit a08076ad authored by Reinout van Rees's avatar Reinout van Rees

Refactored code duplication

parent 93c61dd3
...@@ -171,10 +171,7 @@ class Installer: ...@@ -171,10 +171,7 @@ class Installer:
self._index = _get_index(index, links, self._allow_hosts) self._index = _get_index(index, links, self._allow_hosts)
if versions is not None: if versions is not None:
# Normalize all versions to lowercase. PyPI is case-insensitive self._versions = normalize_versions(versions)
# and not all distributions are consistent in their own naming.
self._versions = dict([(k.lower(), v)
for (k, v) in versions.items()])
def _satisfied(self, req, source=None): def _satisfied(self, req, source=None):
dists = [dist for dist in self._env[req.project_name] if dist in req] dists = [dist for dist in self._env[req.project_name] if dist in req]
...@@ -688,11 +685,20 @@ class Installer: ...@@ -688,11 +685,20 @@ class Installer:
if tmp != self._download_cache: if tmp != self._download_cache:
shutil.rmtree(tmp) shutil.rmtree(tmp)
def normalize_versions(versions):
"""Return version dict with keys normalized to lowercase.
PyPI is case-insensitive and not all distributions are consistent in
their own naming.
"""
return dict([(k.lower(), v) for (k, v) in versions.items()])
def default_versions(versions=None): def default_versions(versions=None):
old = Installer._versions old = Installer._versions
if versions is not None: if versions is not None:
Installer._versions = dict([(k.lower(), v) Installer._versions = normalize_versions(versions)
for (k, v) in versions.items()])
return old return old
def download_cache(path=-1): def download_cache(path=-1):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment