1
1
Fork 0
mirror of https://github.com/pypa/pip synced 2023-12-13 21:30:23 +01:00
pip/tests/functional/test_install_vcs_git.py
Matt Robenolt 4c3ab41e90 Only update VCS when things have actually changed
This saves a network hop when using git and passing an explicit sha
as a ref by comparing the version that's already checked out.

Yields a ~4x speedup on my local machine

Before:
```
$ /usr/local/bin/pip --version
pip 7.1.0 from /usr/local/lib/python2.7/site-packages (python 2.7)
$ time /usr/local/bin/pip install --disable-pip-version-check -e git+https://github.com/getsentry/raven-python.git@56fc6f7beecf445843d0ec7052bb8c6f0ea80a2e#egg=raven_dev
Obtaining raven-dev from git+https://github.com/getsentry/raven-python.git@56fc6f7beecf445843d0ec7052bb8c6f0ea80a2e#egg=raven_dev
  Updating ./src/raven-dev clone (to 56fc6f7beecf445843d0ec7052bb8c6f0ea80a2e)
  Could not find a tag or branch '56fc6f7beecf445843d0ec7052bb8c6f0ea80a2e', assuming commit.
Installing collected packages: raven-dev
  Running setup.py develop for raven-dev
Successfully installed raven-dev
/usr/local/bin/pip install --disable-pip-version-check -e   0.84s user 0.48s system 39% cpu 3.300 total
```

After:
```
$ /Users/matt/.virtualenvs/pip/bin/pip --version
pip 7.2.0.dev0 from /Users/matt/code/pip (python 2.7)
$ time /Users/matt/.virtualenvs/pip/bin/pip install --disable-pip-version-check -e git+https://github.com/getsentry/raven-python.git@56fc6f7beecf445843d0ec7052bb8c6f0ea80a2e#egg=raven_dev
Obtaining raven-dev from git+https://github.com/getsentry/raven-python.git@56fc6f7beecf445843d0ec7052bb8c6f0ea80a2e#egg=raven_dev
checking version
  Skipping because already up-to-date.
Installing collected packages: raven-dev
  Running setup.py develop for raven-dev
Successfully installed raven-dev
/Users/matt/.virtualenvs/pip/bin/pip install --disable-pip-version-check -e   0.59s user 0.22s system 98% cpu 0.824 total
```
2015-09-01 13:23:18 -07:00

135 lines
4.3 KiB
Python

import pytest
from mock import patch
from pip.vcs.git import Git
from tests.lib import _create_test_package
from tests.lib.git_submodule_helpers import (
_change_test_package_submodule,
_pull_in_submodule_changes_to_module,
_create_test_package_with_submodule,
)
@pytest.mark.network
def test_get_short_refs_should_return_tag_name_and_commit_pair(script):
version_pkg_path = _create_test_package(script)
script.run('git', 'tag', '0.1', cwd=version_pkg_path)
script.run('git', 'tag', '0.2', cwd=version_pkg_path)
commit = script.run(
'git', 'rev-parse', 'HEAD',
cwd=version_pkg_path
).stdout.strip()
git = Git()
result = git.get_short_refs(version_pkg_path)
assert result['0.1'] == commit, result
assert result['0.2'] == commit, result
@pytest.mark.network
def test_get_short_refs_should_return_branch_name_and_commit_pair(script):
version_pkg_path = _create_test_package(script)
script.run('git', 'branch', 'branch0.1', cwd=version_pkg_path)
commit = script.run(
'git', 'rev-parse', 'HEAD',
cwd=version_pkg_path
).stdout.strip()
git = Git()
result = git.get_short_refs(version_pkg_path)
assert result['master'] == commit, result
assert result['branch0.1'] == commit, result
@pytest.mark.network
def test_get_short_refs_should_ignore_no_branch(script):
version_pkg_path = _create_test_package(script)
script.run('git', 'branch', 'branch0.1', cwd=version_pkg_path)
commit = script.run(
'git', 'rev-parse', 'HEAD',
cwd=version_pkg_path
).stdout.strip()
# current branch here is "* (nobranch)"
script.run(
'git', 'checkout', commit,
cwd=version_pkg_path,
expect_stderr=True,
)
git = Git()
result = git.get_short_refs(version_pkg_path)
assert result['master'] == commit, result
assert result['branch0.1'] == commit, result
@pytest.mark.network
def test_check_version(script):
version_pkg_path = _create_test_package(script)
script.run('git', 'branch', 'branch0.1', cwd=version_pkg_path)
commit = script.run(
'git', 'rev-parse', 'HEAD',
cwd=version_pkg_path
).stdout.strip()
git = Git()
assert git.check_version(version_pkg_path, [commit])
assert git.check_version(version_pkg_path, [commit[:7]])
assert not git.check_version(version_pkg_path, ['branch0.1'])
assert not git.check_version(version_pkg_path, ['abc123'])
@patch('pip.vcs.git.Git.get_short_refs')
def test_check_rev_options_should_handle_branch_name(get_refs_mock):
get_refs_mock.return_value = {'master': '123456', '0.1': '123456'}
git = Git()
result = git.check_rev_options('master', '.', [])
assert result == ['123456']
@patch('pip.vcs.git.Git.get_short_refs')
def test_check_rev_options_should_handle_tag_name(get_refs_mock):
get_refs_mock.return_value = {'master': '123456', '0.1': '123456'}
git = Git()
result = git.check_rev_options('0.1', '.', [])
assert result == ['123456']
@patch('pip.vcs.git.Git.get_short_refs')
def test_check_rev_options_should_handle_ambiguous_commit(get_refs_mock):
get_refs_mock.return_value = {'master': '123456', '0.1': '123456'}
git = Git()
result = git.check_rev_options('0.1', '.', [])
assert result == ['123456'], result
# TODO(pnasrat) fix all helpers to do right things with paths on windows.
@pytest.mark.skipif("sys.platform == 'win32'")
@pytest.mark.network
def test_check_submodule_addition(script):
"""
Submodules are pulled in on install and updated on upgrade.
"""
module_path, submodule_path = _create_test_package_with_submodule(script)
install_result = script.pip(
'install', '-e', 'git+' + module_path + '#egg=version_pkg'
)
assert (
script.venv / 'src/version-pkg/testpkg/static/testfile'
in install_result.files_created
)
_change_test_package_submodule(script, submodule_path)
_pull_in_submodule_changes_to_module(script, module_path)
# expect error because git may write to stderr
update_result = script.pip(
'install', '-e', 'git+' + module_path + '#egg=version_pkg',
'--upgrade',
expect_error=True,
)
assert (
script.venv / 'src/version-pkg/testpkg/static/testfile2'
in update_result.files_created
)