← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~abentley/bzr-builder/lp-update into lp:~launchpad-pqm/bzr-builder/trunk

 

Aaron Bentley has proposed merging lp:~abentley/bzr-builder/lp-update into lp:~launchpad-pqm/bzr-builder/trunk.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)


Update bzr-builder to tip (0.6)
-- 
https://code.launchpad.net/~abentley/bzr-builder/lp-update/+merge/39372
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~abentley/bzr-builder/lp-update into lp:~launchpad-pqm/bzr-builder/trunk.
=== modified file 'recipe.py'
--- recipe.py	2010-08-31 20:06:24 +0000
+++ recipe.py	2010-10-26 14:04:47 +0000
@@ -452,6 +452,8 @@
     branch should be merged instead of nested.
     """
 
+    can_have_children = False
+
     def __init__(self, recipe_branch, nest_path=None):
         self.recipe_branch = recipe_branch
         self.nest_path = nest_path
@@ -462,6 +464,15 @@
     def as_tuple(self):
         return (self.recipe_branch, self.nest_path)
 
+    def _get_revid_part(self):
+        if self.recipe_branch.revid is not None:
+            revid_part = " revid:%s" % self.recipe_branch.revid
+        elif self.recipe_branch.revspec is not None:
+            revid_part = " %s" % self.recipe_branch.revspec
+        else:
+            revid_part = ""
+        return revid_part
+
 
 class CommandInstruction(ChildBranch):
 
@@ -474,6 +485,9 @@
         if proc.returncode != 0:
             raise CommandFailedError(self.nest_path)
 
+    def as_text(self):
+        return "%s %s" % (RUN_INSTRUCTION, self.nest_path)
+
 
 class MergeInstruction(ChildBranch):
 
@@ -486,6 +500,12 @@
         merge_branch(self.recipe_branch, tree_to, br_to,
                 possible_transports=possible_transports)
 
+    def as_text(self):
+        revid_part = self._get_revid_part()
+        return "%s %s %s%s" % (
+            MERGE_INSTRUCTION, self.recipe_branch.name,
+            self.recipe_branch.url, revid_part)
+
 
 class NestPartInstruction(ChildBranch):
 
@@ -498,14 +518,33 @@
         nest_part_branch(self.recipe_branch, tree_to, br_to, self.subpath,
             self.target_subdir)
 
+    def as_text(self):
+        revid_part = self._get_revid_part()
+        if self.target_subdir is not None:
+            target_revid_part = " %s%s" % (
+                self.target_subdir, revid_part)
+        else:
+            target_revid_part = revid_part
+        return "%s %s %s %s%s" % (
+            NEST_PART_INSTRUCTION, self.recipe_branch.name,
+            self.recipe_branch.url, self.subpath, target_revid_part)
+
 
 class NestInstruction(ChildBranch):
 
+    can_have_children = True
+
     def apply(self, target_path, tree_to, br_to, possible_transports=None):
         _build_inner_tree(self.recipe_branch,
             target_path=os.path.join(target_path, self.nest_path),
             possible_transports=possible_transports)
 
+    def as_text(self):
+        revid_part = self._get_revid_part()
+        return "%s %s %s %s%s" % (
+            NEST_INSTRUCTION, self.recipe_branch.name,
+            self.recipe_branch.url, self.nest_path, revid_part)
+
 
 class RecipeBranch(object):
     """A nested structure that represents a Recipe.
@@ -680,35 +719,22 @@
     def _add_child_branches_to_manifest(self, child_branches, indent_level):
         manifest = ""
         for instruction in child_branches:
-            child_branch = instruction.recipe_branch
-            nest_location = instruction.nest_path
-            if child_branch is None:
-                manifest += "%s%s %s\n" % ("  " * indent_level, RUN_INSTRUCTION,
-                        nest_location)
-            else:
-                if child_branch.revid is not None:
-                    revid_part = " revid:%s" % child_branch.revid
-                elif child_branch.revspec is not None:
-                    revid_part = " %s" % child_branch.revspec
-                else:
-                    revid_part = ""
-                if nest_location is not None:
-                    manifest += "%s%s %s %s %s%s\n" % \
-                                 ("  " * indent_level, NEST_INSTRUCTION,
-                                  child_branch.name,
-                                  child_branch.url, nest_location,
-                                  revid_part)
-                    manifest += self._add_child_branches_to_manifest(
-                            child_branch.child_branches, indent_level+1)
-                else:
-                    manifest += "%s%s %s %s%s\n" % \
-                                 ("  " * indent_level, MERGE_INSTRUCTION,
-                                  child_branch.name,
-                                  child_branch.url, revid_part)
+            manifest += "%s%s\n" % (
+                "  " * indent_level, instruction.as_text())
+            if instruction.can_have_children:
+                manifest += self._add_child_branches_to_manifest(
+                    instruction.recipe_branch.child_branches,
+                    indent_level+1)
         return manifest
 
 
     def __str__(self):
+        return self.get_recipe_text(validate=True)
+
+    def list_branch_names(self):
+        return self._list_child_names()
+
+    def get_recipe_text(self, validate=False):
         manifest = "# bzr-builder format %s deb-version " % str(self.format)
         # TODO: should we store the expanded version that was used?
         manifest += "%s\n" % (self.deb_version,)
@@ -720,15 +746,13 @@
             manifest += "%s\n" % (self.url,)
         manifest += self._add_child_branches_to_manifest(self.child_branches,
                 0)
-        # Sanity check.
-        # TODO: write a function that compares the result of this parse with
-        # the branch that we built it from.
-        RecipeParser(manifest).parse()
+        if validate:
+            # Sanity check.
+            # TODO: write a function that compares the result of this parse with
+            # the branch that we built it from.
+            RecipeParser(manifest).parse()
         return manifest
 
-    def list_branch_names(self):
-        return self._list_child_names()
-
 
 class RecipeParseError(errors.BzrError):
     _fmt = "Error parsing %(filename)s:%(line)s:%(char)s: %(problem)s."

=== modified file 'setup.py'
--- setup.py	2010-08-16 20:08:01 +0000
+++ setup.py	2010-10-26 14:04:47 +0000
@@ -4,7 +4,7 @@
 
 if __name__ == '__main__':
     setup(name="bzr-builder",
-          version="0.4",
+          version="0.6",
           description="Turn a recipe in to a bzr branch",
           author="James Westby",
           author_email="james.westby@xxxxxxxxxxxxx",

=== modified file 'tests/test_recipe.py'
--- tests/test_recipe.py	2010-08-26 14:34:55 +0000
+++ tests/test_recipe.py	2010-10-26 14:04:47 +0000
@@ -1040,6 +1040,53 @@
                 "  nest nested2 nested2_url nested2\n"
                 "merge merged merged_url\n", manifest)
 
+    def test_get_recipe_text(self):
+        base_branch = BaseRecipeBranch("base_url", "1", 0.1)
+        base_branch.revid = "base_revid"
+        manifest = base_branch.get_recipe_text()
+        self.assertEqual("# bzr-builder format 0.1 deb-version 1\n"
+                "base_url revid:base_revid\n", manifest)
+
+    def test_get_recipe_doesnt_raise_on_invalid_recipe(self):
+        base_branch = BaseRecipeBranch("base_url", "1", 0.1)
+        base_branch.revid = "base_revid"
+        nested_branch1 = RecipeBranch("nested1", "nested1_url",
+                revspec="tag:foo")
+        base_branch.nest_branch(".", nested_branch1)
+        manifest = base_branch.get_recipe_text()
+        self.assertEqual("# bzr-builder format 0.1 deb-version 1\n"
+                "base_url revid:base_revid\n"
+                "nest nested1 nested1_url . tag:foo\n", manifest)
+
+    def test_get_recipe_text_validate_True(self):
+        base_branch = BaseRecipeBranch("base_url", "1", 0.1)
+        base_branch.revid = "base_revid"
+        nested_branch1 = RecipeBranch("nested1", "nested1_url",
+                revspec="tag:foo")
+        base_branch.nest_branch(".", nested_branch1)
+        self.assertRaises(RecipeParseError, base_branch.get_recipe_text,
+                validate=True)
+
+    def test_str_validates(self):
+        base_branch = BaseRecipeBranch("base_url", "1", 0.1)
+        base_branch.revid = "base_revid"
+        nested_branch1 = RecipeBranch("nested1", "nested1_url",
+                revspec="tag:foo")
+        base_branch.nest_branch(".", nested_branch1)
+        self.assertRaises(RecipeParseError, str, base_branch)
+
+    def test_with_nest_part(self):
+        base_branch = BaseRecipeBranch("base_url", "1", 0.1)
+        base_branch.revid = "base_revid"
+        nested_branch1 = RecipeBranch("nested1", "nested1_url",
+                revspec="tag:foo")
+        base_branch.nest_part_branch(nested_branch1, "foo", "bar")
+        manifest = base_branch.get_recipe_text()
+        self.assertEqual("# bzr-builder format 0.1 deb-version 1\n"
+                "base_url revid:base_revid\n"
+                "nest-part nested1 nested1_url foo bar tag:foo\n",
+                manifest)
+
 
 class RecipeBranchTests(TestCaseInTempDir):