Skip to content

Commit bef76a6

Browse files
authored
Even more convenient proto generation (#1039)
* Easier proto generation * Use JSON syntax for Dockerfile CMD
1 parent 70e5bea commit bef76a6

File tree

4 files changed

+41
-16
lines changed

4 files changed

+41
-16
lines changed

README.md

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1902,21 +1902,19 @@ poe test -s --log-cli-level=DEBUG -k test_sync_activity_thread_cancel_caught
19021902

19031903
#### Proto Generation and Testing
19041904

1905-
To allow for backwards compatibility, protobuf code is generated on the 3.x series of the protobuf library. To generate
1906-
protobuf code, you must be on Python <= 3.10, and then run `uv add "protobuf<4"` + `uv sync --all-extras`. Then the
1907-
protobuf files can be generated via `poe gen-protos`. Tests can be run for protobuf version 3 by setting the
1908-
`TEMPORAL_TEST_PROTO3` env var to `1` prior to running tests.
1909-
1910-
Do not commit `uv.lock` or `pyproject.toml` changes. To go back from this downgrade, restore both of those files and run
1911-
`uv sync --all-extras`. Make sure you `poe format` the results.
1912-
1913-
For a less system-intrusive approach, you can:
1914-
```shell
1915-
docker build -f scripts/_proto/Dockerfile .
1916-
docker run --rm -v "${PWD}/temporalio/api:/api_new" -v "${PWD}/temporalio/bridge/proto:/bridge_new" <just built image sha>
1917-
poe format
1905+
If you have docker available, run
1906+
1907+
```
1908+
poe gen-protos-docker
19181909
```
19191910

1911+
Alternatively: to generate protobuf code, you must be on Python <= 3.10, and then run `uv add
1912+
"protobuf<4"` + `uv sync --all-extras`. Then the protobuf files can be generated via `poe
1913+
gen-protos` followed by `poe format`. Do not commit `uv.lock` or `pyproject.toml` changes. To go
1914+
back from this downgrade, restore both of those files and run `uv sync --all-extras`. Tests can be
1915+
run for protobuf version 3 by setting the `TEMPORAL_TEST_PROTO3` env var to `1` prior to running
1916+
tests.
1917+
19201918
### Style
19211919

19221920
* Mostly [Google Style Guide](https://google.github.io/styleguide/pyguide.html). Notable exceptions:

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ dev = [
6464
build-develop = "uv run maturin develop --uv"
6565
build-develop-with-release = { cmd = "uv run maturin develop --release --uv" }
6666
format = [{cmd = "uv run ruff check --select I --fix"}, {cmd = "uv run ruff format"}, ]
67-
gen-docs = "uv run python scripts/gen_docs.py"
68-
gen-protos = "uv run python scripts/gen_protos.py"
67+
gen-docs = "uv run scripts/gen_docs.py"
68+
gen-protos = "uv run scripts/gen_protos.py"
69+
gen-protos-docker = "uv run scripts/gen_protos_docker.py"
6970
lint = [
7071
{cmd = "uv run ruff check --select I"},
7172
{cmd = "uv run ruff format --check"},

scripts/_proto/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ RUN uv add "protobuf<4"
1212
RUN uv sync --all-extras
1313
RUN poe gen-protos
1414

15-
CMD cp -r ./temporalio/api/* /api_new && cp -r ./temporalio/bridge/proto/* /bridge_new
15+
CMD ["sh", "-c", "cp -r ./temporalio/api/* /api_new && cp -r ./temporalio/bridge/proto/* /bridge_new"]

scripts/gen_protos_docker.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import os
2+
import subprocess
3+
4+
# Build the Docker image and capture its ID
5+
result = subprocess.run(
6+
["docker", "build", "-q", "-f", "scripts/_proto/Dockerfile", "."],
7+
capture_output=True,
8+
text=True,
9+
check=True,
10+
)
11+
image_id = result.stdout.strip()
12+
13+
subprocess.run(
14+
[
15+
"docker",
16+
"run",
17+
"--rm",
18+
"-v",
19+
f"{os.getcwd()}/temporalio/api:/api_new",
20+
"-v",
21+
f"{os.getcwd()}/temporalio/bridge/proto:/bridge_new",
22+
image_id,
23+
],
24+
check=True,
25+
)
26+
subprocess.run(["uv", "run", "poe", "format"], check=True)

0 commit comments

Comments
 (0)