diff --git a/README.md b/README.md index a63e5e6d9..ec15d4408 100644 --- a/README.md +++ b/README.md @@ -1902,21 +1902,19 @@ poe test -s --log-cli-level=DEBUG -k test_sync_activity_thread_cancel_caught #### Proto Generation and Testing -To allow for backwards compatibility, protobuf code is generated on the 3.x series of the protobuf library. To generate -protobuf code, you must be on Python <= 3.10, and then run `uv add "protobuf<4"` + `uv sync --all-extras`. Then the -protobuf files can be generated via `poe gen-protos`. Tests can be run for protobuf version 3 by setting the -`TEMPORAL_TEST_PROTO3` env var to `1` prior to running tests. - -Do not commit `uv.lock` or `pyproject.toml` changes. To go back from this downgrade, restore both of those files and run -`uv sync --all-extras`. Make sure you `poe format` the results. - -For a less system-intrusive approach, you can: -```shell -docker build -f scripts/_proto/Dockerfile . -docker run --rm -v "${PWD}/temporalio/api:/api_new" -v "${PWD}/temporalio/bridge/proto:/bridge_new" -poe format +If you have docker available, run + +``` +poe gen-protos-docker ``` +Alternatively: to generate protobuf code, you must be on Python <= 3.10, and then run `uv add +"protobuf<4"` + `uv sync --all-extras`. Then the protobuf files can be generated via `poe +gen-protos` followed by `poe format`. Do not commit `uv.lock` or `pyproject.toml` changes. To go +back from this downgrade, restore both of those files and run `uv sync --all-extras`. Tests can be +run for protobuf version 3 by setting the `TEMPORAL_TEST_PROTO3` env var to `1` prior to running +tests. + ### Style * Mostly [Google Style Guide](https://google.github.io/styleguide/pyguide.html). Notable exceptions: diff --git a/pyproject.toml b/pyproject.toml index 3e2321fd0..77f31e2ad 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -64,8 +64,9 @@ dev = [ build-develop = "uv run maturin develop --uv" build-develop-with-release = { cmd = "uv run maturin develop --release --uv" } format = [{cmd = "uv run ruff check --select I --fix"}, {cmd = "uv run ruff format"}, ] -gen-docs = "uv run python scripts/gen_docs.py" -gen-protos = "uv run python scripts/gen_protos.py" +gen-docs = "uv run scripts/gen_docs.py" +gen-protos = "uv run scripts/gen_protos.py" +gen-protos-docker = "uv run scripts/gen_protos_docker.py" lint = [ {cmd = "uv run ruff check --select I"}, {cmd = "uv run ruff format --check"}, diff --git a/scripts/_proto/Dockerfile b/scripts/_proto/Dockerfile index 47f3c60dc..7617cbe1b 100644 --- a/scripts/_proto/Dockerfile +++ b/scripts/_proto/Dockerfile @@ -12,4 +12,4 @@ RUN uv add "protobuf<4" RUN uv sync --all-extras RUN poe gen-protos -CMD cp -r ./temporalio/api/* /api_new && cp -r ./temporalio/bridge/proto/* /bridge_new +CMD ["sh", "-c", "cp -r ./temporalio/api/* /api_new && cp -r ./temporalio/bridge/proto/* /bridge_new"] diff --git a/scripts/gen_protos_docker.py b/scripts/gen_protos_docker.py new file mode 100644 index 000000000..7014022bc --- /dev/null +++ b/scripts/gen_protos_docker.py @@ -0,0 +1,26 @@ +import os +import subprocess + +# Build the Docker image and capture its ID +result = subprocess.run( + ["docker", "build", "-q", "-f", "scripts/_proto/Dockerfile", "."], + capture_output=True, + text=True, + check=True, +) +image_id = result.stdout.strip() + +subprocess.run( + [ + "docker", + "run", + "--rm", + "-v", + f"{os.getcwd()}/temporalio/api:/api_new", + "-v", + f"{os.getcwd()}/temporalio/bridge/proto:/bridge_new", + image_id, + ], + check=True, +) +subprocess.run(["uv", "run", "poe", "format"], check=True)