mirror of
https://github.com/pypa/pip
synced 2023-12-13 21:30:23 +01:00
Simplify local_repos.py.
This commit is contained in:
parent
0a2238ac38
commit
144051e422
|
@ -7,27 +7,32 @@ from pip._vendor.six.moves.urllib import request as urllib_request
|
|||
|
||||
from pip._internal.utils.misc import hide_url
|
||||
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
|
||||
from pip._internal.vcs import bazaar, git, mercurial, subversion
|
||||
from pip._internal.vcs import vcs
|
||||
from tests.lib import path_to_url
|
||||
|
||||
if MYPY_CHECK_RUNNING:
|
||||
from tests.lib.path import Path
|
||||
|
||||
|
||||
def _create_initools_repository(directory):
|
||||
def _ensure_svn_initools_repo(directory):
|
||||
"""
|
||||
Create the SVN INITools repo if it doesn't already exist.
|
||||
"""
|
||||
initools_dir = os.path.join(directory, 'INITools')
|
||||
repo_url_path = os.path.join(initools_dir, 'trunk')
|
||||
if os.path.exists(initools_dir):
|
||||
return repo_url_path
|
||||
|
||||
subprocess.check_call('svnadmin create INITools'.split(), cwd=directory)
|
||||
|
||||
|
||||
def _dump_initools_repository(directory):
|
||||
filename, _ = urllib_request.urlretrieve(
|
||||
'http://bitbucket.org/hltbra/pip-initools-dump/raw/8b55c908a320/'
|
||||
'INITools_modified.dump'
|
||||
)
|
||||
initools_folder = os.path.join(directory, 'INITools')
|
||||
devnull = open(os.devnull, 'w')
|
||||
dump = open(filename)
|
||||
subprocess.check_call(
|
||||
['svnadmin', 'load', initools_folder],
|
||||
['svnadmin', 'load', initools_dir],
|
||||
stdin=dump,
|
||||
stdout=devnull,
|
||||
)
|
||||
|
@ -35,41 +40,7 @@ def _dump_initools_repository(directory):
|
|||
devnull.close()
|
||||
os.remove(filename)
|
||||
|
||||
|
||||
def _create_svn_repository_for_initools(directory):
|
||||
if not os.path.exists(os.path.join(directory, 'INITools')):
|
||||
_create_initools_repository(directory)
|
||||
_dump_initools_repository(directory)
|
||||
|
||||
|
||||
def _get_vcs_and_checkout_url(remote_repository, directory):
|
||||
vcs_classes = {'svn': subversion.Subversion,
|
||||
'git': git.Git,
|
||||
'bzr': bazaar.Bazaar,
|
||||
'hg': mercurial.Mercurial}
|
||||
default_vcs = 'svn'
|
||||
if '+' not in remote_repository:
|
||||
remote_repository = '%s+%s' % (default_vcs, remote_repository)
|
||||
vcs, repository_path = remote_repository.split('+', 1)
|
||||
vcs_class = vcs_classes[vcs]
|
||||
branch = ''
|
||||
if vcs == 'svn':
|
||||
branch = os.path.basename(remote_repository)
|
||||
# remove the slash
|
||||
repository_name = os.path.basename(
|
||||
remote_repository[:-len(branch) - 1]
|
||||
)
|
||||
else:
|
||||
repository_name = os.path.basename(remote_repository)
|
||||
|
||||
destination_path = os.path.join(directory, repository_name)
|
||||
if not os.path.exists(destination_path):
|
||||
url = hide_url(remote_repository)
|
||||
vcs_class().obtain(destination_path, url=url)
|
||||
return '%s+%s' % (
|
||||
vcs,
|
||||
path_to_url('/'.join([directory, repository_name, branch])),
|
||||
)
|
||||
return repo_url_path
|
||||
|
||||
|
||||
def local_checkout(
|
||||
|
@ -82,14 +53,23 @@ def local_checkout(
|
|||
temp directory Path object unique to each test function invocation,
|
||||
created as a sub directory of the base temp directory.
|
||||
"""
|
||||
assert '+' in remote_repo
|
||||
vcs_name, repository_path = remote_repo.split('+', 1)
|
||||
|
||||
directory = temp_path.joinpath('cache')
|
||||
if not os.path.exists(directory):
|
||||
os.mkdir(directory)
|
||||
# os.makedirs(directory)
|
||||
|
||||
if remote_repo.startswith('svn'):
|
||||
_create_svn_repository_for_initools(directory)
|
||||
return _get_vcs_and_checkout_url(remote_repo, directory)
|
||||
if vcs_name == 'svn':
|
||||
assert remote_repo.endswith('/INITools/trunk')
|
||||
repo_url_path = _ensure_svn_initools_repo(directory)
|
||||
else:
|
||||
repository_name = os.path.basename(remote_repo)
|
||||
repo_url_path = os.path.join(directory, repository_name)
|
||||
vcs_backend = vcs.get_backend(vcs_name)
|
||||
vcs_backend.obtain(repo_url_path, url=hide_url(remote_repo))
|
||||
|
||||
return '{}+{}'.format(vcs_name, path_to_url(repo_url_path))
|
||||
|
||||
|
||||
def local_repo(remote_repo, temp_path):
|
||||
|
|
Loading…
Reference in a new issue