Skip to content

Refactor _get_used_vcs_backend #7281

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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