pip/pip/vcs/bazaar.py

121 lines
4.2 KiB
Python
Raw Normal View History

import os
import tempfile
import re
from pip.compat import urlparse
from pip.log import logger
from pip.util import rmtree, display_path, call_subprocess
from pip.vcs import vcs, VersionControl
from pip.download import path_to_url
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)
# Python >= 2.7.4, 3.3 doesn't have uses_fragment or non_hierarchical
2012-07-01 12:47:23 +02:00
# Register lp but do not expose as a scheme to support bzr+lp.
if getattr(urlparse, 'uses_fragment', None):
2012-07-01 12:47:23 +02:00
urlparse.uses_fragment.extend(['lp'])
urlparse.non_hierarchical.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
def export(self, location):
"""
Export the Bazaar repository at the url to the destination location
"""
temp_dir = tempfile.mkdtemp('-export', 'pip-')
self.unpack(temp_dir)
if os.path.exists(location):
# Remove the location to make sure Bazaar can export it correctly
rmtree(location)
try:
call_subprocess([self.cmd, 'export', location], cwd=temp_dir,
filter_stdout=self._filter, show_stdout=False)
finally:
rmtree(temp_dir)
def switch(self, dest, url, rev_options):
call_subprocess([self.cmd, 'switch', url], cwd=dest)
def update(self, dest, rev_options):
call_subprocess(
[self.cmd, 'pull', '-q'] + rev_options, cwd=dest)
def obtain(self, dest):
url, rev = self.get_url_rev()
if rev:
rev_options = ['-r', rev]
rev_display = ' (to revision %s)' % rev
else:
rev_options = []
rev_display = ''
if self.check_destination(dest, url, rev_options, rev_display):
logger.notify('Checking out %s%s to %s'
% (url, rev_display, display_path(dest)))
call_subprocess(
[self.cmd, 'branch', '-q'] + rev_options + [url, dest])
def get_url_rev(self):
# hotfix the URL scheme after removing bzr+ from bzr+ssh:// readd it
url, rev = super(Bazaar, self).get_url_rev()
if url.startswith('ssh://'):
url = 'bzr+' + url
return url, rev
def get_url(self, location):
urls = call_subprocess(
[self.cmd, '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 = call_subprocess(
[self.cmd, 'revno'], show_stdout=False, cwd=location)
return revision.splitlines()[-1]
def get_tag_revs(self, location):
tags = call_subprocess(
[self.cmd, 'tags'], show_stdout=False, cwd=location)
tag_revs = []
for line in tags.splitlines():
tags_match = re.search(r'([.\w-]+)\s*(.*)$', line)
if tags_match:
tag = tags_match.group(1)
rev = tags_match.group(2)
tag_revs.append((rev.strip(), tag.strip()))
return dict(tag_revs)
def get_src_requirement(self, dist, location, find_tags):
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)
tag_revs = self.get_tag_revs(location)
if current_rev in tag_revs:
# It's a tag
full_egg_name = '%s-%s' % (egg_project_name, tag_revs[current_rev])
else:
full_egg_name = '%s-dev_r%s' % (dist.egg_name(), current_rev)
return '%s@%s#egg=%s' % (repo, current_rev, full_egg_name)
vcs.register(Bazaar)