From bbc7c1dcd16ee21dd35dbacd06ddd1b6731b67d9 Mon Sep 17 00:00:00 2001 From: Simon Toens Date: Sat, 23 Mar 2024 19:05:43 +0900 Subject: [PATCH] Support exact match syntax for package exclusions --- common/argsupport.py | 7 ++++++- tests/argsupporttest.py | 21 +++++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/common/argsupport.py b/common/argsupport.py index acec977..d3eba34 100644 --- a/common/argsupport.py +++ b/common/argsupport.py @@ -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) diff --git a/tests/argsupporttest.py b/tests/argsupporttest.py index 7e5a404..53d3deb 100644 --- a/tests/argsupporttest.py +++ b/tests/argsupporttest.py @@ -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, @@ -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()