Skip to content

ci: stubtest holds the Python type stubs to the built wheel, and a script lists the stubs' breaking changes (#873) - #913

Merged
DrunkOnJava merged 6 commits into
mainfrom
ci/python-stubtest
Oct 23, 2026
Merged

DrunkOnJava merged 6 commits into
mainfrom
ci/python-stubtest

Conversation

@DrunkOnJava

@DrunkOnJava DrunkOnJava commented Oct 23, 2026 •

Copy link
Copy Markdown
Owner

Summary

The Python half of S2 in #873. mypy's stubtest now fails the Linux wheel job when the built wheel and python/rvt/__init__.pyi disagree. tools/ci/python-api-compat.py lists the breaking changes between two versions of those stubs. With stubtest keeping the stubs true, a diff of the stubs is a diff of the Python API. The script is wired into the semver checks job of #910 once that lands, under the same ! rule as the crate.

Changes

  • tools/ci/requirements-test.{in,txt}: mypy 2.4.0, hash-pinned. Recompiled with the uv command at the file's top; only mypy and its dependencies were added.
  • .github/workflows/ci.yml, job python-wheel: "The type stubs match the built wheel" runs python3 -m mypy.stubtest rvt on Linux after the pytest suite, against the installed wheel.
  • tools/ci/python-api-compat.py <base.pyi> <head.pyi>: walks both stubs with ast and reports a public name that is removed or changed kind, a parameter that is removed, renamed, moved or made keyword-only, a parameter that lost its default, a new parameter without one, and a TypedDict key removed (a returned dict's shape). It exits 1 when there is any.

What stubtest found (first run, 30 errors, four distinct problems), fixed here

  • rvt.FileMetadata was a stub-only alias, so from rvt import FileMetadata type-checked but failed at runtime. python/rvt/__init__.py now defines it as typing.Dict[str, Any], since the wheel supports Python 3.8, where dict[str, Any] cannot be evaluated.
  • RevitFile's constructor is pyo3's __new__, while the stub declared __init__. The stub now declares __new__ with the same parameters, and python-api-compat.py treats either spelling as the constructor, so this correction is not reported as a removal.
  • RevitFile cannot be subclassed at runtime and is a disjoint base, so the stub marks it @final and @disjoint_base.
  • The stub's header pointed at src/python.rs as the source of truth; it is rvt-py/src/lib.rs.

The second run, with stubtest checking the runtime module too, found two more, also fixed here:

  • Four methods the wheel has were missing from the stubs: basic_file_info_json_strict, schema_diagnostics, read_adocument_strict and read_adocument_lossy.
  • The return-shape aliases the stubs name (TypedSchemaSummary, TypedField, TypedADocument, TypedDecodedElement, TypedElementCounts) did not exist at runtime, so importing one failed like FileMetadata did. python/rvt/__init__.py defines each with typing generics.

Every other method's signature matched the wheel.

Testing

  • python-api-compat.py, run locally on the current stub against itself, reports nothing and exits 0. Against a copy that renames read_adocument and drops write_ifc's mode default, it reports both and exits 1.
  • stubtest: this PR's wheel job is the run, and any drift it finds between the stubs and the wheel is fixed here.
  • tools/check-local.sh: N/A, CI and tooling only.

Audit-honesty checklist

  • README / docs reflect the current state after this PR
  • No limitation resolved or introduced
  • Commit messages describe what and why
  • No emojis
  • No private paths, personal email addresses, or internal jargon in committed files
  • Reverse-engineering finding: N/A

Legal and contribution hygiene

  • I agree this work is licensable under Apache-2.0
  • This PR contains no Autodesk proprietary source, decompiled internals, or NDA'd SDK content

…File's constructor as pyo3 builds it (__new__, final)
…, and the return-shape aliases exist at runtime
@DrunkOnJava
DrunkOnJava marked this pull request as ready for review October 23, 2026 15:25
@DrunkOnJava
DrunkOnJava enabled auto-merge (squash) October 23, 2026 15:25

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7e87cb4c5c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tools/ci/requirements-test.in Resolved
Comment thread tools/ci/python-api-compat.py Resolved
Comment thread tools/ci/python-api-compat.py Resolved
Comment thread tools/ci/python-api-compat.py Resolved
…and a removed __version__, and the dev lockfile carries mypy

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fb14c70cb2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tools/ci/python-api-compat.py Resolved
Comment thread tools/ci/python-api-compat.py Resolved
Comment thread tools/ci/python-api-compat.py Resolved
Comment thread tools/ci/python-api-compat.py Resolved
Comment thread tools/ci/python-api-compat.py Resolved
Comment thread tools/ci/python-api-compat.py Resolved
Comment thread tools/ci/python-api-compat.py Resolved
@DrunkOnJava
DrunkOnJava merged commit 8ea5d33 into main Oct 23, 2026
28 checks passed
@DrunkOnJava
DrunkOnJava deleted the ci/python-stubtest branch October 23, 2026 17:18

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b902690c81

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread .github/workflows/ci.yml
Comment on lines +973 to +975
- name: The type stubs match the built wheel
if: runner.os == 'Linux'
run: python3 -m mypy.stubtest rvt

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Run the compatibility checker in CI

The inspected semver job still invokes only tools/ci/semver-gate.sh, while this new wheel step runs stubtest, which compares the head wheel with the head stub and cannot detect compatibility against the base revision. A repo-wide search finds no invocation of python-api-compat.py, so removing a Python method or required parameter still passes every CI gate; invoke this script from the semver job with the base and head stubs.

Useful? React with 👍 / 👎.

positional = a.posonlyargs + a.args
defaults = [None] * (len(positional) - len(a.defaults)) + [ast.unparse(d) for d in a.defaults]
kinds = ["positional-only"] * len(a.posonlyargs) + ["positional"] * len(a.args)
out = [(p.arg, k, d) for p, k, d in zip(positional, kinds, defaults)]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Include annotations in compatibility signatures

The signature representation retains only parameter names, kinds, and defaults, dropping each parameter annotation and the function return annotation. Consequently, a stub change such as def f(x: object) -> str to def f(x: str) -> int exits successfully even though existing typed callers and consumers are no longer compatible; preserve and compare annotations as part of each callable signature.

Useful? React with 👍 / 👎.

Comment on lines +130 to +134
for j, (hname, hkind, hdefault) in enumerate(head_params):
if hdefault is not None or (hkind == "positional-only" and j < len(base_params)):
continue
if hname not in base_names:
found.append(f"{name}: new parameter {hname} has no default")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject inserted required positional-only parameters

A new positional-only parameter is unconditionally treated as an existing slot whenever its index is below the old parameter count. For example, comparing def f(x, /) with def f(y, x, /) exits successfully: the old slot is falsely matched to y, and this exemption suppresses the new-required-parameter report, although every existing f(value) call now fails because x is missing.

Useful? React with 👍 / 👎.

else:
out[name] = (kind, [signature], decorators)
elif isinstance(node, ast.ClassDef) and public(node.name):
out[prefix + node.name] = ("class", None)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve class bases in the collected API

Every class is reduced to the same ("class", None) entry, so changing class Child(Base) to class Child passes when both class names and their directly declared members remain. Existing callers then lose inherited methods and Child is no longer assignable to or recognized as Base; retain and compare the base-class expressions when collecting classes.

Useful? React with 👍 / 👎.

out += [(p.arg, "keyword", None if d is None else ast.unparse(d)) for p, d in zip(a.kwonlyargs, a.kw_defaults)]
if a.kwarg:
out.append(("**", "variadic", ""))
return [p for p in out if p[0] not in ("self", "cls")]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Strip only the implicit receiver parameter

Filtering every parameter named self or cls also removes legitimate callable arguments rather than just the leading instance or class receiver. For example, changing def register(self, cls) to def register(self) exits successfully even though calls such as obj.register(MyType) now fail; make receiver removal depend on the callable's binding and position.

Useful? React with 👍 / 👎.

DrunkOnJava added a commit that referenced this pull request Oct 24, 2026
…onours SOURCE_DATE_EPOCH (#873) (#926)

## Summary

`RELEASE.md` promises the output formats are written deterministically,
and nothing checked it. A new CLI test runs every shipped writer twice
on the same file and requires the same bytes. The one thing that
differed, the export time an IFC records, is now set by
`SOURCE_DATE_EPOCH`.

## Motivation

S2 of the 1.0 criteria (#873) needs a check on each stable surface. The
crate, the Python stubs, the wasm bindings and the CLIs' JSON got theirs
in #910, #913 and #915; the output formats had validity checks
(IfcOpenShell, the glTF container, the schedule columns) but none for
the determinism `RELEASE.md` names. The IfcOpenShell witness writes
`"deterministic": true` as a constant, not a measurement.

## Changes

- `src/bin/rvt_ifc.rs`: reads `SOURCE_DATE_EPOCH` (Unix seconds, the
reproducible-builds convention) and passes it to
`write_step_with_options`; unset or empty keeps the wall-clock time,
anything else that is not a number is refused before the file is opened.
The help mentions it, and the module doc and `about` no longer say the
export is document-level only.
- `tests/reproducible_outputs.rs` (class `cli`): `rvt-ifc`, `rvt-gltf`,
`rvt-sheet`, `rvt-schedule` and `rvt-schedule --schedule rooms`, twice
each, same bytes, on the tier-1 project and on `Revit_IFC5_Einhoven.rvt`
when `RVT_PROJECT_CORPUS_DIR` has it (tier 2). A second test checks the
epoch reaches the `FILE_NAME` header and `IfcOwnerHistory`, and that a
malformed value fails naming the variable.
- `docs/user-guide.md` (Export IFC), `RELEASE.md` (Output formats row),
`docs/release-1.0-criteria.md` (S2 passed, with what each check is),
`CHANGELOG.md`.

## Testing

CI runs the new target; no build on this machine. The measured result is
the test itself: the same bytes from two runs of each writer, on a
synthetic and a real file.

- [ ] `tools/check-local.sh` passes: left to CI
- [x] Verified end to end: the test runs the built CLIs on the committed
tier-1 file and on Einhoven (magnetar-io/revit-test-datasets, MIT) in
tier 2
- [x] IFC exporter: the IFC body is unchanged; only the header and
owner-history time can differ, and only when `SOURCE_DATE_EPOCH` is set.
Witness observations hash entity counts, relations and storeys, so they
do not move
- N/A: performance

## Audit-honesty checklist

- [x] Docs reflect the state after this PR
- [x] No limitation resolved beyond the check itself
- [x] No new limitation
- [x] Commit message says what and why
- [x] No emojis
- [x] No private paths
- N/A: not a format finding

## Legal and contribution hygiene

- [x] Apache-2.0
- [x] No Autodesk proprietary content
- [x] No new fixtures

## Breaking changes

None. Without `SOURCE_DATE_EPOCH`, `rvt-ifc` writes what it wrote
before.

## Screenshots or output samples

With `SOURCE_DATE_EPOCH=1700000000` the header reads
`FILE_NAME('…','2023-11-14T22:13:20',…)` and the owner history ends
`,1700000000);`.

## Related issues

Refs #873 (S2)
Repository owner deleted a comment from chatgpt-codex-connector Bot Oct 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant