Commits

Jannis Leidel  committed 98d87b4

Removed dependency to bzrlib and added tests for Bazaar support.

  • Participants
  • Parent commits b0421dd
  • Branches trunk

Comments (0)

Files changed (4)

 # use glob syntax.
 syntax: glob
-tests/test-scratch/*
+tests/test-scratch/*
+testenv
             dest='editables',
             action='append',
             default=[],
-            metavar='(svn|git|hg)+REPOS_URL[@REV]#egg=PACKAGE',
+            metavar='(svn|git|hg|bzr)+REPOS_URL[@REV]#egg=PACKAGE',
             help='Install a package directly from a checkout.  Source will be checked '
             'out into src/PACKAGE (lower-case) and installed in-place (using '
             'setup.py develop).  You can run this on an existing directory/checkout (like '
         comments = []
         if (os.path.exists(os.path.join(location, '.svn')) or
             os.path.exists(os.path.join(location, '.git')) or
-            os.path.exists(os.path.join(location, '.hg'))):
+            os.path.exists(os.path.join(location, '.hg')) or
+            os.path.exists(os.path.join(location, '.bzr'))):
             editable = True
             req = get_src_requirement(dist, location, find_tags)
             if req is None:
         return current_rev.strip()
 
     def get_tag_revs(self, location):
-        tags = call_subprocess(['hg', 'tags'], show_stdout=False, cwd=location)
+        tags = call_subprocess(
+            ['hg', 'tags'], show_stdout=False, cwd=location)
         tag_revs = []
         for line in tags.splitlines():
             tags_match = re.search(r'([\w-]+)\s*([\d]+):.*$', line)
     guide = ('# This was a Bazaar repo; to make it a repo again run:\n'
              'bzr checkout -r %(rev)s %(url)s .\n')
 
-    def __init__(self, *args, **kwargs):
-        try:
-            from bzrlib.branch import Branch
-        except ImportError, e:
-            logger.fatal("bzrlib could not be imported")
-            raise InstallationError('You must have Bazaar installed')
-        super(Bazaar, self).__init__(*args, **kwargs)
-
-    def get_branch(self, location):
-        try:
-            from bzrlib.branch import Branch
-        except ImportError, e:
-            logger.fatal("bzrlib could not be imported")
-        return Branch.open(location)
-
     def get_info(self, location):
         """Returns (url, revision), where both are strings"""
         assert not location.rstrip('/').endswith('.bzr'), 'Bad directory: %s' % location
             rev_options = ['-r', rev]
             rev_display = ' (to revision %s)' % rev
         else:
-            rev_options = ['default']
+            rev_options = []
             rev_display = ''
         checkout = True
         if os.path.exists(os.path.join(dest, '.bzr')):
                 ['bzr', 'checkout', '-q'] + rev_options + [url, dest])
 
     def get_url(self, location):
-        branch = self.get_branch(location)
-        if branch.get_parent():
-            # This is a branch
-            return branch.get_parent()
-        master_branch = branch.get_master_branch()
-        if master_branch:
-            # This is a checkout
-            return master_branch.get_parent()
+        urls = call_subprocess(
+            ['bzr', 'info'], show_stdout=False, cwd=location)
+        for line in urls.splitlines():
+            line = line.strip()
+            for x in ('checkout of branch: ',
+                      'repository branch: ',
+                      'parent branch: '):
+                if line.startswith(x):
+                    return line.split(x)[1]
         return None
 
     def get_revision(self, location):
-        branch = self.get_branch(location)
-        if branch.last_revision():
-            return branch.last_revision().strip()
-        return None
+        revision = call_subprocess(
+            ['bzr', 'revno'], show_stdout=False, cwd=location)
+        return revision.strip()
 
     def get_newest_revision(self, location):
         url = self.get_url(location)
-        match = re.search(r'([.\w-]+)\s*(.*)$', url)
-        if match:
-            return match.group(1).strip()
-        return None
+        revision = call_subprocess(
+            ['bzr', 'revno', url], show_stdout=False, cwd=location)
+        return revision.strip()
 
     def get_tag_revs(self, location):
         tags = call_subprocess(
                 tag_revs.append((rev.strip(), tag.strip()))
         return dict(tag_revs)
 
-    def get_revision(self, location):
-        current_branch = call_subprocess(
-            ['bzr', 'revno'], show_stdout=False, cwd=location).strip()
-        branch_revs = self.get_branch_revs(location)
-        for branch in branch_revs:
-            if current_branch == branch_revs[branch]:
-                return branch
-        return self.get_tip_revision(location)
-
     def get_src_requirement(self, dist, location, find_tags):
         repo = self.get_url(location)
         if not repo.lower().startswith('bzr:'):

File tests/test_basic.txt

     >>> assert (lib_py + 'site-packages/easy-install.pth') in result.files_updated
     >>> assert 'src/django-registration' in result.files_created
     >>> assert 'src/django-registration/.hg' in result.files_created
+
+Checking out from Bazaar::
+
+    >>> reset_env()
+    >>> result = run_pip('install', '-e', 'bzr+http://bazaar.launchpad.net/%7Ejezdez/pip-test/test/#egg=pip-test', expect_error=True)
+    >>> egg_link = result.files_created[lib_py + 'site-packages/pip-test.egg-link']
+    >>> # FIXME: I don't understand why there's a trailing . here:
+    >>> egg_link.bytes
+    '.../test-scratch/src/pip-test\n.'
+    >>> assert (lib_py + 'site-packages/easy-install.pth') in result.files_updated
+    >>> assert 'src/pip-test' in result.files_created
+    >>> assert 'src/pip-test/.bzr' in result.files_created

File tests/test_freeze.txt

     -e hg+http://bitbucket.org/mitsuhiko/pygments-main/@...#egg=Pygments-...
     ...
     <BLANKLINE>
+
+Heck, now look in the Bazaar:
+
+    >>> reset_env()
+    >>> env = get_env()
+    >>> result = env.run('bzr', 'checkout', '-r', '2', 'http://bazaar.launchpad.net/%7Ejezdez/pip-test/test/', 'pip-test')
+    >>> result = env.run(os.path.join(env.base_path, 'bin/python'), 'setup.py', 'develop',
+    ...                  cwd=os.path.join(env.base_path, 'pip-test'))
+    >>> result = run_pip('freeze', expect_stderr=True)
+    >>> print result
+    Script result: ...ython... ../../pip.py -E .../test-scratch freeze
+    -- stdout: --------------------
+    -e bzr+http://bazaar.launchpad.net/%7Ejezdez/pip-test/test/@...#egg=pip_test-...
+    ...
+    <BLANKLINE>
+
+    >>> result = run_pip('freeze', '-f', 'bzr+http://bazaar.launchpad.net/%7Ejezdez/pip-test/test/#egg=pip_test', expect_stderr=True)
+    >>> print result
+    Script result: ...ython... ../../pip.py -E .../test-scratch freeze -f bzr+http://bazaar.launchpad.net/%7Ejezdez/pip-test/test/#egg=pip_test
+    -- stdout: --------------------
+    -f bzr+http://bazaar.launchpad.net/%7Ejezdez/pip-test/test/#egg=pip_test
+    -e bzr+http://bazaar.launchpad.net/%7Ejezdez/pip-test/test/@...#egg=pip_test-...
+    ...
+    <BLANKLINE>