Skip to content

Commit

Permalink
wip2
Browse files Browse the repository at this point in the history
Signed-off-by: Dori Medini <dori@starkware.co>
  • Loading branch information
dorimedini-starkware committed Jul 22, 2024
1 parent f553d35 commit 355310a
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions scripts/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,21 @@
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.
# '- ' is a prefix of each interesting line in the output.
# '([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:
Expand All @@ -40,6 +46,8 @@ def get_local_changes(repo_path, commit_id: Optional[str]) -> List[str]:

def get_modified_packages(files: List[str]) -> Set[str]:
tree = get_workspace_tree()
print(f"DORI: {files=}", flush=True)
print(f"DORI: {tree=}", flush=True)
packages = set()
for file in files:
for p_name, p_path in tree.items():
Expand All @@ -48,18 +56,19 @@ 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())
.decode("utf-8")
.splitlines()
)
print(f"DORI: {res=}", flush=True)
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))
print(f"DORI: {deps=}", flush=True)
return deps


Expand All @@ -86,15 +95,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()


Expand Down

0 comments on commit 355310a

Please sign in to comment.