Skip to content

Commit

Permalink
Merge pull request #7281 from sbidoul/ref-get_used_vcs_backend-sbi
Browse files Browse the repository at this point in the history
Refactor _get_used_vcs_backend
  • Loading branch information
chrahunt authored Nov 2, 2019
2 parents 2a2794e + 18a5881 commit 448303a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
1 change: 1 addition & 0 deletions news/7281.trivial
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
refactor _get_used_vcs_backend
14 changes: 1 addition & 13 deletions src/pip/_internal/operations/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
from pip._internal.req.req_install import InstallRequirement
from pip._internal.req.req_tracker import RequirementTracker
from pip._internal.utils.hashes import Hashes
from pip._internal.vcs.versioncontrol import VersionControl

if PY2:
CopytreeKwargs = TypedDict(
Expand Down Expand Up @@ -103,22 +102,11 @@ def _get_prepared_distribution(req, req_tracker, finder, build_isolation):

def unpack_vcs_link(link, location):
# type: (Link, str) -> None
vcs_backend = _get_used_vcs_backend(link)
vcs_backend = vcs.get_backend_for_scheme(link.scheme)
assert vcs_backend is not None
vcs_backend.unpack(location, url=hide_url(link.url))


def _get_used_vcs_backend(link):
# type: (Link) -> Optional[VersionControl]
"""
Return a VersionControl object or None.
"""
for vcs_backend in vcs.backends:
if link.scheme in vcs_backend.schemes:
return vcs_backend
return None


def _progress_indicator(iterable, *args, **kwargs):
return iterable

Expand Down
10 changes: 10 additions & 0 deletions src/pip/_internal/vcs/versioncontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,16 @@ def get_backend_for_dir(self, location):
return vcs_backend
return None

def get_backend_for_scheme(self, scheme):
# type: (str) -> Optional[VersionControl]
"""
Return a VersionControl object or None.
"""
for vcs_backend in self._registry.values():
if scheme in vcs_backend.schemes:
return vcs_backend
return None

def get_backend(self, name):
# type: (str) -> Optional[VersionControl]
"""
Expand Down
5 changes: 5 additions & 0 deletions tests/functional/test_vcs_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@

import pytest

from pip._internal.vcs import vcs
from pip._internal.vcs.git import Git, RemoteNotFoundError
from tests.lib import _create_test_package, _git_commit, _test_path_to_file_url


def test_get_backend_for_scheme():
assert vcs.get_backend_for_scheme("git+https") is vcs.get_backend("Git")


def get_head_sha(script, dest):
"""Return the HEAD sha."""
result = script.run('git', 'rev-parse', 'HEAD', cwd=dest)
Expand Down

0 comments on commit 448303a

Please sign in to comment.