Skip to content

feat(python): read a proto file's Python module from a file option - #311

Open
moetemp wants to merge 1 commit into
moe/up/oneof-record-casefrom
moe/up/python-proto-modules
Open

moetemp wants to merge 1 commit into
moe/up/oneof-record-casefrom
moe/up/python-proto-modules

Conversation

@moetemp

@moetemp moetemp commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

What changed?

This PR adds the nexus.python_module file option, in a new proto/nexus/options.proto that the crate includes. A .proto file that sets it names the Python module of its messages and enums. A file that doesn't keeps the module that nexgen derives from its path.

import "nexus/options.proto";

option (nexus.python_module) = "streamprotos.temporal.api.stream.v1.message_pb2";
  • prost_types::FileOptions drops extension fields, so nexgen reads the option from the raw descriptor bytes.
  • nexgen refuses a value that isn't a dotted Python module name.
  • The sample's three Stream protos import the options file and set the option. streams.bin, the Python and .NET bindings and the README's rebuild steps change with them.

In the stream sample's Python output, the models import the Stream protos from streamprotos.

Why?

By default, Python imports a temporal/... proto from temporalio, and the Stream protos of temporalio/api#895 aren't in a released temporalio. The module depends on where the protos are installed, so the protos name it, not each WIT binding. sdk-python doesn't need the option, since it generates those protos into temporalio itself.

How did you test it?

Link to a test plan if any -

  • Unit Tests
  • Staging
  • End to End Tests

Backend unit tests cover the module choice and the read of the raw option, and a rejection fixture covers a bad module name. test_stream_service.py round-trips each read item kind through the streamprotos classes, and basedpyright checks the stream service.

@moetemp
moetemp force-pushed the moe/up/python-proto-modules branch from fc0ccdc to 775b87d Compare October 27, 2026 18:35
@moetemp
moetemp force-pushed the moe/up/python-proto-modules branch 2 times, most recently from fec09fb to 92cfcc2 Compare October 28, 2026 16:37
This was referenced Oct 28, 2026
@moetemp
moetemp changed the base branch from main to moe/up/oneof-record-case October 28, 2026 22:57
@moetemp
moetemp force-pushed the moe/up/oneof-record-case branch 2 times, most recently from 7d98eab to a892bd7 Compare October 29, 2026 00:53
@moetemp
moetemp force-pushed the moe/up/python-proto-modules branch from 92cfcc2 to 81fd8c7 Compare October 29, 2026 04:00
@moetemp moetemp changed the title feat(python): map a proto file prefix to a local module feat(python): pick a proto message's module with python-import Oct 29, 2026
@moetemp
moetemp force-pushed the moe/up/oneof-record-case branch from a892bd7 to 5ae1c19 Compare October 29, 2026 06:28
@moetemp
moetemp force-pushed the moe/up/python-proto-modules branch from 81fd8c7 to 36a8328 Compare October 29, 2026 06:28
@moetemp moetemp changed the title feat(python): pick a proto message's module with python-import feat(python): read a proto file's Python module from a file option Oct 29, 2026
@moetemp
moetemp force-pushed the moe/up/oneof-record-case branch from 5ae1c19 to 2f6b64b Compare October 29, 2026 07:00
@moetemp
moetemp force-pushed the moe/up/python-proto-modules branch from 36a8328 to 2f28526 Compare October 29, 2026 07:00
@moetemp
moetemp force-pushed the moe/up/oneof-record-case branch from 2f6b64b to 4391281 Compare October 29, 2026 07:35
@moetemp
moetemp force-pushed the moe/up/python-proto-modules branch from 2f28526 to 2497fc5 Compare October 29, 2026 07:35
nexgen ships `proto/nexus/options.proto`, whose `nexus.python_module` file option names the
Python module of a file's messages and enums. nexgen reads it from the raw descriptor bytes,
since prost drops extension fields. The stream sample's protos set it, so Python imports them
from the sample's streamprotos package, and basedpyright checks the stream service.
@moetemp
moetemp force-pushed the moe/up/oneof-record-case branch from 4391281 to 3ff91ac Compare October 29, 2026 09:29
@moetemp
moetemp force-pushed the moe/up/python-proto-modules branch from 2497fc5 to 52b7104 Compare October 29, 2026 09:29
@moetemp
moetemp marked this pull request as ready for review October 29, 2026 09:42
@moetemp
moetemp requested a review from a team as a code owner October 29, 2026 09:42

This branch has not been deployed

No deployments
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