Skip to content

Commit cfecaa4

Browse files
jeremymanningclaude
andcommitted
Clean up every ruff finding and two thirds of the mypy ones
First lint and type pass over the build scripts. Neither tool is wired into CI, so this is groundwork rather than a fix for anything failing. ruff, 42 findings to 0: - 38 auto-fixed: unused imports, f-strings with no placeholders, one redefined-while-unused - dropped two header lists in fix_members.py and sync_cv_people.py that were read off the sheet and never used - moved onboard_member.py's deferred dartmouth_chat import up with the other module imports, carrying its explanatory comment along so the mlx-lm rationale stays attached to the import it explains mypy, 24 errors to 8, all of it annotation-only: - annotated eight collections mypy could not infer, and the two implicit Optional defaults in build_cv.run_command and add_borders - declared member as Optional in offboard_member.py, since prompt_for_selection can return None - annotated add_borders' img as Image.Image: Image.open returns an ImageFile but convert and crop return an Image - onboard_member.py now narrows on `alumni_entry is not None` directly rather than through an intermediate bool mypy cannot see through The eight remaining mypy errors are all third-party stub limitations, not defects: BeautifulSoup attribute lookups in extract_people.py, Image.getpixel's union return, an re.subn overload, and one variable in extract_cv.py that holds two shapes. extract_cv.py is the LaTeX to HTML parser the CV build depends on, so it is not worth restructuring in the same push as a CV change. Filed separately. Verified behavior-neutral by rebuilding: publications.html, people.html, software.html, news.html and JRM_CV.html all come back byte-identical, and JRM_CV.pdf differs only in its embedded timestamp. ruff is clean and the suite is 348 passed, 12 skipped. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QQUWxAFYESZCZe3DLyy1eB
1 parent 6ac7d1a commit cfecaa4

22 files changed

Lines changed: 44 additions & 62 deletions

‎scripts/add_borders.py‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
import subprocess
2121
import tempfile
2222
from pathlib import Path
23+
from typing import Optional
2324
from PIL import Image
2425
import numpy as np
25-
import io
2626

2727
# Register HEIC/HEIF support so Pillow can open .heic files
2828
try:
@@ -95,17 +95,15 @@ def resize_to_max_dimension(img: Image.Image, max_size: int = MAX_INPUT_DIMENSIO
9595
def get_face_detector():
9696
"""Get or create a mediapipe face detector (cached)."""
9797
if not hasattr(get_face_detector, '_detector'):
98-
import mediapipe as mp
9998
from mediapipe.tasks import python as mp_python
10099
from mediapipe.tasks.python import vision
101100
import urllib.request
102-
import os
103101

104102
# Download the face detection model if not present
105103
model_path = Path(__file__).parent / 'blaze_face_short_range.tflite'
106104
if not model_path.exists():
107105
url = "https://storage.googleapis.com/mediapipe-models/face_detector/blaze_face_short_range/float16/latest/blaze_face_short_range.tflite"
108-
print(f" Downloading face detection model...")
106+
print(" Downloading face detection model...")
109107
urllib.request.urlretrieve(url, str(model_path))
110108

111109
# Create face detector
@@ -441,7 +439,7 @@ def process_images(
441439
svg_path: Path,
442440
output_size: int = OUTPUT_SIZE,
443441
use_face_detection: bool = False,
444-
seed: int = None
442+
seed: Optional[int] = None
445443
) -> None:
446444
"""Process images, adding borders after optional crop and resize.
447445
@@ -482,7 +480,7 @@ def process_images(
482480
print(f" Processing {img_path.name}...")
483481

484482
# Load image
485-
img = Image.open(img_path)
483+
img: Image.Image = Image.open(img_path)
486484
if img.mode != 'RGBA':
487485
img = img.convert('RGBA')
488486

‎scripts/build_cv.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
]
6666

6767

68-
def run_command(cmd: list, cwd: Path = None, timeout: int = 120) -> tuple:
68+
def run_command(cmd: list, cwd: Optional[Path] = None, timeout: int = 120) -> tuple:
6969
"""Run a command and return (success, stdout, stderr)."""
7070
try:
7171
result = subprocess.run(

‎scripts/build_people.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ def generate_undergrad_list_content(
437437
# agree on capitalization (e.g. "Evan Mcdermid" vs "Evan McDermid"), and
438438
# an exact-match miss silently drops that person to the end of their
439439
# cohort instead of their CV position.
440-
cv_position = {}
440+
cv_position: Dict[str, int] = {}
441441
if cv_order:
442442
for i, name in enumerate(cv_order):
443443
cv_position.setdefault(name.casefold(), i)

‎scripts/build_publications.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
format_dissertation_citation,
2424
format_talk_citation,
2525
format_poster_citation,
26-
format_course_citation,
2726
markdown_to_html,
2827
resolve_link,
2928
build_links_html,

‎scripts/build_software.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import openpyxl
1919

2020
from utils import inject_content
21-
from citation_utils import markdown_to_html, resolve_link, build_links_html
21+
from citation_utils import markdown_to_html, build_links_html
2222

2323

2424
def load_software(xlsx_path: Path) -> Dict[str, List[Dict[str, Any]]]:

‎scripts/citation_utils.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
- Build link HTML from URLs or local file paths
99
"""
1010
import re
11-
from typing import Optional, List, Tuple
12-
from pathlib import Path
11+
from typing import List, Tuple
1312

1413
# GitHub repository URL for the project
1514
GITHUB_REPO_URL = "https://github.com/ContextLab/contextlab.github.io/blob/main"

‎scripts/extract_cv.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import re
1010
from pathlib import Path
11-
from typing import Dict, List, Optional
11+
from typing import Dict, List
1212
from dataclasses import dataclass, field
1313

1414

‎scripts/extract_people.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"""
66
import re
77
from pathlib import Path
8+
from typing import Any, Dict, List
89
from bs4 import BeautifulSoup
910
import openpyxl
1011

@@ -146,7 +147,7 @@ def extract_alumni_list(elem) -> list:
146147
- Gina Notaro (2017-2018; now at <a>Lockheed Martin</a>)
147148
- <a>Andrew Heusser</a> (2016-2018; now at <a>Akili</a>)
148149
"""
149-
alumni = []
150+
alumni: List[Dict[str, Any]] = []
150151
if not elem:
151152
return alumni
152153

@@ -237,7 +238,7 @@ def extract_alumni_list(elem) -> list:
237238

238239
def extract_alumni_simple_list(elem) -> list:
239240
"""Extract simple alumni list (just names and years)."""
240-
alumni = []
241+
alumni: List[Dict[str, Any]] = []
241242
if not elem:
242243
return alumni
243244

‎scripts/extract_publications.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
44
This is a one-time script to migrate existing HTML data to the spreadsheet format.
55
"""
6-
import re
76
from pathlib import Path
7+
from typing import Any, Dict
88
from bs4 import BeautifulSoup
99
import openpyxl
1010

@@ -26,7 +26,7 @@ def extract_publications(html_path: Path) -> dict:
2626
'posters': 'posters'
2727
}
2828

29-
data = {}
29+
data: Dict[str, Any] = {}
3030

3131
for key, section_id in sections.items():
3232
section = soup.find('section', id=section_id)

‎scripts/extract_software.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"""
66
import re
77
from pathlib import Path
8+
from typing import Any, Dict
89
from bs4 import BeautifulSoup
910
import openpyxl
1011

@@ -23,7 +24,7 @@ def extract_software(html_path: Path) -> dict:
2324
'matlab': 'matlab'
2425
}
2526

26-
data = {}
27+
data: Dict[str, Any] = {}
2728

2829
for key, section_id in sections.items():
2930
section = soup.find('section', id=section_id)

0 commit comments

Comments
 (0)