Skip to content

Commit 71806e1

Browse files
Gate Jenkins mypy on py.typed marker (#159)
1 parent 9786dcf commit 71806e1

10 files changed

Lines changed: 32 additions & 27 deletions

File tree

libs/build-utils/CHANGELOG.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
**4.1.0 - 06/29/26**
2+
3+
- Run mypy in CI based on the presence of a ``py.typed`` marker under ``src/``
4+
- Centralize py.typed marker logic in a new ``mypy-if-typed`` Make target
5+
- Deprecate the ``run_mypy`` ``reusable_pipeline`` argument; it is still accepted but ignored
6+
17
**4.0.2 - 06/24/26**
28

39
- Add ``--runslow`` and ``--runweekly`` support to pytest calls so that Jenkins builds pass

libs/build-utils/resources/makefiles/base.mk

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,14 @@ lint: # Check for formatting errors
188188
mypy: # Check for type hinting errors
189189
mypy --config-file pyproject.toml .
190190

191+
.PHONY: mypy-if-typed
192+
mypy-if-typed: # Run mypy only if a py.typed marker exists under src/
193+
@if find src -name py.typed 2>/dev/null | grep -q .; then \
194+
make mypy; \
195+
else \
196+
echo "No py.typed marker found under src/; skipping mypy."; \
197+
fi
198+
191199
# test: test targets are defined in test.mk
192200

193201
.PHONY: build-docs
@@ -253,15 +261,9 @@ clean: # Clean build artifacts and temporary files
253261
.PHONY: check
254262
check: # Run development checks
255263
make lint
256-
# Run mypy if any py.typed marker exists under src/
257-
# Use 'find' command rather than a hardcoded src/$(PACKAGE_NAME)/py.typed path so
258-
# this works for both flat layouts (src/<pkg>/py.typed) and namespace layouts under
259-
# monorepo (src/vivarium/<pkg>/py.typed).
260-
@if find src -name py.typed 2>/dev/null | grep -q .; then \
261-
echo; \
262-
echo "Running mypy"; \
263-
make mypy; \
264-
fi
264+
# Run mypy if any py.typed marker exists under src/ (see mypy-if-typed)
265+
@echo
266+
make mypy-if-typed
265267
# Run all fast tests
266268
@echo
267269
@echo "Running fast tests"

libs/build-utils/vars/build_stages.groovy

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,12 @@ def installPackage(String env_reqs = "") {
118118
}
119119
}
120120

121-
def checkFormatting(Boolean run_mypy) {
121+
def checkFormatting() {
122122
stage("Check Formatting - Python ${PYTHON_VERSION}") {
123123
withWorkingDirectory {
124124
script {
125125
sh "${ACTIVATE} && make lint"
126-
if (run_mypy == true) {
127-
sh "${ACTIVATE} && make mypy"
128-
}
126+
sh "${ACTIVATE} && make mypy-if-typed"
129127
}
130128
}
131129
}

libs/build-utils/vars/reusable_pipeline.groovy

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ def call(Map config = [:]){
1010
requires_slurm: Whether the child tasks require the slurm scheduler.
1111
deployable: Whether the package can be deployed by Jenkins.
1212
skip_doc_build: Only skips the doc build.
13-
run_mypy: Whether to run mypy on the package
13+
run_mypy: DEPRECATED and ignored. mypy now runs automatically whenever a
14+
py.typed marker exists under the package's src/ (matching `make check`
15+
and GH Actions).
1416
env_reqs: The pyproject.toml extras to install with `make install` (e.g. "ci_jenkins").
1517
Empty/omitted leaves base.mk's default ("dev"), which is correct for standalone repos.
1618
github_credentials_id: Jenkins credential ID to use during the deploy stage when pushing
@@ -37,7 +39,12 @@ def call(Map config = [:]){
3739
def requires_slurm = config.requires_slurm ?: false
3840
def is_deployable = (config?.deployable == true)
3941
def skip_doc_build = (config?.skip_doc_build == true)
40-
def run_mypy = (config.run_mypy != null) ? config.run_mypy : true
42+
// DEPRECATED: run_mypy no longer controls anything. mypy runs in checkFormatting
43+
// whenever a py.typed marker exists under src/. Accepted for backward compatibility.
44+
if (config.run_mypy != null) {
45+
echo "WARNING: 'run_mypy' is deprecated and ignored; mypy now runs automatically " +
46+
"when a py.typed marker exists under src/."
47+
}
4148
// Empty string leaves base.mk's default ("dev") in effect. installPackage in
4249
// build_stages.groovy only sets ENV_REQS=... when this is non-empty.
4350
def env_reqs = config.env_reqs ?: ""
@@ -59,7 +66,6 @@ def call(Map config = [:]){
5966
echo " requires_slurm: ${requires_slurm}"
6067
echo " is_deployable: ${is_deployable}"
6168
echo " skip_doc_build: ${skip_doc_build}"
62-
echo " run_mypy: ${run_mypy}"
6369
echo " env_reqs: ${env_reqs}"
6470

6571
if (stagger_scheduled_builds && scheduled_branches.size() > 1) {
@@ -259,7 +265,7 @@ def call(Map config = [:]){
259265
buildStages.runDebugInfo(skipEval)
260266
buildStages.buildEnvironment()
261267
buildStages.installPackage(env_reqs)
262-
buildStages.checkFormatting(run_mypy)
268+
buildStages.checkFormatting()
263269
// Transform test type inputs to actual make test target names
264270
tests = test_types.collect { "test-${it}" }
265271
buildStages.runTests(tests, run_weekly)

libs/compat/Jenkinsfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,5 @@ library("vivarium_build_utils@${get_vbu_version()}")
3030
reusable_pipeline(
3131
scheduled_branches: ['main'],
3232
skip_doc_build: true,
33-
run_mypy: false,
3433
env_reqs: 'ci_jenkins',
3534
)

libs/gbd-mapping/Jenkinsfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,4 @@ reusable_pipeline(
3535
"main"
3636
],
3737
env_reqs: "ci_jenkins",
38-
run_mypy: false,
3938
)

libs/gbd-mapping/pyproject.toml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,10 @@ git_describe_command = 'git describe --dirty --tags --long --match "vivarium-gbd
6666
fallback_version = "0.0.0+no-git-tag"
6767

6868
# No [tool.mypy] section: this package is only partially typed and the
69-
# gbd_mapping module is largely auto-generated. CI's `make mypy` is skipped
70-
# when py.typed is absent (see .github/workflows/ci.yml); Jenkinsfile sets
71-
# `run_mypy: false` to match. When the codebase is fully annotated, add a
69+
# gbd_mapping module is largely auto-generated. CI skips mypy when no py.typed
70+
# marker exists under src/. When the codebase is fully annotated, add a
7271
# py.typed marker plus the standard [tool.mypy] block (see
73-
# libs/config-tree/pyproject.toml for the template) and flip Jenkins
74-
# `run_mypy` back to true.
72+
# libs/config-tree/pyproject.toml for the template) to enable mypy everywhere.
7573

7674
[tool.black]
7775
line-length = 94

libs/profiling/Jenkinsfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,5 @@ library("vivarium_build_utils@${get_vbu_version()}")
3030
reusable_pipeline(
3131
scheduled_branches: ["main"],
3232
skip_doc_build: true,
33-
run_mypy: false,
3433
env_reqs: "ci_jenkins",
3534
)

libs/public-health/Jenkinsfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,5 @@ reusable_pipeline(
3434
// for subsequent scheduled builds to run.
3535
"main",
3636
],
37-
run_mypy: false,
3837
env_reqs: "ci_jenkins",
3938
)

libs/risk-distributions/Jenkinsfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,4 @@ reusable_pipeline(
3535
"main"
3636
],
3737
env_reqs: "ci_jenkins",
38-
run_mypy: false,
3938
)

0 commit comments

Comments
 (0)