From 7bdbcb559885bd6bdea027b7270a541f31708431 Mon Sep 17 00:00:00 2001 From: Dori Medini Date: Mon, 22 Jul 2024 16:07:09 +0300 Subject: [PATCH] wip2 Signed-off-by: Dori Medini --- scripts/run_tests.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/scripts/run_tests.py b/scripts/run_tests.py index c2c65c7a9e1..cb53c25143a 100755 --- a/scripts/run_tests.py +++ b/scripts/run_tests.py @@ -8,15 +8,20 @@ from typing import Dict, List, Set, Optional from git import Repo -PATTERN = r"(\w+)\s*v([\d.]*.*)\((.*?)\)" +PATTERN = r"(\w+)\s*v([\d.]*.*)\(([^*]*?)\)( \(\*\))?" + +# Pattern to match the dependency tree output (`cargo tree -i` output). +# First match group is the dependent crate name; second match group is the local path to the +# dependant crate. +# '([a-zA-Z0-9_]+)' is the crate name. +# ' [^(]* ' is anything between the crate name and the path (path is in parens). +# '\(([^)]+)\)' should match the path to the crate. No closing paren in the path. +DEPENDENCY_PATTERN = r"([a-zA-Z0-9_]+) [^(]* \(([^)]+)\)" + def get_workspace_tree() -> Dict[str, str]: tree = dict() - res = ( - subprocess.check_output("cargo tree --depth 0".split()) - .decode("utf-8") - .splitlines() - ) + res = subprocess.check_output("cargo tree --depth 0".split()).decode("utf-8").splitlines() for l in res: m = re.match(PATTERN, l) if m is not None: @@ -48,16 +53,15 @@ def get_modified_packages(files: List[str]) -> Set[str]: return packages - def get_package_dependencies(package_name: str) -> Set[str]: res = ( - subprocess.check_output(f"cargo tree -i {package_name}".split()) + subprocess.check_output(f"cargo tree -i {package_name} --prefix none".split()) .decode("utf-8") .splitlines() ) deps = set() for l in res: - m = re.match(PATTERN, l) + m = re.match(DEPENDENCY_PATTERN, l) if m is not None: deps.add(m.group(1)) return deps @@ -86,15 +90,14 @@ def run_test(changes_only: bool, commit_id: Optional[str], features: Optional[st subprocess.run(cmd, check=True) print("Tests complete.") + def parse_args() -> argparse.Namespace: parser = argparse.ArgumentParser(description="Presubmit script.") parser.add_argument("--changes_only", action="store_true") parser.add_argument( "--features", type=str, help="Which services to deploy. For multi services separate by ','." ) - parser.add_argument( - "--commit_id", type=str, help="GIT commit ID to compare against." - ) + parser.add_argument("--commit_id", type=str, help="GIT commit ID to compare against.") return parser.parse_args()