From 22acd1fed1f126bdccfa0a11acc0b5aaeb9874f6 Mon Sep 17 00:00:00 2001 From: Chris Jerdonek Date: Mon, 16 Jul 2018 20:12:44 -0700 Subject: [PATCH 1/3] Break out VersionControl.is_repository_directory(). --- news/67C1ECA3-A0C6-4DA6-B987-BE46C7629AF2.trivial | 0 src/pip/_internal/vcs/__init__.py | 8 +++++++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 news/67C1ECA3-A0C6-4DA6-B987-BE46C7629AF2.trivial diff --git a/news/67C1ECA3-A0C6-4DA6-B987-BE46C7629AF2.trivial b/news/67C1ECA3-A0C6-4DA6-B987-BE46C7629AF2.trivial new file mode 100644 index 000000000..e69de29bb diff --git a/src/pip/_internal/vcs/__init__.py b/src/pip/_internal/vcs/__init__.py index 704f1c3fa..4a392b891 100644 --- a/src/pip/_internal/vcs/__init__.py +++ b/src/pip/_internal/vcs/__init__.py @@ -200,6 +200,12 @@ class VersionControl(object): drive, tail = os.path.splitdrive(repo) return repo.startswith(os.path.sep) or drive + def is_repository_directory(self, path): + """ + Return whether a directory path is a repository directory. + """ + return os.path.exists(os.path.join(path, self.dirname)) + # See issue #1083 for why this method was introduced: # https://github.com/pypa/pip/issues/1083 def translate_egg_surname(self, surname): @@ -325,7 +331,7 @@ class VersionControl(object): return rev_display = rev_options.to_display() - if os.path.exists(os.path.join(dest, self.dirname)): + if self.is_repository_directory(dest): existing_url = self.get_url(dest) if self.compare_urls(existing_url, url): logger.debug( From f62440950be90c862a96027db94ef0e60a303013 Mon Sep 17 00:00:00 2001 From: Chris Jerdonek Date: Tue, 17 Jul 2018 13:05:26 -0700 Subject: [PATCH 2/3] Use is_repository_directory() inside VersionControl.controls_location(). --- src/pip/_internal/vcs/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pip/_internal/vcs/__init__.py b/src/pip/_internal/vcs/__init__.py index 4a392b891..66a3c93cb 100644 --- a/src/pip/_internal/vcs/__init__.py +++ b/src/pip/_internal/vcs/__init__.py @@ -204,6 +204,8 @@ class VersionControl(object): """ Return whether a directory path is a repository directory. """ + logger.debug('Checking in %s for %s (%s)...', + path, self.dirname, self.name) return os.path.exists(os.path.join(path, self.dirname)) # See issue #1083 for why this method was introduced: @@ -472,10 +474,8 @@ class VersionControl(object): It is meant to be overridden to implement smarter detection mechanisms for specific vcs. """ - logger.debug('Checking in %s for %s (%s)...', - location, cls.dirname, cls.name) - path = os.path.join(location, cls.dirname) - return os.path.exists(path) + vcs = cls() + return vcs.is_repository_directory(location) def get_src_requirement(dist, location): From c6a18767dd2b0cabe2ef0176ce96b637cdbb8f36 Mon Sep 17 00:00:00 2001 From: Chris Jerdonek Date: Tue, 17 Jul 2018 20:53:42 -0700 Subject: [PATCH 3/3] Make is_repository_directory() a class method. This addresses a review suggestion of @xavfernandez. --- src/pip/_internal/vcs/__init__.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/pip/_internal/vcs/__init__.py b/src/pip/_internal/vcs/__init__.py index 66a3c93cb..e8b4deb1d 100644 --- a/src/pip/_internal/vcs/__init__.py +++ b/src/pip/_internal/vcs/__init__.py @@ -200,14 +200,6 @@ class VersionControl(object): drive, tail = os.path.splitdrive(repo) return repo.startswith(os.path.sep) or drive - def is_repository_directory(self, path): - """ - Return whether a directory path is a repository directory. - """ - logger.debug('Checking in %s for %s (%s)...', - path, self.dirname, self.name) - return os.path.exists(os.path.join(path, self.dirname)) - # See issue #1083 for why this method was introduced: # https://github.com/pypa/pip/issues/1083 def translate_egg_surname(self, surname): @@ -467,15 +459,26 @@ class VersionControl(object): else: raise # re-raise exception if a different error occurred + @classmethod + def is_repository_directory(cls, path): + """ + Return whether a directory path is a repository directory. + """ + logger.debug('Checking in %s for %s (%s)...', + path, cls.dirname, cls.name) + return os.path.exists(os.path.join(path, cls.dirname)) + @classmethod def controls_location(cls, location): """ Check if a location is controlled by the vcs. It is meant to be overridden to implement smarter detection mechanisms for specific vcs. + + This can do more than is_repository_directory() alone. For example, + the Git override checks that Git is actually available. """ - vcs = cls() - return vcs.is_repository_directory(location) + return cls.is_repository_directory(location) def get_src_requirement(dist, location):