Skip to content

fix(python): rewrite generated imports with protoletariat#207

Merged
scarmuega merged 1 commit into
mainfrom
fix/python-codegen-imports
May 20, 2026
Merged

fix(python): rewrite generated imports with protoletariat#207
scarmuega merged 1 commit into
mainfrom
fix/python-codegen-imports

Conversation

@scarmuega
Copy link
Copy Markdown
Member

Problem

The protobuf Python plugin emits absolute imports rooted at the proto package:

from utxorpc.v1alpha.cardano import cardano_pb2

These do not resolve once the code is packaged under utxorpc_spec (modules install as utxorpc_spec.utxorpc.*), so import utxorpc_spec... fails with ModuleNotFoundError: No module named 'utxorpc.v1alpha'utxorpc-spec 0.19.x is un-importable.

generate.yml already had a Fix python imports step, but it used BSD sed -i '' syntax which is invalid on the GNU/Linux runner — it silently never applied.

Fix

Replace the sed hack with protoletariat, which rewrites proto-generated imports to relative imports by inspecting the FileDescriptorSet — location-independent and correct for both v1alpha and v1beta. --exclude-google-imports leaves the well-known-type imports alone.

Also adds an import smoke-test (v1alpha + v1beta) so an un-importable package can't ship silently again.

Follow-up

Needs a new spec release (v0.19.2) to republish a working utxorpc-spec; then python-sdk#9 bumps to it.

The protobuf Python plugin emits absolute imports rooted at the proto package (from utxorpc.v1alpha...), which fail once the code is packaged under utxorpc_spec — making utxorpc-spec un-importable. The previous sed step used BSD 'sed -i ' syntax and silently no-op'd on the GNU/Linux runner.

Replace it with protoletariat, which rewrites proto-generated imports to relative imports (location-independent, both v1alpha and v1beta), and add an import smoke-test so a broken package cannot ship again.
@scarmuega
Copy link
Copy Markdown
Member Author

Verified by dispatching the standalone generate.yml on this branch (run 26179054318) — both Fix python imports (protoletariat) and Smoke-test python imports pass; import utxorpc_spec.utxorpc.v1alpha.sync.sync_pb2 and the v1beta equivalent both resolve.

Note: the pr-check.yml check on this PR shows startup_failure, but that is pre-existing and unrelated — every pr-check.yml run since 2026-05-19 fails the same way (on unrelated branches too). Cause: pr-check.yml declares permissions: contents: read, but it calls publish-all.yml whose publish-node job requires id-token: write; a reusable workflow cannot exceed the caller's permissions, so the run cannot start.

@scarmuega scarmuega merged commit d9586e5 into main May 20, 2026
1 check passed
@scarmuega scarmuega deleted the fix/python-codegen-imports branch May 20, 2026 17:43
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