Skip to content

Commit

Permalink
Merge pull request #6001 from cjerdonek/rename-and-test-vcs-get-url
Browse files Browse the repository at this point in the history
Test and rename Git.get_url()
  • Loading branch information
cjerdonek committed Nov 10, 2018
2 parents 8a4e285 + 2dbd347 commit 313d571
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/pip/_internal/vcs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ def obtain(self, dest):

rev_display = rev_options.to_display()
if self.is_repository_directory(dest):
existing_url = self.get_url(dest)
existing_url = self.get_remote_url(dest)
if self.compare_urls(existing_url, url):
logger.debug(
'%s in %s exists, and has correct URL (%s)',
Expand Down Expand Up @@ -419,7 +419,7 @@ def get_src_requirement(self, location, project_name):
"""
raise NotImplementedError

def get_url(self, location):
def get_remote_url(self, location):
"""
Return the url used at location
"""
Expand Down
4 changes: 2 additions & 2 deletions src/pip/_internal/vcs/bazaar.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def get_url_rev_and_auth(self, url):
url = 'bzr+' + url
return url, rev, user_pass

def get_url(self, location):
def get_remote_url(self, location):
urls = self.run_command(['info'], show_stdout=False, cwd=location)
for line in urls.splitlines():
line = line.strip()
Expand All @@ -95,7 +95,7 @@ def get_revision(self, location):
return revision.splitlines()[-1]

def get_src_requirement(self, location, project_name):
repo = self.get_url(location)
repo = self.get_remote_url(location)
if not repo:
return None
if not repo.lower().startswith('bzr:'):
Expand Down
4 changes: 2 additions & 2 deletions src/pip/_internal/vcs/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def update(self, dest, url, rev_options):
#: update submodules
self.update_submodules(dest)

def get_url(self, location):
def get_remote_url(self, location):
"""Return URL of the first remote encountered."""
remotes = self.run_command(
['config', '--get-regexp', r'remote\..*\.url'],
Expand Down Expand Up @@ -294,7 +294,7 @@ def _get_subdirectory(self, location):
return os.path.relpath(location, root_dir)

def get_src_requirement(self, location, project_name):
repo = self.get_url(location)
repo = self.get_remote_url(location)
if not repo.lower().startswith('git:'):
repo = 'git+' + repo
current_rev = self.get_revision(location)
Expand Down
4 changes: 2 additions & 2 deletions src/pip/_internal/vcs/mercurial.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def update(self, dest, url, rev_options):
cmd_args = ['update', '-q'] + rev_options.to_args()
self.run_command(cmd_args, cwd=dest)

def get_url(self, location):
def get_remote_url(self, location):
url = self.run_command(
['showconfig', 'paths.default'],
show_stdout=False, cwd=location).strip()
Expand All @@ -85,7 +85,7 @@ def get_revision_hash(self, location):
return current_rev_hash

def get_src_requirement(self, location, project_name):
repo = self.get_url(location)
repo = self.get_remote_url(location)
if not repo.lower().startswith('hg:'):
repo = 'hg+' + repo
current_rev_hash = self.get_revision_hash(location)
Expand Down
4 changes: 2 additions & 2 deletions src/pip/_internal/vcs/subversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def make_rev_args(self, username, password):

return extra_args

def get_url(self, location):
def get_remote_url(self, location):
# In cases where the source is in a subdirectory, not alongside
# setup.py we have to look up in the location until we find a real
# setup.py
Expand Down Expand Up @@ -196,7 +196,7 @@ def _get_svn_url_rev(self, location):
return url, rev

def get_src_requirement(self, location, project_name):
repo = self.get_url(location)
repo = self.get_remote_url(location)
if repo is None:
return None
repo = 'svn+' + repo
Expand Down
7 changes: 4 additions & 3 deletions tests/functional/test_install_vcs_git.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import pytest

from tests.lib import (
_change_test_package_version, _create_test_package, pyversion,
_change_test_package_version, _create_test_package, _test_path_to_file_url,
pyversion,
)
from tests.lib.git_submodule_helpers import (
_change_test_package_submodule, _create_test_package_with_submodule,
Expand Down Expand Up @@ -70,9 +71,9 @@ def _make_version_pkg_url(path, rev=None):
containing the version_pkg package.
rev: an optional revision to install like a branch name, tag, or SHA.
"""
path = path.abspath.replace('\\', '/')
file_url = _test_path_to_file_url(path)
url_rev = '' if rev is None else '@{}'.format(rev)
url = 'git+file://{}{}#egg=version_pkg'.format(path, url_rev)
url = 'git+{}{}#egg=version_pkg'.format(file_url, url_rev)

return url

Expand Down
18 changes: 17 additions & 1 deletion tests/functional/test_vcs_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from pip._internal.utils.temp_dir import TempDirectory
from pip._internal.vcs.git import Git
from tests.lib import _create_test_package
from tests.lib import _create_test_package, _test_path_to_file_url


def get_head_sha(script, dest):
Expand Down Expand Up @@ -70,6 +70,22 @@ def test_git_work_tree_ignored():
git.run_command(['status', temp_dir], extra_environ=env, cwd=temp_dir)


def test_get_remote_url(script, tmpdir):
source_dir = tmpdir / 'source'
source_dir.mkdir()
source_url = _test_path_to_file_url(source_dir)

source_dir = str(source_dir)
script.run('git', 'init', cwd=source_dir)
do_commit(script, source_dir)

repo_dir = str(tmpdir / 'repo')
script.run('git', 'clone', source_url, repo_dir, expect_stderr=True)

remote_url = Git().get_remote_url(repo_dir)
assert remote_url == source_url


def test_get_branch(script, tmpdir):
repo_dir = str(tmpdir)
script.run('git', 'init', cwd=repo_dir)
Expand Down
10 changes: 10 additions & 0 deletions tests/lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ def path_to_url(path):
return 'file://' + url


def _test_path_to_file_url(path):
"""
Convert a test Path to a "file://" URL.
Args:
path: a tests.lib.path.Path object.
"""
return 'file://' + path.abspath.replace('\\', '/')


def create_file(path, contents=None):
"""Create a file on the path, with the given contents
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_vcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def git():
git_url = 'https://github.com/pypa/pip-test-package'
sha = '5547fa909e83df8bd743d3978d6667497983a4b7'
git = Git()
git.get_url = Mock(return_value=git_url)
git.get_remote_url = Mock(return_value=git_url)
git.get_revision = Mock(return_value=sha)
return git

Expand Down

0 comments on commit 313d571

Please sign in to comment.