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) drive, tail = os.path.splitdrive(repo)
return repo.startswith(os.path.sep) or drive 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: # See issue #1083 for why this method was introduced:
# https://github.com/pypa/pip/issues/1083 # https://github.com/pypa/pip/issues/1083
def translate_egg_surname(self, surname): def translate_egg_surname(self, surname):
@ -467,15 +459,26 @@ class VersionControl(object):
else: else:
raise # re-raise exception if a different error occurred 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 @classmethod
def controls_location(cls, location): def controls_location(cls, location):
""" """
Check if a location is controlled by the vcs. Check if a location is controlled by the vcs.
It is meant to be overridden to implement smarter detection It is meant to be overridden to implement smarter detection
mechanisms for specific vcs. 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 cls.is_repository_directory(location)
return vcs.is_repository_directory(location)
def get_src_requirement(dist, location): def get_src_requirement(dist, location):