PYTHON-5240 Add pre-commit hook for config generation (#2237)

This commit is contained in:
Steven Silvester 2025-03-27 08:39:12 -05:00 committed by GitHub
parent 4e5166b29a
commit 3a3f3d2214
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 16 additions and 12 deletions

View File

@ -0,0 +1,6 @@
#!/bin/bash
# Entry point for the generate-config pre-commit hook.
set -eu
python .evergreen/scripts/generate_config.py

View File

@ -1,12 +1,4 @@
# /// script
# requires-python = ">=3.9"
# dependencies = [
# "shrub.py>=3.2.0",
# "pyyaml>=6.0.2"
# ]
# ///
# Note: Run this file with `pipx run`, or `uv run`.
# Note: See CONTRIBUTING.md for how to update/run this file.
from __future__ import annotations
import sys
@ -1113,7 +1105,7 @@ def write_variants_to_file():
with target.open("w") as fid:
fid.write("buildvariants:\n")
for name, func in getmembers(mod, isfunction):
for name, func in sorted(getmembers(mod, isfunction)):
if not name.endswith("_variants"):
continue
if not name.startswith("create_"):
@ -1143,7 +1135,7 @@ def write_tasks_to_file():
with target.open("w") as fid:
fid.write("tasks:\n")
for name, func in getmembers(mod, isfunction):
for name, func in sorted(getmembers(mod, isfunction)):
if not name.endswith("_tasks"):
continue
if not name.startswith("create_"):

View File

@ -116,3 +116,9 @@ repos:
(?x)(
.evergreen/retry-with-backoff.sh
)
- id: generate-config
name: generate-config
entry: .evergreen/scripts/generate-config.sh
language: python
require_serial: true
additional_dependencies: ["shrub.py>=3.2.0", "pyyaml>=6.0.2"]

View File

@ -367,7 +367,7 @@ If you are running one of the `no-responder` tests, omit the `run-server` step.
- If there are any special test considerations, including not running `pytest` at all, handle it in `.evergreen/scripts/run_tests.py`.
- If there are any services or atlas clusters to teardown, handle them in `.evergreen/scripts/teardown_tests.py`.
- Add functions to generate the test variant(s) and task(s) to the `.evergreen/scripts/generate_config.py`.
- Regenerate the test variants and tasks using the instructions in `.evergreen/scripts/generate_config.py`.
- Regenerate the test variants and tasks using `pre-commit run --all-files generate-config`.
- Make sure to add instructions for running the test suite to `CONTRIBUTING.md`.
## Re-sync Spec Tests