Skip to content

Commit

Permalink
Merge pull request #5873 from cjerdonek/remove-get-backend-from-location
Browse files Browse the repository at this point in the history
Simplify vcs.get_src_requirement().
  • Loading branch information
cjerdonek authored Oct 13, 2018
2 parents 8dbbe16 + 00a2ff1 commit 1228f64
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 32 deletions.
Empty file.
10 changes: 8 additions & 2 deletions src/pip/_internal/operations/freeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,18 @@ def _init_args_from_dist(cls, dist, dependency_links):
"""
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, "
Expand Down
45 changes: 15 additions & 30 deletions src/pip/_internal/vcs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,29 +133,23 @@ def unregister(self, cls=None, name=None):
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):
name = name.lower()
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()

Expand Down Expand Up @@ -487,23 +481,14 @@ def controls_location(cls, location):
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()

0 comments on commit 1228f64

Please sign in to comment.