pip/tests/lib/local_repos.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

64 lines
1.9 KiB
Python
Raw Normal View History

2010-06-16 12:32:57 +02:00
import os
import subprocess
import urllib.request
from pathlib import Path
from pip._internal.utils.misc import hide_url
2019-09-13 19:20:34 +02:00
from pip._internal.vcs import vcs
def _create_svn_initools_repo(initools_dir: str) -> None:
2019-09-13 19:20:34 +02:00
"""
Create the SVN INITools repo.
2019-09-13 19:20:34 +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)
filename, _ = urllib.request.urlretrieve(
2021-04-02 11:21:40 +02:00
"http://bitbucket.org/hltbra/pip-initools-dump/raw/8b55c908a320/"
"INITools_modified.dump"
)
with open(filename) as dump:
subprocess.check_call(
2021-04-02 11:21:40 +02:00
["svnadmin", "load", initools_dir],
stdin=dump,
stdout=subprocess.DEVNULL,
)
2010-09-14 01:21:32 +02:00
os.remove(filename)
2010-06-16 12:32:57 +02:00
def local_checkout(
remote_repo: str,
temp_path: Path,
) -> str:
"""
: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]
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")
repo_url_path = os.path.join(directory, repository_name)
assert not os.path.exists(repo_url_path)
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"
_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)
assert vcs_backend is not None
vcs_backend.obtain(repo_url_path, url=hide_url(remote_repo), verbosity=0)
2019-09-13 19:20:34 +02:00
2023-11-07 10:14:56 +01:00
return f"{vcs_name}+{Path(repo_url_path).as_uri()}"
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]