Skip to content

Commit 41efd4d

Browse files
committed
Easier proto generation
1 parent a004faa commit 41efd4d

File tree

3 files changed

+32
-15
lines changed

3 files changed

+32
-15
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/gen_protos_docker.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import os
2+
import subprocess
3+
4+
subprocess.run(["docker", "build", "-f", "scripts/_proto/Dockerfile", "."])
5+
image_id = subprocess.check_output(["docker", "images", "-q"], text=True).split()[0]
6+
subprocess.run(
7+
[
8+
"docker",
9+
"run",
10+
"--rm",
11+
"-v",
12+
f"{os.getcwd()}/temporalio/api:/api_new",
13+
"-v",
14+
f"{os.getcwd()}/temporalio/bridge/proto:/bridge_new",
15+
image_id,
16+
]
17+
)
18+
subprocess.run(["uv", "run", "poe", "format"])

0 commit comments

Comments
 (0)