mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-09-18 10:23:43 +08:00
check dependency footprint (#38825)
This commit is contained in:
Executable
+37
@@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env python3
|
||||
import sys
|
||||
import tomllib
|
||||
import importlib.metadata
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def main() -> int:
|
||||
if sys.prefix == sys.base_prefix:
|
||||
print("Dependency checks require a virtual environment. Run tools/op.sh setup first.")
|
||||
return 1
|
||||
|
||||
project = tomllib.loads((Path(__file__).resolve().parents[2] / "pyproject.toml").read_text())["project"]
|
||||
direct = len(project["dependencies"]) + sum(len(deps) for deps in project["optional-dependencies"].values())
|
||||
# Count each installed package once, including transitive dependencies and all extras.
|
||||
packages = {dist.metadata["Name"].lower().replace("_", "-") for dist in importlib.metadata.distributions()}
|
||||
# Logical file sizes avoid filesystem block-size differences. Don't follow links to the interpreter or source tree.
|
||||
size = sum(path.stat().st_size for path in Path(sys.prefix).rglob("*") if not path.is_symlink() and path.is_file())
|
||||
|
||||
"""
|
||||
This test prevents our depency footprint from growing.
|
||||
These values are *not* intended to be increased, and we
|
||||
expect to strictly drive these down over time.
|
||||
"""
|
||||
failed = False
|
||||
for name, value, limit in (
|
||||
("Direct dependencies (all extras)", direct, 37),
|
||||
("Total dependencies", len(packages), 65),
|
||||
("Venv size (MiB)", size / 1024**2, 550),
|
||||
):
|
||||
print(f"{name}: {value:g} (limit: {limit})")
|
||||
failed |= value > limit
|
||||
return int(failed)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
@@ -46,6 +46,7 @@ function run_tests() {
|
||||
PYTHON_FILES=$2
|
||||
|
||||
run "ruff" ruff check openpilot --quiet
|
||||
run "check_dependencies" python3 $DIR/check_dependencies.py
|
||||
run "check_indentation" $DIR/check_indentation.py $PYTHON_FILES
|
||||
run "check_added_large_files" $DIR/check_added_large_files.py --maxkb=120 $ALL_FILES
|
||||
run "check_shebang_scripts_are_executable" $DIR/check_shebang_scripts_are_executable.py $ALL_FILES
|
||||
@@ -67,6 +68,7 @@ function help() {
|
||||
echo ""
|
||||
echo -e "${BOLD}${UNDERLINE}Tests:${NC}"
|
||||
echo -e " ${BOLD}ruff${NC}"
|
||||
echo -e " ${BOLD}check_dependencies${NC}"
|
||||
echo -e " ${BOLD}check_indentation${NC}"
|
||||
echo -e " ${BOLD}ty${NC}"
|
||||
echo -e " ${BOLD}codespell${NC}"
|
||||
|
||||
Reference in New Issue
Block a user