← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~ikoruk/launchpad:upgrade-python-debian into launchpad:master

 

Yuliy Schwartzburg has proposed merging ~ikoruk/launchpad:upgrade-python-debian into launchpad:master.

Commit message:
update python-debian and introduce our own parsing since newer versions of python-debian don't raise errors in parsing

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~ikoruk/launchpad/+git/launchpad/+merge/479848
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~ikoruk/launchpad:upgrade-python-debian into launchpad:master.
diff --git a/lib/lp/soyuz/model/binarypackagebuild.py b/lib/lp/soyuz/model/binarypackagebuild.py
index 4ac614c..fe789be 100644
--- a/lib/lp/soyuz/model/binarypackagebuild.py
+++ b/lib/lp/soyuz/model/binarypackagebuild.py
@@ -651,6 +651,25 @@ class BinaryPackageBuild(PackageBuildMixin, StormBase):
         apt_pkg.init_system()
 
         # Check package build dependencies using debian.deb822
+
+        if self.dependencies is None:
+            raise UnparsableDependencies(
+                "Build dependencies for %s (%s) could not be parsed: '%s'\n"
+                "It indicates that something is wrong in buildd-workers."
+                % (self.title, self.id, self.dependencies)
+            )
+
+        # make sure the relationship is valid of the form name (= version)
+        for rel in self.dependencies.split(","):
+            # check parentheses are closed
+            if rel.count("(") != rel.count(")"):
+                raise UnparsableDependencies(
+                    "Build dependencies for %s (%s) could not be parsed: "
+                    "'%s'\nIt indicates that something is wrong in "
+                    "buildd-workers."
+                    % (self.title, self.id, self.dependencies)
+                )
+
         try:
             with warnings.catch_warnings():
                 warnings.simplefilter("error")
@@ -662,6 +681,27 @@ class BinaryPackageBuild(PackageBuildMixin, StormBase):
                 % (self.title, self.id, self.dependencies)
             )
 
+        # For each dependency check if there is a name (without spaces) and
+        # version. See TestBuildUpdateDependencies.testInvalidDependencies()
+
+        def has_valid_name(dep):
+            return (
+                dep.get("name") is not None
+                and len(dep.get("name", "").split(" ")) == 1
+            )
+
+        def has_valid_version(dep):
+            return dep.get("version") is None or len(dep.get("version")) == 2
+
+        for dep in parsed_deps:
+            if not has_valid_name(dep[0]) or not has_valid_version(dep[0]):
+                raise UnparsableDependencies(
+                    "Build dependencies for %s (%s) could not be parsed: "
+                    "'%s'\nIt indicates that something is wrong in "
+                    "buildd-workers."
+                    % (self.title, self.id, self.dependencies)
+                )
+
         remaining_deps = []
         for or_dep in parsed_deps:
             if not any(self._isDependencySatisfied(token) for token in or_dep):
diff --git a/lib/lp/soyuz/model/binarysourcereference.py b/lib/lp/soyuz/model/binarysourcereference.py
index a65a7f9..38775b2 100644
--- a/lib/lp/soyuz/model/binarysourcereference.py
+++ b/lib/lp/soyuz/model/binarysourcereference.py
@@ -71,6 +71,14 @@ class BinarySourceReferenceSet:
         if not relationship:
             return []
 
+        # make sure the relationship is valid of the form name (= version)
+        for rel in relationship.split(","):
+            # check parentheses are closed
+            if rel.count("(") != rel.count(")"):
+                raise UnparsableBuiltUsing(
+                    "Built-Using must contain strict dependencies: %s" % (rel,)
+                )
+
         try:
             with warnings.catch_warnings():
                 warnings.simplefilter("error")
diff --git a/lib/lp/soyuz/tests/test_binarysourcereference.py b/lib/lp/soyuz/tests/test_binarysourcereference.py
index 4b50b7c..3b9b23f 100644
--- a/lib/lp/soyuz/tests/test_binarysourcereference.py
+++ b/lib/lp/soyuz/tests/test_binarysourcereference.py
@@ -37,9 +37,7 @@ class TestBinarySourceReference(TestCaseWithFactory):
 
     def test_createFromRelationship_nonsense(self):
         bpr = self.factory.makeBinaryPackageRelease()
-        expected_message = (
-            r"Invalid Built-Using field; cannot be parsed by deb822: .*"
-        )
+        expected_message = r"Built-Using must contain strict dependencies: .*"
         with ExpectedException(UnparsableBuiltUsing, expected_message):
             self.reference_set.createFromRelationship(
                 bpr, "nonsense (", BinarySourceReferenceType.BUILT_USING
diff --git a/requirements/launchpad.txt b/requirements/launchpad.txt
index 11bdb51..57fca91 100644
--- a/requirements/launchpad.txt
+++ b/requirements/launchpad.txt
@@ -142,7 +142,7 @@ pyOpenSSL==17.5.0
 pyparsing==3.1.4
 pystache==0.6.6
 python-dateutil==2.9.0.post0
-python-debian==0.1.32
+python-debian==0.1.49
 python-keystoneclient==3.21.0
 python3-openid==3.2
 python-swiftclient==4.6.0