diff options
author | Chris Jerdonek <chris.jerdonek@gmail.com> | 2018-10-13 00:57:17 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-13 00:57:17 -0700 |
commit | 1228f64ec00819eabd6027d82b1a829980ac2b00 (patch) | |
tree | 4a17ae26beda5efdca4f1636b931dc0127ae5715 | |
parent | 8dbbe165f80dcdf13eb6da08104f36cd9fdc43c8 (diff) | |
parent | 00a2ff198e178b440793820de78e06031c378252 (diff) | |
download | pip-1228f64ec00819eabd6027d82b1a829980ac2b00.tar.gz |
Merge pull request #5873 from cjerdonek/remove-get-backend-from-location
Simplify vcs.get_src_requirement().
-rw-r--r-- | news/D9A540D9-7665-48A5-A1C8-5141ED49E404.trivial | 0 | ||||
-rw-r--r-- | src/pip/_internal/operations/freeze.py | 10 | ||||
-rw-r--r-- | src/pip/_internal/vcs/__init__.py | 45 |
3 files changed, 23 insertions, 32 deletions
diff --git a/news/D9A540D9-7665-48A5-A1C8-5141ED49E404.trivial b/news/D9A540D9-7665-48A5-A1C8-5141ED49E404.trivial new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/news/D9A540D9-7665-48A5-A1C8-5141ED49E404.trivial diff --git a/src/pip/_internal/operations/freeze.py b/src/pip/_internal/operations/freeze.py index b173875bf..af484f2c1 100644 --- a/src/pip/_internal/operations/freeze.py +++ b/src/pip/_internal/operations/freeze.py @@ -173,12 +173,18 @@ class FrozenRequirement(object): """ location = os.path.normcase(os.path.abspath(dist.location)) from pip._internal.vcs import vcs, get_src_requirement - if not dist_is_editable(dist) or not vcs.get_backend_name(location): + if not dist_is_editable(dist): + req = dist.as_requirement() + return (req, False, []) + + vc_type = vcs.get_backend_type(location) + + if not vc_type: req = dist.as_requirement() return (req, False, []) try: - req = get_src_requirement(dist, location) + req = get_src_requirement(vc_type, dist, location) except InstallationError as exc: logger.warning( "Error when trying to get requirement for VCS system %s, " diff --git a/src/pip/_internal/vcs/__init__.py b/src/pip/_internal/vcs/__init__.py index 794b35d65..d34c8be0b 100644 --- a/src/pip/_internal/vcs/__init__.py +++ b/src/pip/_internal/vcs/__init__.py @@ -133,16 +133,16 @@ class VcsSupport(object): else: logger.warning('Cannot unregister because no class or name given') - def get_backend_name(self, location): + def get_backend_type(self, location): """ - Return the name of the version control backend if found at given - location, e.g. vcs.get_backend_name('/path/to/vcs/checkout') + Return the type of the version control backend if found at given + location, e.g. vcs.get_backend_type('/path/to/vcs/checkout') """ for vc_type in self._registry.values(): if vc_type.controls_location(location): logger.debug('Determine that %s uses VCS: %s', location, vc_type.name) - return vc_type.name + return vc_type return None def get_backend(self, name): @@ -150,12 +150,6 @@ class VcsSupport(object): if name in self._registry: return self._registry[name] - def get_backend_from_location(self, location): - vc_type = self.get_backend_name(location) - if vc_type: - return self.get_backend(vc_type) - return None - vcs = VcsSupport() @@ -487,23 +481,14 @@ class VersionControl(object): return cls.is_repository_directory(location) -def get_src_requirement(dist, location): - version_control = vcs.get_backend_from_location(location) - if version_control: - try: - return version_control().get_src_requirement(dist, - location) - except BadCommand: - logger.warning( - 'cannot determine version of editable source in %s ' - '(%s command not found in path)', - location, - version_control.name, - ) - return dist.as_requirement() - logger.warning( - 'cannot determine version of editable source in %s (is not SVN ' - 'checkout, Git clone, Mercurial clone or Bazaar branch)', - location, - ) - return dist.as_requirement() +def get_src_requirement(vc_type, dist, location): + try: + return vc_type().get_src_requirement(dist, location) + except BadCommand: + logger.warning( + 'cannot determine version of editable source in %s ' + '(%s command not found in path)', + location, + vc_type.name, + ) + return dist.as_requirement() |