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 7bdbcb5
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions scripts/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()


Expand Down

0 comments on commit 7bdbcb5

Please sign in to comment.