Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
212 changes: 0 additions & 212 deletions .aitk/scripts/auto_formatter.py

This file was deleted.

3 changes: 1 addition & 2 deletions .aitk/scripts/bump_model_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from sanitize.utils import iter_aitk_info_yml


VERSION_LINE_RE = re.compile(r"^(?P<indent>\s*)version:\s*(?P<value>\d+)\s*(?P<comment>#.*)?$")


Expand Down Expand Up @@ -72,7 +71,7 @@ def bump_file(yml_file: Path, yaml_object: dict, delta: int, dry_run: bool) -> O
print(f"Skip {yml_file}: could not locate 'version: {old}' line under aitk.modelInfo")
return None
m = VERSION_LINE_RE.match(lines[idx].rstrip("\n"))
newline = lines[idx][len(lines[idx].rstrip("\r\n")):] or "\n"
newline = lines[idx][len(lines[idx].rstrip("\r\n")) :] or "\n"
indent = m.group("indent")
comment = m.group("comment")
rebuilt = f"{indent}version: {new}"
Expand Down
2 changes: 1 addition & 1 deletion .aitk/scripts/install_freeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def main():

# Install
print(f"Installing dependencies: {temp_req}")
result = subprocess.run(["uv", "pip", "install", "-r", temp_req, "-p", args.python], text=True)
subprocess.run(["uv", "pip", "install", "-r", temp_req, "-p", args.python], text=True)

# Get freeze
pip_freeze = subprocess.check_output(["uv", "pip", "freeze", "-p", args.python]).decode("utf-8").splitlines()
Expand Down
13 changes: 6 additions & 7 deletions .aitk/scripts/project_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
from sanitize.model_info import ModelInfo, ModelList
from sanitize.project_config import ModelInfoProject, ModelProjectConfig, WorkflowItem
from sanitize.utils import (
GlobalVars,
WINML_COPY_EXEMPT_IDS,
GlobalVars,
isLLM_by_id,
iter_aitk_info_yml,
open_ex,
winml_copy_src_for,
)


def fetch_pipeline_tags(model_link: str) -> Optional[List[str]]:
"""Fetch pipeline_tag from HuggingFace API for a given model link.

Expand All @@ -32,7 +33,7 @@ def fetch_pipeline_tags(model_link: str) -> Optional[List[str]]:
hf_prefix = "https://huggingface.co/"
if not model_link.startswith(hf_prefix):
return None
model_id = model_link[len(hf_prefix):].rstrip("/")
model_id = model_link[len(hf_prefix) :].rstrip("/")
if not model_id:
return None
url = f"https://huggingface.co/api/models/{model_id}"
Expand Down Expand Up @@ -93,7 +94,7 @@ def write_list(
root_dir: Path,
md_path: Path,
):
modelList.sort(key=lambda x: (x.modelName))
modelList.sort(key=lambda x: x.modelName)
f.write(f"## {title}\n\n")
f.write("| Model Name | Supported Runtimes |\n")
f.write("|------------|--------------------|\n")
Expand Down Expand Up @@ -231,9 +232,7 @@ def project_processor():
modelList.models.append(modelInfo)
# copy pre — auto-ensure winml.py copy entry (unless exempt), then run pre-phase copies
copyConfigFile = yml_file.parent / "_copy.json.config"
copyConfig: CopyConfig | None = (
CopyConfig.Read(copyConfigFile.as_posix()) if copyConfigFile.exists() else None
)
copyConfig: CopyConfig | None = CopyConfig.Read(copyConfigFile.as_posix()) if copyConfigFile.exists() else None
if modelInfo.id not in WINML_COPY_EXEMPT_IDS:
desired_src = winml_copy_src_for(modelInfo.id)
if copyConfig is None:
Expand Down Expand Up @@ -262,7 +261,7 @@ def project_processor():
# project config and json configs
convert_yaml_to_project_config(yml_file, yaml_object, modelList, model_summary)

modelList.models.sort(key=lambda x: (x.GetSortKey()))
modelList.models.sort(key=lambda x: x.GetSortKey())
modelList.writeIfChanged()
all_summary.write(root_dir)

Expand Down
9 changes: 5 additions & 4 deletions .aitk/scripts/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
deepdiff
pydantic
pydash
pyyaml
deepdiff==9.1.0
pydantic==2.13.4
pydash==8.0.6
pyyaml==6.0.3
ruff==0.15.14
1 change: 1 addition & 0 deletions .aitk/scripts/requirements_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,6 @@ def requirements_check():
req_is_subset(nvidia_autogptq, general_cuda_autogptq)
req_is_subset(general_cuda_autogptq, nvidia_autogptq)


if __name__ == "__main__":
requirements_check()
82 changes: 82 additions & 0 deletions .aitk/scripts/ruff_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/usr/bin/env python3
"""
Ruff-based lint and format check for Python files in `.aitk/` and every `*/aitk/` folder.

By default, runs `ruff check` and `ruff format --check` (verification only) and exits 1 on
issues. When called with `fix=True`, runs `ruff check --fix` and `ruff format` to rewrite
files in place.
"""

import subprocess
import sys
from pathlib import Path

from sanitize.utils import printError, printInfo, printTip

LINE_LENGTH = "120"
SELECT_RULES = "F401,F841,I"
REQUIREMENTS_HINT = ".aitk/scripts/requirements.txt"


def _ensure_ruff():
try:
subprocess.run(["ruff", "--version"], check=True, capture_output=True)
return True
except (subprocess.CalledProcessError, FileNotFoundError):
printError(f"ruff is not installed. Install dependencies first: pip install -r {REQUIREMENTS_HINT}")
return False


def _collect_targets():
repo_root = Path(__file__).parent.parent.parent

targets = []
dot_aitk = repo_root / ".aitk"
if dot_aitk.is_dir():
targets.append(dot_aitk)

for aitk_dir in sorted(repo_root.glob("*/aitk")):
if aitk_dir.is_dir():
targets.append(aitk_dir)

return targets


def ruff_check(fix: bool = False):
"""
Run ruff lint + format across `.aitk/` and every `*/aitk/` folder.

Args:
fix: When True, apply autofixes and reformat files. When False, only verify.
"""
if not _ensure_ruff():
raise SystemExit(1)

targets = _collect_targets()
if not targets:
printInfo("No .aitk / aitk folders found for ruff to check.")
return

target_args = [str(t) for t in targets]
printTip(f"Running ruff on {len(targets)} folder(s)...")

exclude_ipynb = ["--config", 'extend-exclude=["*.ipynb"]']
Comment thread
xieofxie marked this conversation as resolved.
check_cmd = ["ruff", "check", "--select", SELECT_RULES, "--line-length", LINE_LENGTH, *exclude_ipynb]
format_cmd = ["ruff", "format", "--line-length", LINE_LENGTH, *exclude_ipynb]
if fix:
check_cmd.append("--fix")
else:
format_cmd.append("--check")

check_result = subprocess.run(check_cmd + target_args)
format_result = subprocess.run(format_cmd + target_args)

if check_result.returncode != 0 or format_result.returncode != 0:
printError("Ruff reported issues. Re-run `python sanitize.py --format_scripts` to auto-fix.")
Comment thread
xieofxie marked this conversation as resolved.
Outdated
raise SystemExit(1)

printInfo("Ruff check passed.")


if __name__ == "__main__":
ruff_check(fix="--fix" in sys.argv)
Loading
Loading