mirror of
https://github.com/pypa/pip
synced 2023-12-13 21:30:23 +01:00
Make VersionControl.get_url_rev_and_auth() a class method.
This commit is contained in:
parent
67b384b8c7
commit
3ba489864b
5 changed files with 19 additions and 18 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue