Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
78 changes: 78 additions & 0 deletions bin/filter-errors-after-date
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/usr/bin/env python3

# Used to filter errors to only show lines committed on or after a specific date
# Can be chained with filter-errors-for-user

import sys
import re
import subprocess
from datetime import datetime


_blame = {}


def _is_after_date(file, line_no, cutoff_date):
if file not in _blame:
_blame[file] = _get_git_blame_dates_for_file(file)
line_date = _blame[file].get(line_no)
if not line_date:
return False
return line_date >= cutoff_date


def _get_git_blame_dates_for_file(file_name):
try:
result = subprocess.run(
["git", "blame", "--date=short", file_name],
capture_output=True,
text=True,
check=True,
)

blame_map = {}
# Each line looks like: ^abc123 (Author Name 2024-01-01 1) code
blame_pattern = re.compile(r"^[^\(]+\([^\)]+(\d{4}-\d{2}-\d{2})")

for i, line in enumerate(result.stdout.split("\n")):
if not line:
continue
match = blame_pattern.match(line)
if match:
date_str = match.group(1)
blame_map[str(i + 1)] = date_str

return blame_map
except subprocess.CalledProcessError:
return {}


def main():
if len(sys.argv) != 2:
print("Usage: filter-errors-after-date <date>", file=sys.stderr)
print(" Example: filter-errors-after-date 2025-10-04", file=sys.stderr)
sys.exit(1)

cutoff_date = sys.argv[1]

try:
datetime.strptime(cutoff_date, "%Y-%m-%d")
except ValueError:
print(f"Error: Invalid date format '{cutoff_date}'. Use YYYY-MM-DD", file=sys.stderr)
sys.exit(1)

for line in sys.stdin.readlines():
split = re.findall(r"^([^:]+):(\d+):(.*)", line)
if not split or len(split[0]) != 3:
continue

file, line_no = split[0][:2]
if not file.startswith("dimos/"):
continue

if _is_after_date(file, line_no, cutoff_date):
print(":".join(split[0]))


if __name__ == "__main__":
main()
64 changes: 64 additions & 0 deletions bin/filter-errors-for-user
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env python3

# Used when running `./bin/mypy-strict --for-me`

import sys
import re
import subprocess


_blame = {}


def _is_for_user(file, line_no, user_email):
if file not in _blame:
_blame[file] = _get_git_blame_for_file(file)
return _blame[file][line_no] == user_email


def _get_git_blame_for_file(file_name):
try:
result = subprocess.run(
["git", "blame", "--show-email", "-e", file_name],
capture_output=True,
text=True,
check=True,
)

blame_map = {}
# Each line looks like: ^abc123 (<email@example.com> 2024-01-01 12:00:00 +0000 1) code
blame_pattern = re.compile(r"^[^\(]+\(<([^>]+)>")

for i, line in enumerate(result.stdout.split("\n")):
if not line:
continue
match = blame_pattern.match(line)
if match:
email = match.group(1)
blame_map[str(i + 1)] = email

return blame_map
except subprocess.CalledProcessError:
return {}


def main():
if len(sys.argv) != 2:
print("Usage: filter-errors-for-user <git-email>", file=sys.stderr)
sys.exit(1)

user_email = sys.argv[1]

for line in sys.stdin.readlines():
split = re.findall(r"^([^:]+):(\d+):(.*)", line)
if not split or len(split[0]) != 3:
continue
file, line_no = split[0][:2]
if not file.startswith("dimos/"):
continue
if _is_for_user(file, line_no, user_email):
print(":".join(split[0]))


if __name__ == "__main__":
main()
98 changes: 98 additions & 0 deletions bin/mypy-strict
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/bin/bash
#
# Run mypy with strict settings on the dimos codebase.
#
# Usage:
# ./bin/mypy-strict # Run mypy and show all errors
# ./bin/mypy-strict --user me # Filter for your git user.email
# ./bin/mypy-strict --after cutoff # Filter for lines committed on or after 2025-10-08
# ./bin/mypy-strict --after 2025-11-11 # Filter for lines committed on or after specific date
# ./bin/mypy-strict --user me --after cutoff # Chain filters
#

set -euo pipefail

ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"

cd "$ROOT"

. .venv/bin/activate

run_mypy() {
export MYPYPATH=/opt/ros/jazzy/lib/python3.12/site-packages

mypy_args=(
--config-file mypy_strict.ini
--show-error-codes
--hide-error-context
--no-pretty
dimos
)
mypy "${mypy_args[@]}"
}

main() {
local user_email="none"
local after_date=""

# Parse arguments
while [[ $# -gt 0 ]]; do
case "$1" in
--user)
if [[ $# -lt 2 ]]; then
echo "Error: --user requires an argument" >&2
exit 1
fi
case "$2" in
me)
user_email="$(git config user.email || echo none)"
;;
all)
user_email="none"
;;
*)
user_email="$2"
;;
esac
shift 2
;;
--after)
if [[ $# -lt 2 ]]; then
echo "Error: --after requires an argument" >&2
exit 1
fi
case "$2" in
cutoff)
after_date="2025-10-10"
;;
start)
after_date=""
;;
*)
after_date="$2"
;;
esac
shift 2
;;
*)
echo "Error: Unknown argument '$1'" >&2
exit 1
;;
esac
done

# Build filter pipeline
local pipeline="run_mypy"

if [[ -n "$after_date" ]]; then
pipeline="$pipeline | ./bin/filter-errors-after-date '$after_date'"
fi

if [[ "$user_email" != "none" ]]; then
pipeline="$pipeline | ./bin/filter-errors-for-user '$user_email'"
fi

eval "$pipeline"
}

main "$@"
133 changes: 0 additions & 133 deletions bin/ty-check

This file was deleted.

Loading
Loading