Skip to content

Commit 0655e51

Browse files
authored
Fix excluded labels check (#213)
1 parent 744af9b commit 0655e51

File tree

6 files changed

+21
-7
lines changed

6 files changed

+21
-7
lines changed

src/common/label.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,9 @@ def __hash__(self):
128128
return hash((self.repository_prefix, self.package_path, self.target))
129129

130130
def __eq__(self, other):
131-
if other is None:
131+
if other is self:
132+
return True
133+
if not isinstance(other, Label):
132134
return False
133135
return (self.repository_prefix == other.repository_prefix and
134136
self.package_path == other.package_path and

src/config/config.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"""
1010

1111

12+
from common import label
1213
from common import logger
1314
from config import exclusions
1415
import configparser
@@ -102,7 +103,8 @@ def __init__(self,
102103

103104
# crawler
104105
self.excluded_dependency_paths = _add_pathsep(_to_tuple(excluded_dependency_paths))
105-
self.excluded_dependency_labels = _to_tuple(excluded_dependency_labels)
106+
# stored as common.label.Label instances
107+
self.excluded_dependency_labels = _to_tuple_of_labels(excluded_dependency_labels)
106108

107109
# artifact
108110
self.excluded_src_relpaths = _add_pathsep(_to_tuple(excluded_src_relpaths))
@@ -181,6 +183,10 @@ def _to_tuple(thing):
181183
raise Exception("Cannot convert to tuple [%s] % thing")
182184

183185

186+
def _to_tuple_of_labels(thing):
187+
return tuple([label.Label(lbl) for lbl in _to_tuple(thing)])
188+
189+
184190
def _to_bool(thing):
185191
if isinstance(thing, bool):
186192
return thing

src/crawl/crawler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ def _partition_and_filter_labels(self, labels):
672672
return source_labels, deps
673673

674674
def _filter_label(self, label):
675-
if label.canonical_form in self.workspace.excluded_dependency_labels:
675+
if label in self.workspace.excluded_dependency_labels:
676676
return None
677677
elif label.is_source_ref:
678678
for excluded_dependency_path in self.workspace.excluded_dependency_paths:

src/crawl/workspace.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,10 @@ def filter_artifact_producing_packages(self, packages):
9494

9595
def _parse_dep_label(self, dep_label):
9696
"""
97-
TODO: this has been move to the crawler class and can be removed.
97+
TODO: this has been moved to the crawler class and can be removed.
9898
"""
99-
if dep_label in self.excluded_dependency_labels:
99+
import common.label
100+
if common.label.Label(dep_label) in self.excluded_dependency_labels:
100101
return None
101102

102103
if dep_label.startswith("@"):

tests/configtest.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
"""
77

8+
import common.label as label
89
from config import config
910
import os
1011
import tempfile
@@ -186,12 +187,13 @@ def test_excluded_labels(self):
186187
self._write_file(repo_root, "src/config/pom_template.xml", "foo")
187188
self._write_file(repo_root, ".pomgenrc", """
188189
[crawler]
189-
excluded_dependency_labels= 123 , 444
190+
excluded_dependency_labels= //a/b/c , //a/b/c:foo
190191
""")
191192

192193
cfg = config.load(repo_root)
193194

194-
self.assertEqual(("123", "444"), cfg.excluded_dependency_labels)
195+
self.assertEqual((label.Label("//a/b/c:c"), label.Label("a/b/c:foo")),
196+
cfg.excluded_dependency_labels)
195197

196198
def test_str(self):
197199
repo_root = tempfile.mkdtemp("root")

tests/labeltest.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ def test_eq(self):
117117
self.assertEqual(n1, n2)
118118
self.assertFalse(n1 != n2)
119119

120+
self.assertNotEqual(label.Label("//foo"), None)
121+
self.assertNotEqual(label.Label("//foo"), "//foo")
122+
120123
def test_trailing_slash(self):
121124
n1 = label.Label("//foo/blah/")
122125
self.assertEqual("blah", n1.target)

0 commit comments

Comments
 (0)