2010-06-16 12:32:57 +02:00
|
|
|
import os
|
|
|
|
import subprocess
|
2020-12-27 15:01:06 +01:00
|
|
|
import urllib.request
|
2014-09-12 00:40:45 +02:00
|
|
|
|
2019-08-21 12:22:57 +02:00
|
|
|
from pip._internal.utils.misc import hide_url
|
2019-09-13 19:20:34 +02:00
|
|
|
from pip._internal.vcs import vcs
|
2013-05-27 19:46:31 +02:00
|
|
|
from tests.lib import path_to_url
|
2021-02-19 13:56:59 +01:00
|
|
|
from tests.lib.path import Path
|
2019-09-13 18:18:07 +02:00
|
|
|
|
2011-03-19 04:17:56 +01:00
|
|
|
|
2021-08-28 17:52:10 +02:00
|
|
|
def _create_svn_initools_repo(initools_dir: str) -> None:
|
2019-09-13 19:20:34 +02:00
|
|
|
"""
|
2019-09-19 09:50:16 +02:00
|
|
|
Create the SVN INITools repo.
|
2019-09-13 19:20:34 +02:00
|
|
|
"""
|
2019-09-21 12:01:17 +02:00
|
|
|
directory = os.path.dirname(initools_dir)
|
2021-04-02 11:21:40 +02:00
|
|
|
subprocess.check_call("svnadmin create INITools".split(), cwd=directory)
|
2013-08-21 11:16:07 +02:00
|
|
|
|
2020-12-27 15:01:06 +01:00
|
|
|
filename, _ = urllib.request.urlretrieve(
|
2021-04-02 11:21:40 +02:00
|
|
|
"http://bitbucket.org/hltbra/pip-initools-dump/raw/8b55c908a320/"
|
|
|
|
"INITools_modified.dump"
|
2014-01-28 15:17:51 +01:00
|
|
|
)
|
2020-12-26 16:17:39 +01:00
|
|
|
with open(filename) as dump:
|
|
|
|
subprocess.check_call(
|
2021-04-02 11:21:40 +02:00
|
|
|
["svnadmin", "load", initools_dir],
|
2020-12-26 16:17:39 +01:00
|
|
|
stdin=dump,
|
|
|
|
stdout=subprocess.DEVNULL,
|
|
|
|
)
|
2010-09-14 01:21:32 +02:00
|
|
|
os.remove(filename)
|
2010-06-16 12:32:57 +02:00
|
|
|
|
|
|
|
|
2019-09-13 18:18:07 +02:00
|
|
|
def local_checkout(
|
2021-08-08 02:14:17 +02:00
|
|
|
remote_repo: str,
|
|
|
|
temp_path: Path,
|
|
|
|
) -> str:
|
2019-09-13 18:18:07 +02:00
|
|
|
"""
|
|
|
|
:param temp_path: the return value of the tmpdir fixture, which is a
|
|
|
|
temp directory Path object unique to each test function invocation,
|
|
|
|
created as a sub directory of the base temp directory.
|
|
|
|
"""
|
2021-04-02 11:21:40 +02:00
|
|
|
assert "+" in remote_repo
|
|
|
|
vcs_name = remote_repo.split("+", 1)[0]
|
2019-09-21 12:01:17 +02:00
|
|
|
repository_name = os.path.basename(remote_repo)
|
2019-09-13 19:20:34 +02:00
|
|
|
|
2021-04-02 11:21:40 +02:00
|
|
|
directory = temp_path.joinpath("cache")
|
2019-09-21 12:01:17 +02:00
|
|
|
repo_url_path = os.path.join(directory, repository_name)
|
|
|
|
assert not os.path.exists(repo_url_path)
|
|
|
|
|
2013-08-22 12:14:09 +02:00
|
|
|
if not os.path.exists(directory):
|
|
|
|
os.mkdir(directory)
|
2010-06-16 12:32:57 +02:00
|
|
|
|
2021-04-02 11:21:40 +02:00
|
|
|
if vcs_name == "svn":
|
|
|
|
assert repository_name == "INITools"
|
2019-09-21 12:01:17 +02:00
|
|
|
_create_svn_initools_repo(repo_url_path)
|
2021-04-02 11:21:40 +02:00
|
|
|
repo_url_path = os.path.join(repo_url_path, "trunk")
|
2019-09-13 19:20:34 +02:00
|
|
|
else:
|
|
|
|
vcs_backend = vcs.get_backend(vcs_name)
|
2021-08-22 06:04:11 +02:00
|
|
|
assert vcs_backend is not None
|
2022-01-25 09:54:02 +01:00
|
|
|
vcs_backend.obtain(repo_url_path, url=hide_url(remote_repo), verbosity=0)
|
2019-09-13 19:20:34 +02:00
|
|
|
|
2021-04-02 11:21:40 +02:00
|
|
|
return "{}+{}".format(vcs_name, path_to_url(repo_url_path))
|
2010-06-22 00:48:28 +02:00
|
|
|
|
|
|
|
|
2021-08-28 17:52:10 +02:00
|
|
|
def local_repo(remote_repo: str, temp_path: Path) -> str:
|
2021-04-02 11:21:40 +02:00
|
|
|
return local_checkout(remote_repo, temp_path).split("+", 1)[1]
|