pip/src/pip/_internal/vcs/bazaar.py

102 lines
3.1 KiB
Python
Raw Normal View History

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.vcs import VersionControl, vcs
2017-05-16 12:16:30 +02:00
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',
)
Fix launchpad urls Fixes issue #36 by supporting launchpad urls. Functionally tested python pip/runner.py install -e bzr+lp:ijson#egg=ijson Obtaining ijson from bzr+lp:ijson#egg=ijson Checking out lp:ijson to ./src/ijson You have not informed bzr of your Launchpad ID, and you must do this to write to Launchpad or access private data. See "bzr help launchpad-login". Running setup.py egg_info for package ijson Installing collected packages: ijson Running setup.py develop for ijson install_dir /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/ Creating /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/ijson.egg-link (link to .) Adding ijson 0.8.0 to easy-install.pth file error: /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/easy-install.pth: Permission denied Complete output from command /Library/Frameworks/Python.framework/Versions/2.6/Resources/Python.app/Contents/MacOS/Python -c "import setuptools; __file__='/Users/pnasrat/Development/pip/src/ijson/setup.py'; exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" develop --no-deps: running develop install_dir /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/ running egg_info writing ijson.egg-info/PKG-INFO writing top-level names to ijson.egg-info/top_level.txt writing dependency_links to ijson.egg-info/dependency_links.txt warning: manifest_maker: standard file '-c' not found reading manifest file 'ijson.egg-info/SOURCES.txt' reading manifest template 'MANIFEST.in' writing manifest file 'ijson.egg-info/SOURCES.txt' running build_ext Creating /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/ijson.egg-link (link to .) Adding ijson 0.8.0 to easy-install.pth file
2011-04-15 18:56:57 +02:00
def __init__(self, url=None, *args, **kwargs):
super(Bazaar, self).__init__(url, *args, **kwargs)
# This is only needed for python <2.7.5
2012-07-01 12:47:23 +02:00
# 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'])
Fix launchpad urls Fixes issue #36 by supporting launchpad urls. Functionally tested python pip/runner.py install -e bzr+lp:ijson#egg=ijson Obtaining ijson from bzr+lp:ijson#egg=ijson Checking out lp:ijson to ./src/ijson You have not informed bzr of your Launchpad ID, and you must do this to write to Launchpad or access private data. See "bzr help launchpad-login". Running setup.py egg_info for package ijson Installing collected packages: ijson Running setup.py develop for ijson install_dir /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/ Creating /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/ijson.egg-link (link to .) Adding ijson 0.8.0 to easy-install.pth file error: /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/easy-install.pth: Permission denied Complete output from command /Library/Frameworks/Python.framework/Versions/2.6/Resources/Python.app/Contents/MacOS/Python -c "import setuptools; __file__='/Users/pnasrat/Development/pip/src/ijson/setup.py'; exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" develop --no-deps: running develop install_dir /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/ running egg_info writing ijson.egg-info/PKG-INFO writing top-level names to ijson.egg-info/top_level.txt writing dependency_links to ijson.egg-info/dependency_links.txt warning: manifest_maker: standard file '-c' not found reading manifest file 'ijson.egg-info/SOURCES.txt' reading manifest template 'MANIFEST.in' writing manifest file 'ijson.egg-info/SOURCES.txt' running build_ext Creating /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/ijson.egg-link (link to .) Adding ijson 0.8.0 to easy-install.pth file
2011-04-15 18:56:57 +02:00
@staticmethod
def get_base_rev_args(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)
url, rev_options = self.get_url_rev_options(self.url)
self.run_command(
['export', location, url] + rev_options.to_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 = ['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, url, rev_options):
cmd_args = ['pull', '-q'] + rev_options.to_args()
self.run_command(cmd_args, cwd=dest)
@classmethod
def get_url_rev_and_auth(cls, url):
# hotfix the URL scheme after removing bzr+ from bzr+ssh:// readd it
url, rev, user_pass = super(Bazaar, cls).get_url_rev_and_auth(url)
if url.startswith('ssh://'):
url = 'bzr+' + url
return url, rev, user_pass
2019-01-07 01:31:06 +01:00
@classmethod
def get_remote_url(cls, location):
urls = cls.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]
2019-01-07 01:31:06 +01:00
if cls._is_local_repository(repo):
return path_to_url(repo)
return repo
return None
@classmethod
def get_revision(cls, location):
revision = cls.run_command(
['revno'], show_stdout=False, cwd=location,
)
return revision.splitlines()[-1]
2017-10-03 10:21:55 +02:00
def is_commit_id_equal(self, dest, name):
Only update VCS when things have actually changed This saves a network hop when using git and passing an explicit sha as a ref by comparing the version that's already checked out. Yields a ~4x speedup on my local machine Before: ``` $ /usr/local/bin/pip --version pip 7.1.0 from /usr/local/lib/python2.7/site-packages (python 2.7) $ time /usr/local/bin/pip install --disable-pip-version-check -e git+https://github.com/getsentry/raven-python.git@56fc6f7beecf445843d0ec7052bb8c6f0ea80a2e#egg=raven_dev Obtaining raven-dev from git+https://github.com/getsentry/raven-python.git@56fc6f7beecf445843d0ec7052bb8c6f0ea80a2e#egg=raven_dev Updating ./src/raven-dev clone (to 56fc6f7beecf445843d0ec7052bb8c6f0ea80a2e) Could not find a tag or branch '56fc6f7beecf445843d0ec7052bb8c6f0ea80a2e', assuming commit. Installing collected packages: raven-dev Running setup.py develop for raven-dev Successfully installed raven-dev /usr/local/bin/pip install --disable-pip-version-check -e 0.84s user 0.48s system 39% cpu 3.300 total ``` After: ``` $ /Users/matt/.virtualenvs/pip/bin/pip --version pip 7.2.0.dev0 from /Users/matt/code/pip (python 2.7) $ time /Users/matt/.virtualenvs/pip/bin/pip install --disable-pip-version-check -e git+https://github.com/getsentry/raven-python.git@56fc6f7beecf445843d0ec7052bb8c6f0ea80a2e#egg=raven_dev Obtaining raven-dev from git+https://github.com/getsentry/raven-python.git@56fc6f7beecf445843d0ec7052bb8c6f0ea80a2e#egg=raven_dev checking version Skipping because already up-to-date. Installing collected packages: raven-dev Running setup.py develop for raven-dev Successfully installed raven-dev /Users/matt/.virtualenvs/pip/bin/pip install --disable-pip-version-check -e 0.59s user 0.22s system 98% cpu 0.824 total ```
2015-08-31 22:52:01 +02:00
"""Always assume the versions don't match"""
return False
vcs.register(Bazaar)