diff --git a/update.py b/update.py index effbfc1381..8a49c154d8 100644 --- a/update.py +++ b/update.py @@ -31,7 +31,7 @@ import os import os.path import sys -from pip import req +import pkg_resources VERBOSE = None @@ -67,7 +67,6 @@ setuptools.setup( pbr=True) """ - # A header for the requirements file(s). _REQS_HEADER = [ '# The order of packages is significant, because pip processes ' @@ -93,17 +92,14 @@ class Change(object): return "%-30.30s -> %s" % (self.old, self.new) -def _parse_pip(pip): +def _package_name(pip_line): + """Return normalized (lower case) package name. - install_require = req.InstallRequirement.from_line(pip) - if install_require.editable: - return pip - elif hasattr(install_require, "url") and install_require.url: - return pip - elif hasattr(install_require, "link") and install_require.link: - return pip - else: - return install_require.req.key + This is needed for comparing old and new dictionaries of + requirements to ensure they match. + """ + name = pkg_resources.Requirement.parse(pip_line).project_name + return name.lower() def _pass_through(pip): @@ -115,9 +111,7 @@ def _pass_through(pip): def _functionally_equal(old_requirement, new_requirement): - old_require = req.InstallRequirement.from_line(old_requirement) - new_require = req.InstallRequirement.from_line(new_requirement) - return old_require.req == new_require.req + return old_requirement == new_requirement def _read(filename): @@ -139,7 +133,7 @@ def _parse_reqs(filename): pip = pip.strip() if _pass_through(pip): continue - reqs[_parse_pip(pip)] = pip + reqs[_package_name(pip)] = pip return reqs @@ -167,7 +161,7 @@ def _sync_requirements_file(source_reqs, dev_reqs, dest_path, new_reqs.write(old_line) continue - old_pip = _parse_pip(old_require.lower()) + old_pip = _package_name(old_require) # Special cases: # projects need to align hacking version on their own time @@ -177,8 +171,8 @@ def _sync_requirements_file(source_reqs, dev_reqs, dest_path, if old_pip in source_reqs: # allow it to be in dev-requirements - if ((old_pip in dev_reqs) and (old_require.lower() == - dev_reqs[old_pip])): + if ((old_pip in dev_reqs) and ( + old_require == dev_reqs[old_pip])): new_reqs.write("%s\n" % dev_reqs[old_pip]) elif _functionally_equal(old_require, source_reqs[old_pip]): new_reqs.write(old_line)