Make is_repository_directory() a class method.

This addresses a review suggestion of @xavfernandez.
This commit is contained in:
Chris Jerdonek 2018-07-17 20:53:42 -07:00
parent f62440950b
commit c6a18767dd
1 changed files with 13 additions and 10 deletions

View File

@ -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):