From 3ba489864b8f541b29dbc750f897a9e4a2cb4b92 Mon Sep 17 00:00:00 2001 From: Chris Jerdonek Date: Sat, 16 Mar 2019 01:13:25 -0700 Subject: [PATCH] Make VersionControl.get_url_rev_and_auth() a class method. --- src/pip/_internal/vcs/__init__.py | 5 +++-- src/pip/_internal/vcs/bazaar.py | 5 +++-- src/pip/_internal/vcs/git.py | 7 ++++--- src/pip/_internal/vcs/subversion.py | 5 +++-- tests/unit/test_vcs.py | 15 ++++++--------- 5 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/pip/_internal/vcs/__init__.py b/src/pip/_internal/vcs/__init__.py index 827f20f08..88df8cd43 100644 --- a/src/pip/_internal/vcs/__init__.py +++ b/src/pip/_internal/vcs/__init__.py @@ -312,7 +312,8 @@ class VersionControl(object): """ return netloc, (None, None) - def get_url_rev_and_auth(self, url): + @classmethod + def get_url_rev_and_auth(cls, url): # type: (str) -> Tuple[str, Optional[str], AuthInfo] """ Parse the repository URL to use, and return the URL, revision, @@ -329,7 +330,7 @@ class VersionControl(object): ) # Remove the vcs prefix. scheme = scheme.split('+', 1)[1] - netloc, user_pass = self.get_netloc_and_auth(netloc, scheme) + netloc, user_pass = cls.get_netloc_and_auth(netloc, scheme) rev = None if '@' in path: path, rev = path.rsplit('@', 1) diff --git a/src/pip/_internal/vcs/bazaar.py b/src/pip/_internal/vcs/bazaar.py index ab22d01a3..d0a92eaaf 100644 --- a/src/pip/_internal/vcs/bazaar.py +++ b/src/pip/_internal/vcs/bazaar.py @@ -63,9 +63,10 @@ class Bazaar(VersionControl): cmd_args = ['pull', '-q'] + rev_options.to_args() self.run_command(cmd_args, cwd=dest) - def get_url_rev_and_auth(self, url): + @classmethod + def get_url_rev_and_auth(cls, url): # hotfix the URL scheme after removing bzr+ from bzr+ssh:// readd it - url, rev, user_pass = super(Bazaar, self).get_url_rev_and_auth(url) + url, rev, user_pass = super(Bazaar, cls).get_url_rev_and_auth(url) if url.startswith('ssh://'): url = 'bzr+' + url return url, rev, user_pass diff --git a/src/pip/_internal/vcs/git.py b/src/pip/_internal/vcs/git.py index edd159b71..dff215c49 100644 --- a/src/pip/_internal/vcs/git.py +++ b/src/pip/_internal/vcs/git.py @@ -310,7 +310,8 @@ class Git(VersionControl): return None return os.path.relpath(location, root_dir) - def get_url_rev_and_auth(self, url): + @classmethod + def get_url_rev_and_auth(cls, url): """ Prefixes stub URLs like 'user@hostname:user/repo.git' with 'ssh://'. That's required because although they use SSH they sometimes don't @@ -320,10 +321,10 @@ class Git(VersionControl): if '://' not in url: assert 'file:' not in url url = url.replace('git+', 'git+ssh://') - url, rev, user_pass = super(Git, self).get_url_rev_and_auth(url) + url, rev, user_pass = super(Git, cls).get_url_rev_and_auth(url) url = url.replace('ssh://', '') else: - url, rev, user_pass = super(Git, self).get_url_rev_and_auth(url) + url, rev, user_pass = super(Git, cls).get_url_rev_and_auth(url) return url, rev, user_pass diff --git a/src/pip/_internal/vcs/subversion.py b/src/pip/_internal/vcs/subversion.py index 261f6a827..8a9a61ccf 100644 --- a/src/pip/_internal/vcs/subversion.py +++ b/src/pip/_internal/vcs/subversion.py @@ -105,9 +105,10 @@ class Subversion(VersionControl): return split_auth_from_netloc(netloc) - def get_url_rev_and_auth(self, url): + @classmethod + def get_url_rev_and_auth(cls, url): # hotfix the URL scheme after removing svn+ from svn+ssh:// readd it - url, rev, user_pass = super(Subversion, self).get_url_rev_and_auth(url) + url, rev, user_pass = super(Subversion, cls).get_url_rev_and_auth(url) if url.startswith('ssh://'): url = 'svn+' + url return url, rev, user_pass diff --git a/tests/unit/test_vcs.py b/tests/unit/test_vcs.py index 05b8b0c41..adee2fb45 100644 --- a/tests/unit/test_vcs.py +++ b/tests/unit/test_vcs.py @@ -241,10 +241,8 @@ def test_git__get_url_rev__idempotent(): Also check that it doesn't change self.url. """ url = 'git+git@git.example.com:MyProject#egg=MyProject' - vcs = Git(url) - result1 = vcs.get_url_rev_and_auth(url) - assert vcs.url == url - result2 = vcs.get_url_rev_and_auth(url) + result1 = Git.get_url_rev_and_auth(url) + result2 = Git.get_url_rev_and_auth(url) expected = ('git@git.example.com:MyProject', None, (None, None)) assert result1 == expected assert result2 == expected @@ -261,7 +259,7 @@ def test_version_control__get_url_rev_and_auth(url, expected): """ Test the basic case of VersionControl.get_url_rev_and_auth(). """ - actual = VersionControl().get_url_rev_and_auth(url) + actual = VersionControl.get_url_rev_and_auth(url) assert actual == expected @@ -276,7 +274,7 @@ def test_version_control__get_url_rev_and_auth__missing_plus(url): missing from the scheme. """ with pytest.raises(ValueError) as excinfo: - VersionControl().get_url_rev_and_auth(url) + VersionControl.get_url_rev_and_auth(url) assert 'malformed VCS url' in str(excinfo.value) @@ -305,8 +303,7 @@ def test_bazaar__get_url_rev_and_auth(url, expected): """ Test Bazaar.get_url_rev_and_auth(). """ - bzr = Bazaar(url=url) - actual = bzr.get_url_rev_and_auth(url) + actual = Bazaar.get_url_rev_and_auth(url) assert actual == (expected, None, (None, None)) @@ -328,7 +325,7 @@ def test_subversion__get_url_rev_and_auth(url, expected): """ Test Subversion.get_url_rev_and_auth(). """ - actual = Subversion().get_url_rev_and_auth(url) + actual = Subversion.get_url_rev_and_auth(url) assert actual == expected