Skip to content

Commit 4dadbaf

Browse files
Berik AshimovBerik Ashimov
authored andcommitted
build: fix mypyc wheel build — add mypy/setuptools/msgspec to build-system.requires + mypy follow_imports=silent
1 parent 755884c commit 4dadbaf

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

build_mypyc.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,11 @@
3838
"src/hawkapi/routing/route.py",
3939
"src/hawkapi/routing/param_converters.py",
4040
"src/hawkapi/middleware/_pipeline.py",
41-
# Added in Wave 3: router registration path (hot at startup, also called
42-
# on include_router) and the plan-based dependency resolver (hot per
43-
# request on every non-trivial route). Both are pure-typed with no
44-
# subclassing constraints from user code, so mypyc can compile them freely.
45-
"src/hawkapi/routing/router.py",
46-
"src/hawkapi/di/resolver.py",
41+
# NOTE: routing/router.py and di/resolver.py were considered for Wave 3
42+
# expansion but are EXCLUDED — mypyc type-checks transitive imports which
43+
# pull in the entire codebase (including optional deps like structlog,
44+
# prometheus_client). Keep them interpreted until we have a narrower
45+
# mypyc invocation that only checks the selected modules.
4746
# NOTE: app.py is intentionally EXCLUDED — HawkAPI(Router) is subclassed
4847
# by user code and mypyc does not allow interpreted classes to inherit from
4948
# compiled ones at runtime.
@@ -92,6 +91,10 @@ def build_extensions() -> Sequence[Any]:
9291
# Import lazily so pure-Python builds never need ``mypy`` installed.
9392
from mypyc.build import mypycify # noqa: PLC0415
9493

94+
# Type-check scope is limited via [tool.mypy] in pyproject.toml
95+
# (follow_imports = silent, ignore_missing_imports = true) so mypy does not
96+
# walk the whole package when type-checking the compiled modules, and so
97+
# optional runtime deps absent from build isolation do not fail the build.
9598
return mypycify(
9699
list(HOT_MODULES),
97100
strip_asserts=False,

pyproject.toml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[build-system]
2-
requires = ["hatchling"]
2+
requires = ["hatchling", "mypy>=1.11", "setuptools>=68", "msgspec>=0.19"]
33
build-backend = "hatchling.build"
44

55
[project]
@@ -125,6 +125,15 @@ exclude_lines = [
125125
pythonVersion = "3.12"
126126
typeCheckingMode = "strict"
127127

128+
[tool.mypy]
129+
# mypyc compilation (HAWKAPI_BUILD_MYPYC=1) drives mypy via build_mypyc.py.
130+
# Restrict type-checking scope so optional runtime deps absent from the build
131+
# isolation (structlog, prometheus_client, pydantic) do not fail the wheel
132+
# build, and so mypy does not walk the whole package when compiling the
133+
# selected hot modules.
134+
follow_imports = "silent"
135+
ignore_missing_imports = true
136+
128137
[dependency-groups]
129138
dev = [
130139
"pydantic>=2.12.5",

0 commit comments

Comments
 (0)