2021-09-13 00:31:12 +02:00
|
|
|
from typing import Optional
|
|
|
|
|
2015-01-15 00:53:15 +01:00
|
|
|
import pytest
|
2017-06-13 14:17:00 +02:00
|
|
|
|
2021-01-09 15:50:51 +01:00
|
|
|
from pip._internal.utils.urls import path_to_url
|
2020-03-06 18:30:16 +01:00
|
|
|
from tests.lib import pyversion # noqa: F401
|
2017-05-16 12:16:30 +02:00
|
|
|
from tests.lib import (
|
2021-09-13 00:31:12 +02:00
|
|
|
PipTestEnvironment,
|
2019-07-22 06:45:27 +02:00
|
|
|
_change_test_package_version,
|
|
|
|
_create_test_package,
|
|
|
|
_test_path_to_file_url,
|
2017-05-16 12:16:30 +02:00
|
|
|
)
|
2018-07-27 18:11:42 +02:00
|
|
|
from tests.lib.git_submodule_helpers import (
|
2019-07-22 06:45:27 +02:00
|
|
|
_change_test_package_submodule,
|
|
|
|
_create_test_package_with_submodule,
|
2018-07-27 18:11:42 +02:00
|
|
|
_pull_in_submodule_changes_to_module,
|
|
|
|
)
|
2013-05-27 19:46:31 +02:00
|
|
|
from tests.lib.local_repos import local_checkout
|
2021-09-13 00:31:12 +02:00
|
|
|
from tests.lib.path import Path
|
2010-11-21 19:31:15 +01:00
|
|
|
|
2011-05-04 09:44:02 +02:00
|
|
|
|
2021-09-13 00:31:12 +02:00
|
|
|
def _get_editable_repo_dir(script: PipTestEnvironment, package_name: str) -> Path:
|
2018-08-21 10:51:06 +02:00
|
|
|
"""
|
|
|
|
Return the repository directory for an editable install.
|
|
|
|
"""
|
2021-08-13 15:23:45 +02:00
|
|
|
return script.venv_path / "src" / package_name
|
2018-08-21 10:51:06 +02:00
|
|
|
|
|
|
|
|
2021-09-13 00:31:12 +02:00
|
|
|
def _get_editable_branch(script: PipTestEnvironment, package_name: str) -> str:
|
2018-08-19 22:03:02 +02:00
|
|
|
"""
|
|
|
|
Return the current branch of an editable install.
|
|
|
|
"""
|
2018-08-21 10:51:06 +02:00
|
|
|
repo_dir = _get_editable_repo_dir(script, package_name)
|
2021-08-13 15:23:45 +02:00
|
|
|
result = script.run("git", "rev-parse", "--abbrev-ref", "HEAD", cwd=repo_dir)
|
2018-08-21 10:51:06 +02:00
|
|
|
return result.stdout.strip()
|
|
|
|
|
2018-08-19 22:03:02 +02:00
|
|
|
|
2021-09-13 00:31:12 +02:00
|
|
|
def _get_branch_remote(
|
|
|
|
script: PipTestEnvironment, package_name: str, branch: str
|
|
|
|
) -> str:
|
2021-08-13 15:23:45 +02:00
|
|
|
""" """
|
2018-08-21 10:51:06 +02:00
|
|
|
repo_dir = _get_editable_repo_dir(script, package_name)
|
2021-08-13 15:23:45 +02:00
|
|
|
result = script.run("git", "config", f"branch.{branch}.remote", cwd=repo_dir)
|
2018-08-19 22:03:02 +02:00
|
|
|
return result.stdout.strip()
|
|
|
|
|
|
|
|
|
2021-09-13 00:31:12 +02:00
|
|
|
def _github_checkout(
|
|
|
|
url_path: str,
|
|
|
|
temp_dir: Path,
|
|
|
|
rev: Optional[str] = None,
|
|
|
|
egg: Optional[str] = None,
|
|
|
|
scheme: Optional[str] = None,
|
|
|
|
) -> str:
|
2018-08-19 08:02:38 +02:00
|
|
|
"""
|
2018-08-19 09:30:33 +02:00
|
|
|
Call local_checkout() with a GitHub URL, and return the resulting URL.
|
2018-08-19 08:02:38 +02:00
|
|
|
|
|
|
|
Args:
|
2018-08-19 09:43:38 +02:00
|
|
|
url_path: the string used to create the package URL by filling in the
|
|
|
|
format string "git+{scheme}://github.com/{url_path}".
|
2018-08-19 08:02:38 +02:00
|
|
|
temp_dir: the pytest tmpdir value.
|
|
|
|
egg: an optional project name to append to the URL as the egg fragment,
|
|
|
|
prior to returning.
|
2018-08-19 09:43:38 +02:00
|
|
|
scheme: the scheme without the "git+" prefix. Defaults to "https".
|
2018-08-19 08:02:38 +02:00
|
|
|
"""
|
2018-08-19 09:43:38 +02:00
|
|
|
if scheme is None:
|
2021-08-13 15:23:45 +02:00
|
|
|
scheme = "https"
|
|
|
|
url = f"git+{scheme}://github.com/{url_path}"
|
2019-09-13 18:18:07 +02:00
|
|
|
local_url = local_checkout(url, temp_dir)
|
2019-04-04 10:33:39 +02:00
|
|
|
if rev is not None:
|
2021-08-13 15:23:45 +02:00
|
|
|
local_url += f"@{rev}"
|
2018-08-19 08:02:38 +02:00
|
|
|
if egg is not None:
|
2021-08-13 15:23:45 +02:00
|
|
|
local_url += f"#egg={egg}"
|
2018-08-19 08:02:38 +02:00
|
|
|
|
2018-08-19 09:30:33 +02:00
|
|
|
return local_url
|
2018-08-19 08:02:38 +02:00
|
|
|
|
|
|
|
|
2021-09-13 00:31:12 +02:00
|
|
|
def _make_version_pkg_url(
|
|
|
|
path: Path, rev: Optional[str] = None, name: str = "version_pkg"
|
|
|
|
) -> str:
|
2018-08-19 05:53:15 +02:00
|
|
|
"""
|
|
|
|
Return a "git+file://" URL to the version_pkg test package.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
path: a tests.lib.path.Path object pointing to a Git repository
|
|
|
|
containing the version_pkg package.
|
|
|
|
rev: an optional revision to install like a branch name, tag, or SHA.
|
|
|
|
"""
|
2018-11-10 08:37:21 +01:00
|
|
|
file_url = _test_path_to_file_url(path)
|
2021-08-13 15:23:45 +02:00
|
|
|
url_rev = "" if rev is None else f"@{rev}"
|
|
|
|
url = f"git+{file_url}{url_rev}#egg={name}"
|
2018-08-19 05:53:15 +02:00
|
|
|
|
|
|
|
return url
|
|
|
|
|
|
|
|
|
2021-09-13 00:31:12 +02:00
|
|
|
def _install_version_pkg_only(
|
|
|
|
script: PipTestEnvironment,
|
|
|
|
path: Path,
|
|
|
|
rev: Optional[str] = None,
|
|
|
|
expect_stderr: bool = False,
|
|
|
|
) -> None:
|
2017-08-24 01:50:18 +02:00
|
|
|
"""
|
2018-08-19 22:03:02 +02:00
|
|
|
Install the version_pkg package in editable mode (without returning
|
|
|
|
the version).
|
2017-08-24 01:50:18 +02:00
|
|
|
|
|
|
|
Args:
|
|
|
|
path: a tests.lib.path.Path object pointing to a Git repository
|
|
|
|
containing the package.
|
2017-09-01 00:30:41 +02:00
|
|
|
rev: an optional revision to install like a branch name or tag.
|
2017-08-24 01:50:18 +02:00
|
|
|
"""
|
2018-08-19 05:53:15 +02:00
|
|
|
version_pkg_url = _make_version_pkg_url(path, rev=rev)
|
2021-08-13 15:23:45 +02:00
|
|
|
script.pip("install", "-e", version_pkg_url, expect_stderr=expect_stderr)
|
2018-08-19 22:03:02 +02:00
|
|
|
|
|
|
|
|
2021-09-13 00:31:12 +02:00
|
|
|
def _install_version_pkg(
|
|
|
|
script: PipTestEnvironment,
|
|
|
|
path: Path,
|
|
|
|
rev: Optional[str] = None,
|
|
|
|
expect_stderr: bool = False,
|
|
|
|
) -> str:
|
2018-08-19 22:03:02 +02:00
|
|
|
"""
|
|
|
|
Install the version_pkg package in editable mode, and return the version
|
|
|
|
installed.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
path: a tests.lib.path.Path object pointing to a Git repository
|
|
|
|
containing the package.
|
|
|
|
rev: an optional revision to install like a branch name or tag.
|
|
|
|
"""
|
|
|
|
_install_version_pkg_only(
|
2021-08-13 15:23:45 +02:00
|
|
|
script,
|
|
|
|
path,
|
|
|
|
rev=rev,
|
|
|
|
expect_stderr=expect_stderr,
|
2018-08-19 22:03:02 +02:00
|
|
|
)
|
2021-08-13 15:23:45 +02:00
|
|
|
result = script.run("version_pkg")
|
2017-08-24 01:50:18 +02:00
|
|
|
version = result.stdout.strip()
|
|
|
|
|
|
|
|
return version
|
|
|
|
|
|
|
|
|
2021-09-13 00:31:12 +02:00
|
|
|
def test_git_install_again_after_changes(script: PipTestEnvironment) -> None:
|
2017-09-01 00:30:41 +02:00
|
|
|
"""
|
|
|
|
Test installing a repository a second time without specifying a revision,
|
|
|
|
and after updates to the remote repository.
|
|
|
|
|
|
|
|
This test also checks that no warning message like the following gets
|
|
|
|
logged on the update: "Did not find branch or tag ..., assuming ref or
|
|
|
|
revision."
|
|
|
|
"""
|
|
|
|
version_pkg_path = _create_test_package(script)
|
|
|
|
version = _install_version_pkg(script, version_pkg_path)
|
2021-08-13 15:23:45 +02:00
|
|
|
assert version == "0.1"
|
2017-09-01 00:30:41 +02:00
|
|
|
|
|
|
|
_change_test_package_version(script, version_pkg_path)
|
|
|
|
version = _install_version_pkg(script, version_pkg_path)
|
2021-08-13 15:23:45 +02:00
|
|
|
assert version == "some different version"
|
2017-09-01 00:30:41 +02:00
|
|
|
|
|
|
|
|
2021-09-13 00:31:12 +02:00
|
|
|
def test_git_install_branch_again_after_branch_changes(
|
|
|
|
script: PipTestEnvironment,
|
|
|
|
) -> None:
|
2017-08-24 01:50:18 +02:00
|
|
|
"""
|
|
|
|
Test installing a branch again after the branch is updated in the remote
|
|
|
|
repository.
|
|
|
|
"""
|
|
|
|
version_pkg_path = _create_test_package(script)
|
2021-08-13 15:23:45 +02:00
|
|
|
version = _install_version_pkg(script, version_pkg_path, rev="master")
|
|
|
|
assert version == "0.1"
|
2017-08-24 01:50:18 +02:00
|
|
|
|
|
|
|
_change_test_package_version(script, version_pkg_path)
|
2021-08-13 15:23:45 +02:00
|
|
|
version = _install_version_pkg(script, version_pkg_path, rev="master")
|
|
|
|
assert version == "some different version"
|
2017-08-24 01:50:18 +02:00
|
|
|
|
|
|
|
|
2015-01-15 00:53:15 +01:00
|
|
|
@pytest.mark.network
|
2021-09-13 00:31:12 +02:00
|
|
|
def test_install_editable_from_git_with_https(
|
|
|
|
script: PipTestEnvironment, tmpdir: Path
|
|
|
|
) -> None:
|
2010-11-05 21:24:17 +01:00
|
|
|
"""
|
|
|
|
Test cloning from Git with https.
|
|
|
|
"""
|
2021-08-13 15:23:45 +02:00
|
|
|
url_path = "pypa/pip-test-package.git"
|
|
|
|
local_url = _github_checkout(url_path, tmpdir, egg="pip-test-package")
|
|
|
|
result = script.pip("install", "-e", local_url)
|
|
|
|
result.assert_installed("pip-test-package", with_files=[".git"])
|
2010-11-05 21:24:17 +01:00
|
|
|
|
2010-08-05 16:09:40 +02:00
|
|
|
|
2015-01-15 00:53:15 +01:00
|
|
|
@pytest.mark.network
|
2021-09-21 06:44:29 +02:00
|
|
|
@pytest.mark.usefixtures("with_wheel")
|
2021-09-13 00:31:12 +02:00
|
|
|
def test_install_noneditable_git(script: PipTestEnvironment) -> None:
|
2014-08-04 06:01:47 +02:00
|
|
|
"""
|
|
|
|
Test installing from a non-editable git URL with a given tag.
|
|
|
|
"""
|
|
|
|
result = script.pip(
|
2021-08-13 15:23:45 +02:00
|
|
|
"install",
|
|
|
|
"git+https://github.com/pypa/pip-test-package.git"
|
|
|
|
"@0.1.1#egg=pip-test-package",
|
2014-08-04 06:33:28 +02:00
|
|
|
)
|
2021-08-13 15:23:45 +02:00
|
|
|
dist_info_folder = script.site_packages / "pip_test_package-0.1.1.dist-info"
|
|
|
|
result.assert_installed("piptestpackage", without_egg_link=True, editable=False)
|
2020-07-25 13:02:20 +02:00
|
|
|
result.did_create(dist_info_folder)
|
2014-08-04 06:01:47 +02:00
|
|
|
|
|
|
|
|
2021-09-13 00:31:12 +02:00
|
|
|
def test_git_with_sha1_revisions(script: PipTestEnvironment) -> None:
|
2010-08-05 16:09:40 +02:00
|
|
|
"""
|
|
|
|
Git backend should be able to install from SHA1 revisions
|
|
|
|
"""
|
2013-08-21 11:16:07 +02:00
|
|
|
version_pkg_path = _create_test_package(script)
|
|
|
|
_change_test_package_version(script, version_pkg_path)
|
2014-01-28 15:17:51 +01:00
|
|
|
sha1 = script.run(
|
2021-08-13 15:23:45 +02:00
|
|
|
"git",
|
|
|
|
"rev-parse",
|
|
|
|
"HEAD~1",
|
2014-01-28 15:17:51 +01:00
|
|
|
cwd=version_pkg_path,
|
|
|
|
).stdout.strip()
|
2019-04-04 10:32:44 +02:00
|
|
|
version = _install_version_pkg(script, version_pkg_path, rev=sha1)
|
2021-08-13 15:23:45 +02:00
|
|
|
assert "0.1" == version
|
2018-04-03 21:32:48 +02:00
|
|
|
|
|
|
|
|
2021-09-13 00:31:12 +02:00
|
|
|
def test_git_with_short_sha1_revisions(script: PipTestEnvironment) -> None:
|
2018-04-03 21:32:48 +02:00
|
|
|
"""
|
|
|
|
Git backend should be able to install from SHA1 revisions
|
|
|
|
"""
|
|
|
|
version_pkg_path = _create_test_package(script)
|
|
|
|
_change_test_package_version(script, version_pkg_path)
|
|
|
|
sha1 = script.run(
|
2021-08-13 15:23:45 +02:00
|
|
|
"git",
|
|
|
|
"rev-parse",
|
|
|
|
"HEAD~1",
|
2018-04-03 21:32:48 +02:00
|
|
|
cwd=version_pkg_path,
|
|
|
|
).stdout.strip()[:7]
|
2019-04-04 10:32:44 +02:00
|
|
|
version = _install_version_pkg(script, version_pkg_path, rev=sha1)
|
2021-08-13 15:23:45 +02:00
|
|
|
assert "0.1" == version
|
2010-08-05 16:09:40 +02:00
|
|
|
|
2010-08-05 16:35:05 +02:00
|
|
|
|
2021-09-13 00:31:12 +02:00
|
|
|
def test_git_with_branch_name_as_revision(script: PipTestEnvironment) -> None:
|
2010-08-05 16:35:05 +02:00
|
|
|
"""
|
|
|
|
Git backend should be able to install from branch names
|
|
|
|
"""
|
2013-08-21 11:16:07 +02:00
|
|
|
version_pkg_path = _create_test_package(script)
|
2021-08-13 15:23:45 +02:00
|
|
|
branch = "test_branch"
|
|
|
|
script.run("git", "checkout", "-b", branch, cwd=version_pkg_path)
|
2013-08-21 11:16:07 +02:00
|
|
|
_change_test_package_version(script, version_pkg_path)
|
2018-08-19 21:17:10 +02:00
|
|
|
version = _install_version_pkg(script, version_pkg_path, rev=branch)
|
2021-08-13 15:23:45 +02:00
|
|
|
assert "some different version" == version
|
2010-08-05 16:35:05 +02:00
|
|
|
|
2010-08-19 15:39:50 +02:00
|
|
|
|
2021-09-13 00:31:12 +02:00
|
|
|
def test_git_with_tag_name_as_revision(script: PipTestEnvironment) -> None:
|
2010-08-05 16:35:05 +02:00
|
|
|
"""
|
|
|
|
Git backend should be able to install from tag names
|
|
|
|
"""
|
2013-08-21 11:16:07 +02:00
|
|
|
version_pkg_path = _create_test_package(script)
|
2021-08-13 15:23:45 +02:00
|
|
|
script.run("git", "tag", "test_tag", cwd=version_pkg_path)
|
2013-08-21 11:16:07 +02:00
|
|
|
_change_test_package_version(script, version_pkg_path)
|
2021-08-13 15:23:45 +02:00
|
|
|
version = _install_version_pkg(script, version_pkg_path, rev="test_tag")
|
|
|
|
assert "0.1" == version
|
2010-08-05 16:35:05 +02:00
|
|
|
|
2010-11-20 19:44:08 +01:00
|
|
|
|
2021-09-13 00:31:12 +02:00
|
|
|
def _add_ref(script: PipTestEnvironment, path: Path, ref: str) -> None:
|
2017-04-07 00:47:01 +02:00
|
|
|
"""
|
2018-07-20 06:31:43 +02:00
|
|
|
Add a new ref to a repository at the given path.
|
2017-04-07 00:47:01 +02:00
|
|
|
"""
|
2021-08-13 15:23:45 +02:00
|
|
|
script.run("git", "update-ref", ref, "HEAD", cwd=path)
|
2018-07-20 06:31:43 +02:00
|
|
|
|
|
|
|
|
2021-09-13 00:31:12 +02:00
|
|
|
def test_git_install_ref(script: PipTestEnvironment) -> None:
|
2018-07-20 06:31:43 +02:00
|
|
|
"""
|
|
|
|
The Git backend should be able to install a ref with the first install.
|
|
|
|
"""
|
2018-08-19 21:17:10 +02:00
|
|
|
version_pkg_path = _create_test_package(script)
|
2021-08-13 15:23:45 +02:00
|
|
|
_add_ref(script, version_pkg_path, "refs/foo/bar")
|
2018-08-19 21:17:10 +02:00
|
|
|
_change_test_package_version(script, version_pkg_path)
|
2018-07-20 06:31:43 +02:00
|
|
|
|
2018-08-19 21:17:10 +02:00
|
|
|
version = _install_version_pkg(
|
2021-08-13 15:23:45 +02:00
|
|
|
script,
|
|
|
|
version_pkg_path,
|
|
|
|
rev="refs/foo/bar",
|
2018-08-19 21:17:10 +02:00
|
|
|
)
|
2021-08-13 15:23:45 +02:00
|
|
|
assert "0.1" == version
|
2018-07-20 06:31:43 +02:00
|
|
|
|
|
|
|
|
2021-09-13 00:31:12 +02:00
|
|
|
def test_git_install_then_install_ref(script: PipTestEnvironment) -> None:
|
2018-07-20 06:31:43 +02:00
|
|
|
"""
|
|
|
|
The Git backend should be able to install a ref after a package has
|
|
|
|
already been installed.
|
|
|
|
"""
|
2018-08-19 21:17:10 +02:00
|
|
|
version_pkg_path = _create_test_package(script)
|
2021-08-13 15:23:45 +02:00
|
|
|
_add_ref(script, version_pkg_path, "refs/foo/bar")
|
2018-08-19 21:17:10 +02:00
|
|
|
_change_test_package_version(script, version_pkg_path)
|
2018-07-20 06:31:43 +02:00
|
|
|
|
2019-04-04 10:32:44 +02:00
|
|
|
version = _install_version_pkg(script, version_pkg_path)
|
2021-08-13 15:23:45 +02:00
|
|
|
assert "some different version" == version
|
2018-07-20 06:31:43 +02:00
|
|
|
|
|
|
|
# Now install the ref.
|
2018-08-19 21:17:10 +02:00
|
|
|
version = _install_version_pkg(
|
2021-08-13 15:23:45 +02:00
|
|
|
script,
|
|
|
|
version_pkg_path,
|
|
|
|
rev="refs/foo/bar",
|
2018-08-19 21:17:10 +02:00
|
|
|
)
|
2021-08-13 15:23:45 +02:00
|
|
|
assert "0.1" == version
|
2017-04-07 00:47:01 +02:00
|
|
|
|
|
|
|
|
2021-07-22 09:29:16 +02:00
|
|
|
@pytest.mark.network
|
2021-08-13 15:23:45 +02:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"rev, expected_sha",
|
|
|
|
[
|
|
|
|
# Clone the default branch
|
|
|
|
("", "5547fa909e83df8bd743d3978d6667497983a4b7"),
|
|
|
|
# Clone a specific tag
|
|
|
|
("@0.1.1", "7d654e66c8fa7149c165ddeffa5b56bc06619458"),
|
|
|
|
# Clone a specific commit
|
|
|
|
(
|
|
|
|
"@65cf0a5bdd906ecf48a0ac241c17d656d2071d56",
|
|
|
|
"65cf0a5bdd906ecf48a0ac241c17d656d2071d56",
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
2021-09-13 00:31:12 +02:00
|
|
|
def test_install_git_logs_commit_sha(
|
|
|
|
script: PipTestEnvironment, rev: str, expected_sha: str, tmpdir: Path
|
|
|
|
) -> None:
|
2021-07-22 09:29:16 +02:00
|
|
|
"""
|
|
|
|
Test installing from a git repository logs a commit SHA.
|
|
|
|
"""
|
|
|
|
url_path = "pypa/pip-test-package.git"
|
|
|
|
base_local_url = _github_checkout(url_path, tmpdir)
|
|
|
|
local_url = f"{base_local_url}{rev}#egg=pip-test-package"
|
|
|
|
result = script.pip("install", local_url)
|
|
|
|
# `[4:]` removes a 'git+' prefix
|
|
|
|
assert f"Resolved {base_local_url[4:]} to commit {expected_sha}" in result.stdout
|
|
|
|
|
|
|
|
|
2015-01-15 00:53:15 +01:00
|
|
|
@pytest.mark.network
|
2021-09-13 00:31:12 +02:00
|
|
|
def test_git_with_tag_name_and_update(script: PipTestEnvironment, tmpdir: Path) -> None:
|
2010-11-20 19:44:08 +01:00
|
|
|
"""
|
|
|
|
Test cloning a git repository and updating to a different version.
|
|
|
|
"""
|
2021-08-13 15:23:45 +02:00
|
|
|
url_path = "pypa/pip-test-package.git"
|
2019-09-21 11:29:38 +02:00
|
|
|
base_local_url = _github_checkout(url_path, tmpdir)
|
|
|
|
|
2021-08-13 15:23:45 +02:00
|
|
|
local_url = f"{base_local_url}#egg=pip-test-package"
|
|
|
|
result = script.pip("install", "-e", local_url)
|
|
|
|
result.assert_installed("pip-test-package", with_files=[".git"])
|
2018-08-19 08:02:38 +02:00
|
|
|
|
2021-08-13 15:23:45 +02:00
|
|
|
new_local_url = f"{base_local_url}@0.1.2#egg=pip-test-package"
|
2014-01-28 15:17:51 +01:00
|
|
|
result = script.pip(
|
2021-08-13 15:23:45 +02:00
|
|
|
"install",
|
|
|
|
"--global-option=--version",
|
|
|
|
"-e",
|
|
|
|
new_local_url,
|
2021-12-10 14:41:05 +01:00
|
|
|
allow_stderr_warning=True,
|
2014-01-28 15:17:51 +01:00
|
|
|
)
|
2021-08-13 15:23:45 +02:00
|
|
|
assert "0.1.2" in result.stdout
|
2010-11-20 19:44:08 +01:00
|
|
|
|
2010-11-21 19:31:15 +01:00
|
|
|
|
2015-01-15 00:53:15 +01:00
|
|
|
@pytest.mark.network
|
2021-09-13 00:31:12 +02:00
|
|
|
def test_git_branch_should_not_be_changed(
|
|
|
|
script: PipTestEnvironment, tmpdir: Path
|
|
|
|
) -> None:
|
2010-11-21 19:31:15 +01:00
|
|
|
"""
|
|
|
|
Editable installations should not change branch
|
|
|
|
related to issue #32 and #161
|
|
|
|
"""
|
2021-08-13 15:23:45 +02:00
|
|
|
url_path = "pypa/pip-test-package.git"
|
|
|
|
local_url = _github_checkout(url_path, tmpdir, egg="pip-test-package")
|
|
|
|
script.pip("install", "-e", local_url)
|
|
|
|
branch = _get_editable_branch(script, "pip-test-package")
|
|
|
|
assert "master" == branch
|
2010-11-22 20:34:31 +01:00
|
|
|
|
2011-05-04 09:44:02 +02:00
|
|
|
|
2015-01-15 00:53:15 +01:00
|
|
|
@pytest.mark.network
|
2021-09-13 00:31:12 +02:00
|
|
|
def test_git_with_non_editable_unpacking(
|
|
|
|
script: PipTestEnvironment, tmpdir: Path
|
|
|
|
) -> None:
|
2010-11-22 20:34:31 +01:00
|
|
|
"""
|
|
|
|
Test cloning a git repository from a non-editable URL with a given tag.
|
|
|
|
"""
|
2021-08-13 15:23:45 +02:00
|
|
|
url_path = "pypa/pip-test-package.git"
|
2019-04-04 10:33:39 +02:00
|
|
|
local_url = _github_checkout(
|
2021-08-13 15:23:45 +02:00
|
|
|
url_path,
|
|
|
|
tmpdir,
|
|
|
|
rev="0.1.2",
|
|
|
|
egg="pip-test-package",
|
2014-01-28 15:17:51 +01:00
|
|
|
)
|
2021-12-10 14:41:05 +01:00
|
|
|
result = script.pip(
|
|
|
|
"install",
|
|
|
|
"--global-option=--version",
|
|
|
|
local_url,
|
|
|
|
allow_stderr_warning=True,
|
|
|
|
)
|
2021-08-13 15:23:45 +02:00
|
|
|
assert "0.1.2" in result.stdout
|
2010-12-09 03:34:14 +01:00
|
|
|
|
2011-05-04 09:44:02 +02:00
|
|
|
|
2015-01-15 00:53:15 +01:00
|
|
|
@pytest.mark.network
|
2021-09-13 00:31:12 +02:00
|
|
|
def test_git_with_editable_where_egg_contains_dev_string(
|
|
|
|
script: PipTestEnvironment, tmpdir: Path
|
|
|
|
) -> None:
|
2010-12-09 03:34:14 +01:00
|
|
|
"""
|
2014-01-28 15:17:51 +01:00
|
|
|
Test cloning a git repository from an editable url which contains "dev"
|
|
|
|
string
|
2010-12-09 03:34:14 +01:00
|
|
|
"""
|
2021-08-13 15:23:45 +02:00
|
|
|
url_path = "dcramer/django-devserver.git"
|
2018-08-19 09:43:38 +02:00
|
|
|
local_url = _github_checkout(
|
2021-08-13 15:23:45 +02:00
|
|
|
url_path,
|
|
|
|
tmpdir,
|
|
|
|
egg="django-devserver",
|
|
|
|
scheme="git",
|
2018-08-19 09:43:38 +02:00
|
|
|
)
|
2021-08-13 15:23:45 +02:00
|
|
|
result = script.pip("install", "-e", local_url)
|
|
|
|
result.assert_installed("django-devserver", with_files=[".git"])
|
2010-12-09 03:34:14 +01:00
|
|
|
|
2011-05-04 09:44:02 +02:00
|
|
|
|
2015-01-15 00:53:15 +01:00
|
|
|
@pytest.mark.network
|
2021-09-13 00:31:12 +02:00
|
|
|
def test_git_with_non_editable_where_egg_contains_dev_string(
|
|
|
|
script: PipTestEnvironment, tmpdir: Path
|
|
|
|
) -> None:
|
2010-12-09 03:34:14 +01:00
|
|
|
"""
|
2014-01-28 15:17:51 +01:00
|
|
|
Test cloning a git repository from a non-editable url which contains "dev"
|
|
|
|
string
|
2010-12-09 03:34:14 +01:00
|
|
|
"""
|
2021-08-13 15:23:45 +02:00
|
|
|
url_path = "dcramer/django-devserver.git"
|
2018-08-19 09:43:38 +02:00
|
|
|
local_url = _github_checkout(
|
2021-08-13 15:23:45 +02:00
|
|
|
url_path,
|
|
|
|
tmpdir,
|
|
|
|
egg="django-devserver",
|
|
|
|
scheme="git",
|
2018-08-19 09:43:38 +02:00
|
|
|
)
|
2021-08-13 15:23:45 +02:00
|
|
|
result = script.pip("install", local_url)
|
|
|
|
devserver_folder = script.site_packages / "devserver"
|
2020-05-28 12:18:16 +02:00
|
|
|
result.did_create(devserver_folder)
|
2011-05-15 17:47:06 +02:00
|
|
|
|
|
|
|
|
2021-09-13 00:31:12 +02:00
|
|
|
def test_git_with_ambiguous_revs(script: PipTestEnvironment) -> None:
|
2011-05-15 17:47:06 +02:00
|
|
|
"""
|
|
|
|
Test git with two "names" (tag/branch) pointing to the same commit
|
|
|
|
"""
|
2013-08-21 11:16:07 +02:00
|
|
|
version_pkg_path = _create_test_package(script)
|
2021-08-13 15:23:45 +02:00
|
|
|
version_pkg_url = _make_version_pkg_url(version_pkg_path, rev="0.1")
|
|
|
|
script.run("git", "tag", "0.1", cwd=version_pkg_path)
|
|
|
|
result = script.pip("install", "-e", version_pkg_url)
|
|
|
|
assert "Could not find a tag or branch" not in result.stdout
|
2011-05-15 17:47:06 +02:00
|
|
|
# it is 'version-pkg' instead of 'version_pkg' because
|
|
|
|
# egg-link name is version-pkg.egg-link because it is a single .py module
|
2021-08-13 15:23:45 +02:00
|
|
|
result.assert_installed("version-pkg", with_files=[".git"])
|
2012-03-24 19:26:34 +01:00
|
|
|
|
2012-04-14 05:41:33 +02:00
|
|
|
|
2021-09-13 00:31:12 +02:00
|
|
|
def test_editable__no_revision(script: PipTestEnvironment) -> None:
|
2018-08-21 10:51:06 +02:00
|
|
|
"""
|
|
|
|
Test a basic install in editable mode specifying no revision.
|
|
|
|
"""
|
|
|
|
version_pkg_path = _create_test_package(script)
|
|
|
|
_install_version_pkg_only(script, version_pkg_path)
|
|
|
|
|
2021-08-13 15:23:45 +02:00
|
|
|
branch = _get_editable_branch(script, "version-pkg")
|
|
|
|
assert branch == "master"
|
2018-08-21 10:51:06 +02:00
|
|
|
|
2021-08-13 15:23:45 +02:00
|
|
|
remote = _get_branch_remote(script, "version-pkg", "master")
|
|
|
|
assert remote == "origin"
|
2018-08-21 10:51:06 +02:00
|
|
|
|
|
|
|
|
2021-09-13 00:31:12 +02:00
|
|
|
def test_editable__branch_with_sha_same_as_default(script: PipTestEnvironment) -> None:
|
2018-08-21 10:51:06 +02:00
|
|
|
"""
|
|
|
|
Test installing in editable mode a branch whose sha matches the sha
|
2018-08-21 22:35:29 +02:00
|
|
|
of the default branch, but is different from the default branch.
|
2018-08-21 10:51:06 +02:00
|
|
|
"""
|
|
|
|
version_pkg_path = _create_test_package(script)
|
|
|
|
# Create a second branch with the same SHA.
|
2021-08-13 15:23:45 +02:00
|
|
|
script.run("git", "branch", "develop", cwd=version_pkg_path)
|
|
|
|
_install_version_pkg_only(script, version_pkg_path, rev="develop")
|
2018-08-21 10:51:06 +02:00
|
|
|
|
2021-08-13 15:23:45 +02:00
|
|
|
branch = _get_editable_branch(script, "version-pkg")
|
|
|
|
assert branch == "develop"
|
2018-08-21 10:51:06 +02:00
|
|
|
|
2021-08-13 15:23:45 +02:00
|
|
|
remote = _get_branch_remote(script, "version-pkg", "develop")
|
|
|
|
assert remote == "origin"
|
2018-08-21 10:51:06 +02:00
|
|
|
|
|
|
|
|
2021-09-13 00:31:12 +02:00
|
|
|
def test_editable__branch_with_sha_different_from_default(
|
|
|
|
script: PipTestEnvironment,
|
|
|
|
) -> None:
|
2018-08-21 10:51:06 +02:00
|
|
|
"""
|
|
|
|
Test installing in editable mode a branch whose sha is different from
|
|
|
|
the sha of the default branch.
|
|
|
|
"""
|
|
|
|
version_pkg_path = _create_test_package(script)
|
|
|
|
# Create a second branch.
|
2021-08-13 15:23:45 +02:00
|
|
|
script.run("git", "branch", "develop", cwd=version_pkg_path)
|
2018-08-21 10:51:06 +02:00
|
|
|
# Add another commit to the master branch to give it a different sha.
|
|
|
|
_change_test_package_version(script, version_pkg_path)
|
|
|
|
|
2021-08-13 15:23:45 +02:00
|
|
|
version = _install_version_pkg(script, version_pkg_path, rev="develop")
|
|
|
|
assert version == "0.1"
|
2018-08-21 10:51:06 +02:00
|
|
|
|
2021-08-13 15:23:45 +02:00
|
|
|
branch = _get_editable_branch(script, "version-pkg")
|
|
|
|
assert branch == "develop"
|
2018-08-21 10:51:06 +02:00
|
|
|
|
2021-08-13 15:23:45 +02:00
|
|
|
remote = _get_branch_remote(script, "version-pkg", "develop")
|
|
|
|
assert remote == "origin"
|
2018-08-21 10:51:06 +02:00
|
|
|
|
|
|
|
|
2021-09-13 00:31:12 +02:00
|
|
|
def test_editable__non_master_default_branch(script: PipTestEnvironment) -> None:
|
2018-08-19 22:03:02 +02:00
|
|
|
"""
|
|
|
|
Test the branch you get after an editable install from a remote repo
|
|
|
|
with a non-master default branch.
|
|
|
|
"""
|
|
|
|
version_pkg_path = _create_test_package(script)
|
|
|
|
# Change the default branch of the remote repo to a name that is
|
|
|
|
# alphabetically after "master".
|
2021-08-13 15:23:45 +02:00
|
|
|
script.run("git", "checkout", "-b", "release", cwd=version_pkg_path)
|
2018-08-19 22:03:02 +02:00
|
|
|
_install_version_pkg_only(script, version_pkg_path)
|
2018-08-21 10:51:06 +02:00
|
|
|
|
2021-08-13 15:23:45 +02:00
|
|
|
branch = _get_editable_branch(script, "version-pkg")
|
|
|
|
assert branch == "release"
|
2018-08-19 22:03:02 +02:00
|
|
|
|
|
|
|
|
2021-09-13 00:31:12 +02:00
|
|
|
def test_reinstalling_works_with_editable_non_master_branch(
|
|
|
|
script: PipTestEnvironment,
|
|
|
|
) -> None:
|
2017-09-30 00:30:30 +02:00
|
|
|
"""
|
|
|
|
Reinstalling an editable installation should not assume that the "master"
|
|
|
|
branch exists. See https://github.com/pypa/pip/issues/4448.
|
|
|
|
"""
|
|
|
|
version_pkg_path = _create_test_package(script)
|
|
|
|
|
|
|
|
# Switch the default branch to something other than 'master'
|
2021-08-13 15:23:45 +02:00
|
|
|
script.run("git", "branch", "-m", "foobar", cwd=version_pkg_path)
|
2017-09-30 00:30:30 +02:00
|
|
|
|
2018-08-19 21:17:10 +02:00
|
|
|
version = _install_version_pkg(script, version_pkg_path)
|
2021-08-13 15:23:45 +02:00
|
|
|
assert "0.1" == version
|
2017-09-30 00:30:30 +02:00
|
|
|
|
|
|
|
_change_test_package_version(script, version_pkg_path)
|
2018-08-19 21:17:10 +02:00
|
|
|
version = _install_version_pkg(script, version_pkg_path)
|
2021-08-13 15:23:45 +02:00
|
|
|
assert "some different version" == version
|
2018-07-27 18:11:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
# TODO(pnasrat) fix all helpers to do right things with paths on windows.
|
|
|
|
@pytest.mark.skipif("sys.platform == 'win32'")
|
2021-09-13 00:31:12 +02:00
|
|
|
def test_check_submodule_addition(script: PipTestEnvironment) -> None:
|
2018-07-27 18:11:42 +02:00
|
|
|
"""
|
|
|
|
Submodules are pulled in on install and updated on upgrade.
|
|
|
|
"""
|
2021-08-13 15:23:45 +02:00
|
|
|
module_path, submodule_path = _create_test_package_with_submodule(
|
|
|
|
script, rel_path="testpkg/static"
|
2018-10-24 12:35:52 +02:00
|
|
|
)
|
2018-07-27 18:11:42 +02:00
|
|
|
|
|
|
|
install_result = script.pip(
|
2021-08-13 15:23:45 +02:00
|
|
|
"install", "-e", "git+" + path_to_url(module_path) + "#egg=version_pkg"
|
2018-07-27 18:11:42 +02:00
|
|
|
)
|
2021-08-13 15:23:45 +02:00
|
|
|
install_result.did_create(script.venv / "src/version-pkg/testpkg/static/testfile")
|
2018-07-27 18:11:42 +02:00
|
|
|
|
|
|
|
_change_test_package_submodule(script, submodule_path)
|
2018-10-24 12:35:52 +02:00
|
|
|
_pull_in_submodule_changes_to_module(
|
2021-08-13 15:23:45 +02:00
|
|
|
script,
|
|
|
|
module_path,
|
|
|
|
rel_path="testpkg/static",
|
2018-10-24 12:35:52 +02:00
|
|
|
)
|
2018-07-27 18:11:42 +02:00
|
|
|
|
|
|
|
# expect error because git may write to stderr
|
|
|
|
update_result = script.pip(
|
2021-08-13 15:23:45 +02:00
|
|
|
"install",
|
|
|
|
"-e",
|
|
|
|
"git+" + path_to_url(module_path) + "#egg=version_pkg",
|
|
|
|
"--upgrade",
|
2018-07-27 18:11:42 +02:00
|
|
|
)
|
|
|
|
|
2021-08-13 15:23:45 +02:00
|
|
|
update_result.did_create(script.venv / "src/version-pkg/testpkg/static/testfile2")
|
2019-11-02 15:14:39 +01:00
|
|
|
|
|
|
|
|
2021-09-21 06:44:29 +02:00
|
|
|
@pytest.mark.usefixtures("with_wheel")
|
2021-09-13 00:31:12 +02:00
|
|
|
def test_install_git_branch_not_cached(script: PipTestEnvironment) -> None:
|
2019-11-02 15:14:39 +01:00
|
|
|
"""
|
|
|
|
Installing git urls with a branch revision does not cause wheel caching.
|
|
|
|
"""
|
|
|
|
PKG = "gitbranchnotcached"
|
|
|
|
repo_dir = _create_test_package(script, name=PKG)
|
|
|
|
url = _make_version_pkg_url(repo_dir, rev="master", name=PKG)
|
|
|
|
result = script.pip("install", url, "--only-binary=:all:")
|
2020-12-23 20:25:12 +01:00
|
|
|
assert f"Successfully built {PKG}" in result.stdout, result.stdout
|
2019-11-02 15:14:39 +01:00
|
|
|
script.pip("uninstall", "-y", PKG)
|
|
|
|
# build occurs on the second install too because it is not cached
|
|
|
|
result = script.pip("install", url)
|
2021-08-13 15:23:45 +02:00
|
|
|
assert f"Successfully built {PKG}" in result.stdout, result.stdout
|
2019-11-02 15:14:39 +01:00
|
|
|
|
|
|
|
|
2021-09-21 06:44:29 +02:00
|
|
|
@pytest.mark.usefixtures("with_wheel")
|
2021-09-13 00:31:12 +02:00
|
|
|
def test_install_git_sha_cached(script: PipTestEnvironment) -> None:
|
2019-11-02 15:14:39 +01:00
|
|
|
"""
|
|
|
|
Installing git urls with a sha revision does cause wheel caching.
|
|
|
|
"""
|
|
|
|
PKG = "gitshacached"
|
|
|
|
repo_dir = _create_test_package(script, name=PKG)
|
2021-08-13 15:23:45 +02:00
|
|
|
commit = script.run("git", "rev-parse", "HEAD", cwd=repo_dir).stdout.strip()
|
2019-11-02 15:14:39 +01:00
|
|
|
url = _make_version_pkg_url(repo_dir, rev=commit, name=PKG)
|
|
|
|
result = script.pip("install", url)
|
2020-12-23 20:25:12 +01:00
|
|
|
assert f"Successfully built {PKG}" in result.stdout, result.stdout
|
2019-11-02 15:14:39 +01:00
|
|
|
script.pip("uninstall", "-y", PKG)
|
|
|
|
# build does not occur on the second install because it is cached
|
|
|
|
result = script.pip("install", url)
|
2021-08-13 15:23:45 +02:00
|
|
|
assert f"Successfully built {PKG}" not in result.stdout, result.stdout
|