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
2 changes: 1 addition & 1 deletion .config/mise/tasks/weaver/test/_default
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash
#MISE description="Run every policy and template package test, and validate generated code"
#MISE depends=["weaver:test:policies", "weaver:test:templates", "weaver:test:go", "weaver:test:rust", "weaver:test:typescript_effect", "weaver:test:typescript"]
#MISE depends=["weaver:test:policies", "weaver:test:templates", "weaver:test:go", "weaver:test:rust", "weaver:test:typescript_effect", "weaver:test:typescript", "weaver:test:python"]
4 changes: 4 additions & 0 deletions .config/mise/tasks/weaver/test/python
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
#MISE description="Type-check, lint, and run consumer tests against generated Python"
set -euo pipefail
exec ./buildscripts/check_python_output.sh
1 change: 1 addition & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ jobs:
- run: mise run weaver:test:rust
- run: mise run weaver:test:typescript_effect
- run: mise run weaver:test:typescript
- run: mise run weaver:test:python

markdown:
name: Markdown
Expand Down
5 changes: 5 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ Each template package includes:
Generated Go must pass `gofmt`, `go build`, and `go vet`, which
`mise run weaver:test:go` checks.

Generated Python must pass `ruff format --check`, `ruff check`, and
`mypy --strict`, and each case's `test_consumer.py` must pass, which
`mise run weaver:test:python` checks against the pinned OpenTelemetry Python
API and SDK.

Generated Rust must pass formatting, consumer tests, and Clippy, which
`mise run weaver:test:rust` checks against the pinned OpenTelemetry Rust API
and SDK.
Expand Down
7 changes: 7 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ temporary crates and runs formatting, consumer tests, and Clippy. Put consumer
tests in a case's `test.rs`, importing the generated crate as
`generated_semconv`.

For the Python package, `mise run weaver:test:python` runs formatting, lint,
and `mypy --strict` over every expected module and runs each case's
`test_consumer.py` with an SDK `InMemoryMetricReader`. Consumers import the
generated package as `semconv`. Requirements are locked with hashes in
`buildscripts/python/` and installed in a disposable virtual environment outside
the checkout.

For the TypeScript package, `mise run weaver:test:typescript` type-checks every
expected module and runs each case's `consumer.test.ts` against the pinned
OpenTelemetry JavaScript API and SDK. Consumers import `./metrics.ts`, may use
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ is versioned and released from this repository, ready to be referenced by tag.

**The packages turn a semantic convention registry into code and keep that
registry fit for generation.** Templates generate typed telemetry helpers, such
as typed attribute values and signal helpers on the OpenTelemetry Go and
as typed attribute values and signal helpers on the OpenTelemetry Go, Python and
Rust APIs.
Policies run during `weaver registry check` and reject conventions a template
cannot render, before any code is written.
Expand All @@ -31,6 +31,7 @@ Templates live under [`templates`](templates) and policies under
does and the params it accepts.

- [Go code generation](templates/code/go/README.md)
- [Python metrics](templates/code/python/README.md)
- [Rust code generation](templates/code/rust/README.md)
- [TypeScript metrics](templates/code/typescript/README.md)
- [Effect TypeScript metrics](templates/code/typescript_effect/README.md)
Expand Down
49 changes: 49 additions & 0 deletions buildscripts/check_python_output.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env bash
set -euo pipefail

ROOT="$(pwd)"
PACKAGE_DIR="${ROOT}/templates/code/python"
TOOLING_DIR="${ROOT}/buildscripts/python"
WORK_DIR="$(mktemp -d "${TMPDIR:-/tmp}/weaver-python.XXXXXX")"
trap 'rm -rf "${WORK_DIR}"' EXIT
export PYTHONDONTWRITEBYTECODE=1

for test_dir in "${PACKAGE_DIR}"/tests/*/; do
test_name="$(basename "${test_dir}")"
[[ -f "${test_dir}expected-error.txt" ]] && continue
if [[ ! -f "${test_dir}expected/__init__.py" ]]; then
echo " FAIL: ${test_name} is missing expected/__init__.py."
exit 1
fi
if [[ ! -f "${test_dir}test_consumer.py" ]]; then
echo " FAIL: ${test_name} is missing test_consumer.py."
exit 1
fi
mkdir -p "${WORK_DIR}/cases/${test_name}/semconv"
cp -R "${test_dir}expected/." "${WORK_DIR}/cases/${test_name}/semconv/"
cp "${test_dir}test_consumer.py" "${WORK_DIR}/cases/${test_name}/"
done

uv venv --quiet --python "$(command -v python)" "${WORK_DIR}/venv"
uv pip install --quiet --python "${WORK_DIR}/venv/bin/python" --require-hashes --no-deps -r "${TOOLING_DIR}/requirements.txt"
BIN="${WORK_DIR}/venv/bin"

echo "-> Checking ruff format ..."
"${BIN}/ruff" format --check --config "${TOOLING_DIR}/ruff.toml" "${WORK_DIR}/cases"
echo "-> Checking ruff check ..."
"${BIN}/ruff" check --no-cache --config "${TOOLING_DIR}/ruff.toml" "${WORK_DIR}/cases"

shopt -s nullglob
cases=("${WORK_DIR}"/cases/*/)
if [[ ${#cases[@]} -eq 0 ]]; then
echo 'FAIL: no Python cases found'
exit 1
fi
for case_dir in "${cases[@]}"; do
echo "-> Checking Python [$(basename "${case_dir}")] ..."
(
cd "${case_dir}"
"${BIN}/mypy" --config-file "${TOOLING_DIR}/mypy.ini" --cache-dir "${WORK_DIR}/mypy-cache" semconv test_consumer.py
"${BIN}/python" -m pytest --quiet --disable-warnings -p no:cacheprovider test_consumer.py
)
done
5 changes: 5 additions & 0 deletions buildscripts/python/mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[mypy]
python_version = 3.12
strict = True
warn_unused_ignores = True
cache_dir = .mypy_cache
6 changes: 6 additions & 0 deletions buildscripts/python/requirements.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Regenerate requirements.txt with: mise exec -- uv pip compile --generate-hashes --python-version 3.12 --no-header -o requirements.txt requirements.in
mypy==2.4.1
opentelemetry-api==1.45.2
opentelemetry-sdk==1.45.2
pytest==9.2.0
ruff==0.17.3
Loading
Loading