Skip to content

Commit

Permalink
Support exact match syntax for package exclusions
Browse files Browse the repository at this point in the history
  • Loading branch information
simontoens committed Mar 23, 2024
1 parent c45c98f commit bbc7c1d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
7 changes: 6 additions & 1 deletion common/argsupport.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,13 @@ def get_all_packages(repository_root_path, packages_str, verbose=False):
packages = bazel.query_all_artifact_packages(repository_root_path, p, verbose)
for package in packages:
for exclusion_path in exclusion_paths:
prefix_match = True
if exclusion_path.endswith("/"):
exclusion_path = exclusion_path[:-1]
prefix_match = False
if package.startswith(exclusion_path):
break
if prefix_match or package.endswith(exclusion_path):
break
else:
if not package in all_packages:
all_packages.add(package)
Expand Down
21 changes: 19 additions & 2 deletions tests/argsupporttest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@
from crawl import bazel
import unittest


PASTRY_PACKAGES = ["projects/libs/pastry/abstractions",
"projects/libs/pastry/pastry-metrics",]
"projects/libs/pastry/pastry-metrics",]


ZK_CONNECT_PACKAGES = ["projects/libs/servicelibs/zk-connect",]


GRAIL_PACKAGES = ["projects/libs/servicelibs/grail/grail-admin-api",
"projects/libs/servicelibs/grail/grail-admin-impl",]


ALL_PACKAGES_DICT = {"projects/libs" : PASTRY_PACKAGES + ZK_CONNECT_PACKAGES + GRAIL_PACKAGES,
"projects/libs/servicelibs" : ZK_CONNECT_PACKAGES + GRAIL_PACKAGES,
"projects/libs/pastry" : PASTRY_PACKAGES,
Expand Down Expand Up @@ -108,6 +112,19 @@ def test_get_all_packages__multiple_packages__multiple_exclusions(self):
self.assertNotIn("projects/libs/servicelibs/grail/grail-admin-api", packages)
self.assertNotIn("projects/libs/servicelibs/grail/grail-admin-impl", packages)
self.assertNotIn("projects/libs/servicelibs/zk-connect", packages)



def test_exact_match_exclusions(self):
packages_str = "projects/libs,-projects/libs/servicelibs/zk,-projects/libs/servicelibs/grail/grail-admin-api/, -projects/libs/servicelibs/grail/"

packages = argsupport.get_all_packages("root", packages_str)

self.assertIn("projects/libs/pastry/abstractions", packages)
self.assertIn("projects/libs/pastry/pastry-metrics", packages)
self.assertNotIn("projects/libs/servicelibs/grail/grail-admin-api", packages)
self.assertIn("projects/libs/servicelibs/grail/grail-admin-impl", packages)
self.assertNotIn("projects/libs/servicelibs/zk-connect", packages)


if __name__ == '__main__':
unittest.main()

0 comments on commit bbc7c1d

Please sign in to comment.