reupload
This commit is contained in:
110
env/lib/python3.6/site-packages/pip/_internal/vcs/bazaar.py
vendored
Normal file
110
env/lib/python3.6/site-packages/pip/_internal/vcs/bazaar.py
vendored
Normal file
@@ -0,0 +1,110 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
import logging
|
||||
import os
|
||||
|
||||
from pip._vendor.six.moves.urllib import parse as urllib_parse
|
||||
|
||||
from pip._internal.download import path_to_url
|
||||
from pip._internal.utils.misc import display_path, rmtree
|
||||
from pip._internal.utils.temp_dir import TempDirectory
|
||||
from pip._internal.vcs import VersionControl, vcs
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Bazaar(VersionControl):
|
||||
name = 'bzr'
|
||||
dirname = '.bzr'
|
||||
repo_name = 'branch'
|
||||
schemes = (
|
||||
'bzr', 'bzr+http', 'bzr+https', 'bzr+ssh', 'bzr+sftp', 'bzr+ftp',
|
||||
'bzr+lp',
|
||||
)
|
||||
|
||||
def __init__(self, url=None, *args, **kwargs):
|
||||
super(Bazaar, self).__init__(url, *args, **kwargs)
|
||||
# This is only needed for python <2.7.5
|
||||
# Register lp but do not expose as a scheme to support bzr+lp.
|
||||
if getattr(urllib_parse, 'uses_fragment', None):
|
||||
urllib_parse.uses_fragment.extend(['lp'])
|
||||
|
||||
def get_base_rev_args(self, rev):
|
||||
return ['-r', rev]
|
||||
|
||||
def export(self, location):
|
||||
"""
|
||||
Export the Bazaar repository at the url to the destination location
|
||||
"""
|
||||
# Remove the location to make sure Bazaar can export it correctly
|
||||
if os.path.exists(location):
|
||||
rmtree(location)
|
||||
|
||||
with TempDirectory(kind="export") as temp_dir:
|
||||
self.unpack(temp_dir.path)
|
||||
|
||||
self.run_command(
|
||||
['export', location],
|
||||
cwd=temp_dir.path, show_stdout=False,
|
||||
)
|
||||
|
||||
def fetch_new(self, dest, url, rev_options):
|
||||
rev_display = rev_options.to_display()
|
||||
logger.info(
|
||||
'Checking out %s%s to %s',
|
||||
url,
|
||||
rev_display,
|
||||
display_path(dest),
|
||||
)
|
||||
cmd_args = ['branch', '-q'] + rev_options.to_args() + [url, dest]
|
||||
self.run_command(cmd_args)
|
||||
|
||||
def switch(self, dest, url, rev_options):
|
||||
self.run_command(['switch', url], cwd=dest)
|
||||
|
||||
def update(self, dest, rev_options):
|
||||
cmd_args = ['pull', '-q'] + rev_options.to_args()
|
||||
self.run_command(cmd_args, cwd=dest)
|
||||
|
||||
def get_url_rev(self, url):
|
||||
# hotfix the URL scheme after removing bzr+ from bzr+ssh:// readd it
|
||||
url, rev = super(Bazaar, self).get_url_rev(url)
|
||||
if url.startswith('ssh://'):
|
||||
url = 'bzr+' + url
|
||||
return url, rev
|
||||
|
||||
def get_url(self, location):
|
||||
urls = self.run_command(['info'], show_stdout=False, cwd=location)
|
||||
for line in urls.splitlines():
|
||||
line = line.strip()
|
||||
for x in ('checkout of branch: ',
|
||||
'parent branch: '):
|
||||
if line.startswith(x):
|
||||
repo = line.split(x)[1]
|
||||
if self._is_local_repository(repo):
|
||||
return path_to_url(repo)
|
||||
return repo
|
||||
return None
|
||||
|
||||
def get_revision(self, location):
|
||||
revision = self.run_command(
|
||||
['revno'], show_stdout=False, cwd=location,
|
||||
)
|
||||
return revision.splitlines()[-1]
|
||||
|
||||
def get_src_requirement(self, dist, location):
|
||||
repo = self.get_url(location)
|
||||
if not repo:
|
||||
return None
|
||||
if not repo.lower().startswith('bzr:'):
|
||||
repo = 'bzr+' + repo
|
||||
egg_project_name = dist.egg_name().split('-', 1)[0]
|
||||
current_rev = self.get_revision(location)
|
||||
return '%s@%s#egg=%s' % (repo, current_rev, egg_project_name)
|
||||
|
||||
def is_commit_id_equal(self, dest, name):
|
||||
"""Always assume the versions don't match"""
|
||||
return False
|
||||
|
||||
|
||||
vcs.register(Bazaar)
|
||||
309
env/lib/python3.6/site-packages/pip/_internal/vcs/git.py
vendored
Normal file
309
env/lib/python3.6/site-packages/pip/_internal/vcs/git.py
vendored
Normal file
@@ -0,0 +1,309 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
import logging
|
||||
import os.path
|
||||
import re
|
||||
|
||||
from pip._vendor.packaging.version import parse as parse_version
|
||||
from pip._vendor.six.moves.urllib import parse as urllib_parse
|
||||
from pip._vendor.six.moves.urllib import request as urllib_request
|
||||
|
||||
from pip._internal.compat import samefile
|
||||
from pip._internal.exceptions import BadCommand
|
||||
from pip._internal.utils.misc import display_path
|
||||
from pip._internal.utils.temp_dir import TempDirectory
|
||||
from pip._internal.vcs import VersionControl, vcs
|
||||
|
||||
urlsplit = urllib_parse.urlsplit
|
||||
urlunsplit = urllib_parse.urlunsplit
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
HASH_REGEX = re.compile('[a-fA-F0-9]{40}')
|
||||
|
||||
|
||||
def looks_like_hash(sha):
|
||||
return bool(HASH_REGEX.match(sha))
|
||||
|
||||
|
||||
class Git(VersionControl):
|
||||
name = 'git'
|
||||
dirname = '.git'
|
||||
repo_name = 'clone'
|
||||
schemes = (
|
||||
'git', 'git+http', 'git+https', 'git+ssh', 'git+git', 'git+file',
|
||||
)
|
||||
# Prevent the user's environment variables from interfering with pip:
|
||||
# https://github.com/pypa/pip/issues/1130
|
||||
unset_environ = ('GIT_DIR', 'GIT_WORK_TREE')
|
||||
default_arg_rev = 'HEAD'
|
||||
|
||||
def __init__(self, url=None, *args, **kwargs):
|
||||
|
||||
# Works around an apparent Git bug
|
||||
# (see https://article.gmane.org/gmane.comp.version-control.git/146500)
|
||||
if url:
|
||||
scheme, netloc, path, query, fragment = urlsplit(url)
|
||||
if scheme.endswith('file'):
|
||||
initial_slashes = path[:-len(path.lstrip('/'))]
|
||||
newpath = (
|
||||
initial_slashes +
|
||||
urllib_request.url2pathname(path)
|
||||
.replace('\\', '/').lstrip('/')
|
||||
)
|
||||
url = urlunsplit((scheme, netloc, newpath, query, fragment))
|
||||
after_plus = scheme.find('+') + 1
|
||||
url = scheme[:after_plus] + urlunsplit(
|
||||
(scheme[after_plus:], netloc, newpath, query, fragment),
|
||||
)
|
||||
|
||||
super(Git, self).__init__(url, *args, **kwargs)
|
||||
|
||||
def get_base_rev_args(self, rev):
|
||||
return [rev]
|
||||
|
||||
def get_git_version(self):
|
||||
VERSION_PFX = 'git version '
|
||||
version = self.run_command(['version'], show_stdout=False)
|
||||
if version.startswith(VERSION_PFX):
|
||||
version = version[len(VERSION_PFX):].split()[0]
|
||||
else:
|
||||
version = ''
|
||||
# get first 3 positions of the git version becasue
|
||||
# on windows it is x.y.z.windows.t, and this parses as
|
||||
# LegacyVersion which always smaller than a Version.
|
||||
version = '.'.join(version.split('.')[:3])
|
||||
return parse_version(version)
|
||||
|
||||
def export(self, location):
|
||||
"""Export the Git repository at the url to the destination location"""
|
||||
if not location.endswith('/'):
|
||||
location = location + '/'
|
||||
|
||||
with TempDirectory(kind="export") as temp_dir:
|
||||
self.unpack(temp_dir.path)
|
||||
self.run_command(
|
||||
['checkout-index', '-a', '-f', '--prefix', location],
|
||||
show_stdout=False, cwd=temp_dir.path
|
||||
)
|
||||
|
||||
def get_revision_sha(self, dest, rev):
|
||||
"""
|
||||
Return a commit hash for the given revision if it names a remote
|
||||
branch or tag. Otherwise, return None.
|
||||
|
||||
Args:
|
||||
dest: the repository directory.
|
||||
rev: the revision name.
|
||||
"""
|
||||
# Pass rev to pre-filter the list.
|
||||
output = self.run_command(['show-ref', rev], cwd=dest,
|
||||
show_stdout=False, on_returncode='ignore')
|
||||
refs = {}
|
||||
for line in output.strip().splitlines():
|
||||
try:
|
||||
sha, ref = line.split()
|
||||
except ValueError:
|
||||
# Include the offending line to simplify troubleshooting if
|
||||
# this error ever occurs.
|
||||
raise ValueError('unexpected show-ref line: {!r}'.format(line))
|
||||
|
||||
refs[ref] = sha
|
||||
|
||||
branch_ref = 'refs/remotes/origin/{}'.format(rev)
|
||||
tag_ref = 'refs/tags/{}'.format(rev)
|
||||
|
||||
return refs.get(branch_ref) or refs.get(tag_ref)
|
||||
|
||||
def check_rev_options(self, dest, rev_options):
|
||||
"""Check the revision options before checkout.
|
||||
|
||||
Returns a new RevOptions object for the SHA1 of the branch or tag
|
||||
if found.
|
||||
|
||||
Args:
|
||||
rev_options: a RevOptions object.
|
||||
"""
|
||||
rev = rev_options.arg_rev
|
||||
sha = self.get_revision_sha(dest, rev)
|
||||
|
||||
if sha is not None:
|
||||
return rev_options.make_new(sha)
|
||||
|
||||
# Do not show a warning for the common case of something that has
|
||||
# the form of a Git commit hash.
|
||||
if not looks_like_hash(rev):
|
||||
logger.warning(
|
||||
"Did not find branch or tag '%s', assuming revision or ref.",
|
||||
rev,
|
||||
)
|
||||
return rev_options
|
||||
|
||||
def is_commit_id_equal(self, dest, name):
|
||||
"""
|
||||
Return whether the current commit hash equals the given name.
|
||||
|
||||
Args:
|
||||
dest: the repository directory.
|
||||
name: a string name.
|
||||
"""
|
||||
if not name:
|
||||
# Then avoid an unnecessary subprocess call.
|
||||
return False
|
||||
|
||||
return self.get_revision(dest) == name
|
||||
|
||||
def fetch_new(self, dest, url, rev_options):
|
||||
rev_display = rev_options.to_display()
|
||||
logger.info(
|
||||
'Cloning %s%s to %s', url, rev_display, display_path(dest),
|
||||
)
|
||||
self.run_command(['clone', '-q', url, dest])
|
||||
|
||||
if rev_options.rev:
|
||||
# Then a specific revision was requested.
|
||||
rev_options = self.check_rev_options(dest, rev_options)
|
||||
# Only do a checkout if the current commit id doesn't match
|
||||
# the requested revision.
|
||||
if not self.is_commit_id_equal(dest, rev_options.rev):
|
||||
rev = rev_options.rev
|
||||
# Only fetch the revision if it's a ref
|
||||
if rev.startswith('refs/'):
|
||||
self.run_command(
|
||||
['fetch', '-q', url] + rev_options.to_args(),
|
||||
cwd=dest,
|
||||
)
|
||||
# Change the revision to the SHA of the ref we fetched
|
||||
rev = 'FETCH_HEAD'
|
||||
self.run_command(['checkout', '-q', rev], cwd=dest)
|
||||
|
||||
#: repo may contain submodules
|
||||
self.update_submodules(dest)
|
||||
|
||||
def switch(self, dest, url, rev_options):
|
||||
self.run_command(['config', 'remote.origin.url', url], cwd=dest)
|
||||
cmd_args = ['checkout', '-q'] + rev_options.to_args()
|
||||
self.run_command(cmd_args, cwd=dest)
|
||||
|
||||
self.update_submodules(dest)
|
||||
|
||||
def update(self, dest, rev_options):
|
||||
# First fetch changes from the default remote
|
||||
if self.get_git_version() >= parse_version('1.9.0'):
|
||||
# fetch tags in addition to everything else
|
||||
self.run_command(['fetch', '-q', '--tags'], cwd=dest)
|
||||
else:
|
||||
self.run_command(['fetch', '-q'], cwd=dest)
|
||||
# Then reset to wanted revision (maybe even origin/master)
|
||||
rev_options = self.check_rev_options(dest, rev_options)
|
||||
cmd_args = ['reset', '--hard', '-q'] + rev_options.to_args()
|
||||
self.run_command(cmd_args, cwd=dest)
|
||||
#: update submodules
|
||||
self.update_submodules(dest)
|
||||
|
||||
def get_url(self, location):
|
||||
"""Return URL of the first remote encountered."""
|
||||
remotes = self.run_command(
|
||||
['config', '--get-regexp', r'remote\..*\.url'],
|
||||
show_stdout=False, cwd=location,
|
||||
)
|
||||
remotes = remotes.splitlines()
|
||||
found_remote = remotes[0]
|
||||
for remote in remotes:
|
||||
if remote.startswith('remote.origin.url '):
|
||||
found_remote = remote
|
||||
break
|
||||
url = found_remote.split(' ')[1]
|
||||
return url.strip()
|
||||
|
||||
def get_revision(self, location):
|
||||
current_rev = self.run_command(
|
||||
['rev-parse', 'HEAD'], show_stdout=False, cwd=location,
|
||||
)
|
||||
return current_rev.strip()
|
||||
|
||||
def _get_subdirectory(self, location):
|
||||
"""Return the relative path of setup.py to the git repo root."""
|
||||
# find the repo root
|
||||
git_dir = self.run_command(['rev-parse', '--git-dir'],
|
||||
show_stdout=False, cwd=location).strip()
|
||||
if not os.path.isabs(git_dir):
|
||||
git_dir = os.path.join(location, git_dir)
|
||||
root_dir = os.path.join(git_dir, '..')
|
||||
# find setup.py
|
||||
orig_location = location
|
||||
while not os.path.exists(os.path.join(location, 'setup.py')):
|
||||
last_location = location
|
||||
location = os.path.dirname(location)
|
||||
if location == last_location:
|
||||
# We've traversed up to the root of the filesystem without
|
||||
# finding setup.py
|
||||
logger.warning(
|
||||
"Could not find setup.py for directory %s (tried all "
|
||||
"parent directories)",
|
||||
orig_location,
|
||||
)
|
||||
return None
|
||||
# relative path of setup.py to repo root
|
||||
if samefile(root_dir, location):
|
||||
return None
|
||||
return os.path.relpath(location, root_dir)
|
||||
|
||||
def get_src_requirement(self, dist, location):
|
||||
repo = self.get_url(location)
|
||||
if not repo.lower().startswith('git:'):
|
||||
repo = 'git+' + repo
|
||||
egg_project_name = dist.egg_name().split('-', 1)[0]
|
||||
if not repo:
|
||||
return None
|
||||
current_rev = self.get_revision(location)
|
||||
req = '%s@%s#egg=%s' % (repo, current_rev, egg_project_name)
|
||||
subdirectory = self._get_subdirectory(location)
|
||||
if subdirectory:
|
||||
req += '&subdirectory=' + subdirectory
|
||||
return req
|
||||
|
||||
def get_url_rev(self, url):
|
||||
"""
|
||||
Prefixes stub URLs like 'user@hostname:user/repo.git' with 'ssh://'.
|
||||
That's required because although they use SSH they sometimes don't
|
||||
work with a ssh:// scheme (e.g. GitHub). But we need a scheme for
|
||||
parsing. Hence we remove it again afterwards and return it as a stub.
|
||||
"""
|
||||
if '://' not in url:
|
||||
assert 'file:' not in url
|
||||
url = url.replace('git+', 'git+ssh://')
|
||||
url, rev = super(Git, self).get_url_rev(url)
|
||||
url = url.replace('ssh://', '')
|
||||
else:
|
||||
url, rev = super(Git, self).get_url_rev(url)
|
||||
|
||||
return url, rev
|
||||
|
||||
def update_submodules(self, location):
|
||||
if not os.path.exists(os.path.join(location, '.gitmodules')):
|
||||
return
|
||||
self.run_command(
|
||||
['submodule', 'update', '--init', '--recursive', '-q'],
|
||||
cwd=location,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def controls_location(cls, location):
|
||||
if super(Git, cls).controls_location(location):
|
||||
return True
|
||||
try:
|
||||
r = cls().run_command(['rev-parse'],
|
||||
cwd=location,
|
||||
show_stdout=False,
|
||||
on_returncode='ignore')
|
||||
return not r
|
||||
except BadCommand:
|
||||
logger.debug("could not determine if %s is under git control "
|
||||
"because git is not available", location)
|
||||
return False
|
||||
|
||||
|
||||
vcs.register(Git)
|
||||
102
env/lib/python3.6/site-packages/pip/_internal/vcs/mercurial.py
vendored
Normal file
102
env/lib/python3.6/site-packages/pip/_internal/vcs/mercurial.py
vendored
Normal file
@@ -0,0 +1,102 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
import logging
|
||||
import os
|
||||
|
||||
from pip._vendor.six.moves import configparser
|
||||
|
||||
from pip._internal.download import path_to_url
|
||||
from pip._internal.utils.misc import display_path
|
||||
from pip._internal.utils.temp_dir import TempDirectory
|
||||
from pip._internal.vcs import VersionControl, vcs
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Mercurial(VersionControl):
|
||||
name = 'hg'
|
||||
dirname = '.hg'
|
||||
repo_name = 'clone'
|
||||
schemes = ('hg', 'hg+http', 'hg+https', 'hg+ssh', 'hg+static-http')
|
||||
|
||||
def get_base_rev_args(self, rev):
|
||||
return [rev]
|
||||
|
||||
def export(self, location):
|
||||
"""Export the Hg repository at the url to the destination location"""
|
||||
with TempDirectory(kind="export") as temp_dir:
|
||||
self.unpack(temp_dir.path)
|
||||
|
||||
self.run_command(
|
||||
['archive', location], show_stdout=False, cwd=temp_dir.path
|
||||
)
|
||||
|
||||
def fetch_new(self, dest, url, rev_options):
|
||||
rev_display = rev_options.to_display()
|
||||
logger.info(
|
||||
'Cloning hg %s%s to %s',
|
||||
url,
|
||||
rev_display,
|
||||
display_path(dest),
|
||||
)
|
||||
self.run_command(['clone', '--noupdate', '-q', url, dest])
|
||||
cmd_args = ['update', '-q'] + rev_options.to_args()
|
||||
self.run_command(cmd_args, cwd=dest)
|
||||
|
||||
def switch(self, dest, url, rev_options):
|
||||
repo_config = os.path.join(dest, self.dirname, 'hgrc')
|
||||
config = configparser.SafeConfigParser()
|
||||
try:
|
||||
config.read(repo_config)
|
||||
config.set('paths', 'default', url)
|
||||
with open(repo_config, 'w') as config_file:
|
||||
config.write(config_file)
|
||||
except (OSError, configparser.NoSectionError) as exc:
|
||||
logger.warning(
|
||||
'Could not switch Mercurial repository to %s: %s', url, exc,
|
||||
)
|
||||
else:
|
||||
cmd_args = ['update', '-q'] + rev_options.to_args()
|
||||
self.run_command(cmd_args, cwd=dest)
|
||||
|
||||
def update(self, dest, rev_options):
|
||||
self.run_command(['pull', '-q'], cwd=dest)
|
||||
cmd_args = ['update', '-q'] + rev_options.to_args()
|
||||
self.run_command(cmd_args, cwd=dest)
|
||||
|
||||
def get_url(self, location):
|
||||
url = self.run_command(
|
||||
['showconfig', 'paths.default'],
|
||||
show_stdout=False, cwd=location).strip()
|
||||
if self._is_local_repository(url):
|
||||
url = path_to_url(url)
|
||||
return url.strip()
|
||||
|
||||
def get_revision(self, location):
|
||||
current_revision = self.run_command(
|
||||
['parents', '--template={rev}'],
|
||||
show_stdout=False, cwd=location).strip()
|
||||
return current_revision
|
||||
|
||||
def get_revision_hash(self, location):
|
||||
current_rev_hash = self.run_command(
|
||||
['parents', '--template={node}'],
|
||||
show_stdout=False, cwd=location).strip()
|
||||
return current_rev_hash
|
||||
|
||||
def get_src_requirement(self, dist, location):
|
||||
repo = self.get_url(location)
|
||||
if not repo.lower().startswith('hg:'):
|
||||
repo = 'hg+' + repo
|
||||
egg_project_name = dist.egg_name().split('-', 1)[0]
|
||||
if not repo:
|
||||
return None
|
||||
current_rev_hash = self.get_revision_hash(location)
|
||||
return '%s@%s#egg=%s' % (repo, current_rev_hash, egg_project_name)
|
||||
|
||||
def is_commit_id_equal(self, dest, name):
|
||||
"""Always assume the versions don't match"""
|
||||
return False
|
||||
|
||||
|
||||
vcs.register(Mercurial)
|
||||
254
env/lib/python3.6/site-packages/pip/_internal/vcs/subversion.py
vendored
Normal file
254
env/lib/python3.6/site-packages/pip/_internal/vcs/subversion.py
vendored
Normal file
@@ -0,0 +1,254 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
|
||||
from pip._vendor.six.moves.urllib import parse as urllib_parse
|
||||
|
||||
from pip._internal.index import Link
|
||||
from pip._internal.utils.logging import indent_log
|
||||
from pip._internal.utils.misc import display_path, remove_auth_from_url, rmtree
|
||||
from pip._internal.vcs import VersionControl, vcs
|
||||
|
||||
_svn_xml_url_re = re.compile('url="([^"]+)"')
|
||||
_svn_rev_re = re.compile(r'committed-rev="(\d+)"')
|
||||
_svn_url_re = re.compile(r'URL: (.+)')
|
||||
_svn_revision_re = re.compile(r'Revision: (.+)')
|
||||
_svn_info_xml_rev_re = re.compile(r'\s*revision="(\d+)"')
|
||||
_svn_info_xml_url_re = re.compile(r'<url>(.*)</url>')
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Subversion(VersionControl):
|
||||
name = 'svn'
|
||||
dirname = '.svn'
|
||||
repo_name = 'checkout'
|
||||
schemes = ('svn', 'svn+ssh', 'svn+http', 'svn+https', 'svn+svn')
|
||||
|
||||
def get_base_rev_args(self, rev):
|
||||
return ['-r', rev]
|
||||
|
||||
def get_info(self, location):
|
||||
"""Returns (url, revision), where both are strings"""
|
||||
assert not location.rstrip('/').endswith(self.dirname), \
|
||||
'Bad directory: %s' % location
|
||||
output = self.run_command(
|
||||
['info', location],
|
||||
show_stdout=False,
|
||||
extra_environ={'LANG': 'C'},
|
||||
)
|
||||
match = _svn_url_re.search(output)
|
||||
if not match:
|
||||
logger.warning(
|
||||
'Cannot determine URL of svn checkout %s',
|
||||
display_path(location),
|
||||
)
|
||||
logger.debug('Output that cannot be parsed: \n%s', output)
|
||||
return None, None
|
||||
url = match.group(1).strip()
|
||||
match = _svn_revision_re.search(output)
|
||||
if not match:
|
||||
logger.warning(
|
||||
'Cannot determine revision of svn checkout %s',
|
||||
display_path(location),
|
||||
)
|
||||
logger.debug('Output that cannot be parsed: \n%s', output)
|
||||
return url, None
|
||||
return url, match.group(1)
|
||||
|
||||
def export(self, location):
|
||||
"""Export the svn repository at the url to the destination location"""
|
||||
url, rev_options = self.get_url_rev_options(self.url)
|
||||
|
||||
logger.info('Exporting svn repository %s to %s', url, location)
|
||||
with indent_log():
|
||||
if os.path.exists(location):
|
||||
# Subversion doesn't like to check out over an existing
|
||||
# directory --force fixes this, but was only added in svn 1.5
|
||||
rmtree(location)
|
||||
cmd_args = ['export'] + rev_options.to_args() + [url, location]
|
||||
self.run_command(cmd_args, show_stdout=False)
|
||||
|
||||
def fetch_new(self, dest, url, rev_options):
|
||||
rev_display = rev_options.to_display()
|
||||
logger.info(
|
||||
'Checking out %s%s to %s',
|
||||
url,
|
||||
rev_display,
|
||||
display_path(dest),
|
||||
)
|
||||
cmd_args = ['checkout', '-q'] + rev_options.to_args() + [url, dest]
|
||||
self.run_command(cmd_args)
|
||||
|
||||
def switch(self, dest, url, rev_options):
|
||||
cmd_args = ['switch'] + rev_options.to_args() + [url, dest]
|
||||
self.run_command(cmd_args)
|
||||
|
||||
def update(self, dest, rev_options):
|
||||
cmd_args = ['update'] + rev_options.to_args() + [dest]
|
||||
self.run_command(cmd_args)
|
||||
|
||||
def get_location(self, dist, dependency_links):
|
||||
for url in dependency_links:
|
||||
egg_fragment = Link(url).egg_fragment
|
||||
if not egg_fragment:
|
||||
continue
|
||||
if '-' in egg_fragment:
|
||||
# FIXME: will this work when a package has - in the name?
|
||||
key = '-'.join(egg_fragment.split('-')[:-1]).lower()
|
||||
else:
|
||||
key = egg_fragment
|
||||
if key == dist.key:
|
||||
return url.split('#', 1)[0]
|
||||
return None
|
||||
|
||||
def get_revision(self, location):
|
||||
"""
|
||||
Return the maximum revision for all files under a given location
|
||||
"""
|
||||
# Note: taken from setuptools.command.egg_info
|
||||
revision = 0
|
||||
|
||||
for base, dirs, files in os.walk(location):
|
||||
if self.dirname not in dirs:
|
||||
dirs[:] = []
|
||||
continue # no sense walking uncontrolled subdirs
|
||||
dirs.remove(self.dirname)
|
||||
entries_fn = os.path.join(base, self.dirname, 'entries')
|
||||
if not os.path.exists(entries_fn):
|
||||
# FIXME: should we warn?
|
||||
continue
|
||||
|
||||
dirurl, localrev = self._get_svn_url_rev(base)
|
||||
|
||||
if base == location:
|
||||
base = dirurl + '/' # save the root url
|
||||
elif not dirurl or not dirurl.startswith(base):
|
||||
dirs[:] = []
|
||||
continue # not part of the same svn tree, skip it
|
||||
revision = max(revision, localrev)
|
||||
return revision
|
||||
|
||||
def get_url_rev(self, url):
|
||||
# hotfix the URL scheme after removing svn+ from svn+ssh:// readd it
|
||||
url, rev = super(Subversion, self).get_url_rev(url)
|
||||
if url.startswith('ssh://'):
|
||||
url = 'svn+' + url
|
||||
return url, rev
|
||||
|
||||
def get_url_rev_args(self, url):
|
||||
extra_args = get_rev_options_args(url)
|
||||
url = remove_auth_from_url(url)
|
||||
|
||||
return url, extra_args
|
||||
|
||||
def get_url(self, location):
|
||||
# In cases where the source is in a subdirectory, not alongside
|
||||
# setup.py we have to look up in the location until we find a real
|
||||
# setup.py
|
||||
orig_location = location
|
||||
while not os.path.exists(os.path.join(location, 'setup.py')):
|
||||
last_location = location
|
||||
location = os.path.dirname(location)
|
||||
if location == last_location:
|
||||
# We've traversed up to the root of the filesystem without
|
||||
# finding setup.py
|
||||
logger.warning(
|
||||
"Could not find setup.py for directory %s (tried all "
|
||||
"parent directories)",
|
||||
orig_location,
|
||||
)
|
||||
return None
|
||||
|
||||
return self._get_svn_url_rev(location)[0]
|
||||
|
||||
def _get_svn_url_rev(self, location):
|
||||
from pip._internal.exceptions import InstallationError
|
||||
|
||||
entries_path = os.path.join(location, self.dirname, 'entries')
|
||||
if os.path.exists(entries_path):
|
||||
with open(entries_path) as f:
|
||||
data = f.read()
|
||||
else: # subversion >= 1.7 does not have the 'entries' file
|
||||
data = ''
|
||||
|
||||
if (data.startswith('8') or
|
||||
data.startswith('9') or
|
||||
data.startswith('10')):
|
||||
data = list(map(str.splitlines, data.split('\n\x0c\n')))
|
||||
del data[0][0] # get rid of the '8'
|
||||
url = data[0][3]
|
||||
revs = [int(d[9]) for d in data if len(d) > 9 and d[9]] + [0]
|
||||
elif data.startswith('<?xml'):
|
||||
match = _svn_xml_url_re.search(data)
|
||||
if not match:
|
||||
raise ValueError('Badly formatted data: %r' % data)
|
||||
url = match.group(1) # get repository URL
|
||||
revs = [int(m.group(1)) for m in _svn_rev_re.finditer(data)] + [0]
|
||||
else:
|
||||
try:
|
||||
# subversion >= 1.7
|
||||
xml = self.run_command(
|
||||
['info', '--xml', location],
|
||||
show_stdout=False,
|
||||
)
|
||||
url = _svn_info_xml_url_re.search(xml).group(1)
|
||||
revs = [
|
||||
int(m.group(1)) for m in _svn_info_xml_rev_re.finditer(xml)
|
||||
]
|
||||
except InstallationError:
|
||||
url, revs = None, []
|
||||
|
||||
if revs:
|
||||
rev = max(revs)
|
||||
else:
|
||||
rev = 0
|
||||
|
||||
return url, rev
|
||||
|
||||
def get_src_requirement(self, dist, location):
|
||||
repo = self.get_url(location)
|
||||
if repo is None:
|
||||
return None
|
||||
# FIXME: why not project name?
|
||||
egg_project_name = dist.egg_name().split('-', 1)[0]
|
||||
rev = self.get_revision(location)
|
||||
return 'svn+%s@%s#egg=%s' % (repo, rev, egg_project_name)
|
||||
|
||||
def is_commit_id_equal(self, dest, name):
|
||||
"""Always assume the versions don't match"""
|
||||
return False
|
||||
|
||||
|
||||
def get_rev_options_args(url):
|
||||
"""
|
||||
Return the extra arguments to pass to RevOptions.
|
||||
"""
|
||||
r = urllib_parse.urlsplit(url)
|
||||
if hasattr(r, 'username'):
|
||||
# >= Python-2.5
|
||||
username, password = r.username, r.password
|
||||
else:
|
||||
netloc = r[1]
|
||||
if '@' in netloc:
|
||||
auth = netloc.split('@')[0]
|
||||
if ':' in auth:
|
||||
username, password = auth.split(':', 1)
|
||||
else:
|
||||
username, password = auth, None
|
||||
else:
|
||||
username, password = None, None
|
||||
|
||||
extra_args = []
|
||||
if username:
|
||||
extra_args += ['--username', username]
|
||||
if password:
|
||||
extra_args += ['--password', password]
|
||||
|
||||
return extra_args
|
||||
|
||||
|
||||
vcs.register(Subversion)
|
||||
Reference in New Issue
Block a user