Skip to content

Commit c965c47

Browse files
authored
gRPC Service Improvements (#106)
1 parent efc1c7b commit c965c47

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+4412
-878
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
run: |
5252
poe gen-protos
5353
poe format
54-
[[ -z $(git status --porcelain) ]] || (git status; echo "Protos changed"; exit 1)
54+
[[ -z $(git status --porcelain) ]] || (git diff; echo "Protos changed"; exit 1)
5555
5656
# Do docs stuff (only on one host)
5757
- name: Build API docs

README.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,6 @@ These steps can be followed to use with a virtual environment and `pip`:
5151
* Needed because older versions of `pip` may not pick the right wheel
5252
* Install Temporal SDK - `python -m pip install temporalio`
5353

54-
For macOS M1 users on Python 3.10+, due to an
55-
[improperly named wheel in PyPI for gRPC](https://github.com/grpc/grpc/issues/28387), you may have to run
56-
`pip install --no-binary :all: grpcio --ignore-installed` in your environment before use. (this is fixed in the next
57-
version of `temporalio` and in the `main` branch)
58-
5954
The SDK is now ready for use. To build from source, see "Building" near the end of this documentation.
6055

6156
**NOTE: This README is for the current branch and not necessarily what's released on `PyPI`.**

poetry.lock

Lines changed: 31 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ script = "build.py"
2525
"Bug Tracker" = "https://github.com/temporalio/sdk-python/issues"
2626

2727
[tool.poetry.dependencies]
28-
grpcio = "^1.47.0"
28+
grpcio = { version = "^1.48.0", optional = true }
2929
opentelemetry-api = { version = "^1.11.1", optional = true }
3030
opentelemetry-sdk = { version = "^1.11.1", optional = true }
3131
protobuf = "^3.20.1"
@@ -36,10 +36,11 @@ typing-extensions = "^4.2.0"
3636
[tool.poetry.dev-dependencies]
3737
black = "^22.3.0"
3838
cibuildwheel = "^2.7.0"
39-
grpcio-tools = "^1.47.0"
39+
grpcio-tools = "^1.48.0"
4040
isort = "^5.10.1"
4141
mypy = "^0.961"
4242
mypy-protobuf = "^3.2.0"
43+
protoc-wheel-0 = "^21.1"
4344
pydantic = "^1.9.1"
4445
pydocstyle = "^6.1.1"
4546
# TODO(cretz): Update when https://github.com/twisted/pydoctor/pull/595 released
@@ -48,13 +49,14 @@ pydoctor = { git = "https://github.com/cretz/pydoctor.git", branch = "overloads"
4849
pytest = "^7.1.2"
4950
pytest-asyncio = "^0.18.3"
5051
pytest-timeout = "^2.1.0"
51-
setuptools = "^62.3.3"
52+
setuptools = "^64.0.1"
5253
setuptools-rust = "^1.3.0"
5354
toml = "^0.10.2"
5455
twine = "^4.0.1"
5556

5657
[tool.poetry.extras]
5758
opentelemetry = ["opentelemetry-api", "opentelemetry-sdk"]
59+
grpc = ["grpc"]
5860

5961
[tool.poe.tasks]
6062
build-develop = ["build-bridge-develop"]
@@ -94,6 +96,7 @@ asyncio_mode = "auto"
9496
log_cli = true
9597
log_cli_level = "INFO"
9698
log_cli_format = "%(asctime)s [%(levelname)8s] %(message)s (%(filename)s:%(lineno)s)"
99+
testpaths = ["tests"]
97100
timeout = 600
98101
timeout_func_only = true
99102

@@ -158,4 +161,4 @@ sidebar-expand-depth = 2
158161

159162
[build-system]
160163
build-backend = "poetry.core.masonry.api"
161-
requires = ["poetry-core>=1.0.0", "setuptools", "wheel", "setuptools-rust"]
164+
requires = ["poetry-core>=1.0.0", "setuptools", "wheel", "setuptools-rust", "protoc-wheel-0"]

scripts/gen_protos.py

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,14 @@
1212
proto_dir = base_dir / "temporalio" / "bridge" / "sdk-core" / "protos"
1313
api_proto_dir = proto_dir / "api_upstream"
1414
core_proto_dir = proto_dir / "local"
15-
proto_paths = proto_dir.glob("**/*.proto")
15+
testsrv_proto_dir = proto_dir / "testsrv_upstream"
16+
17+
# Exclude testsrv dependencies
18+
proto_paths = (
19+
v
20+
for v in proto_dir.glob("**/*.proto")
21+
if not str(v).startswith(str(testsrv_proto_dir / "dependencies"))
22+
)
1623

1724
api_out_dir = base_dir / "temporalio" / "api"
1825
sdk_out_dir = base_dir / "temporalio" / "bridge" / "proto"
@@ -71,25 +78,39 @@ def fix_generated_output(base_path: Path):
7178
# Add docstring to API's init
7279
if str(base_path.as_posix()).endswith("/temporal/api"):
7380
f.write('"""gRPC API."""\n')
74-
# Imports
81+
# Non-gRPC imports
7582
message_names = []
7683
for stem, messages in imports.items():
77-
for message in messages:
78-
# MyPy protobuf does not document this experimental class, see
79-
# https://github.com/nipunn1313/mypy-protobuf/issues/212#issuecomment-885300106
80-
import_suffix = ""
81-
if stem == "service_pb2_grpc" and (
82-
message == "WorkflowService" or message == "OperatorService"
83-
):
84-
import_suffix = " # type: ignore"
85-
f.write(f"from .{stem} import {message}{import_suffix}\n")
86-
message_names.append(message)
84+
if stem != "service_pb2_grpc":
85+
for message in messages:
86+
f.write(f"from .{stem} import {message}\n")
87+
message_names.append(message)
8788
# __all__
8889
message_names = sorted(message_names)
8990
if message_names:
9091
f.write(
9192
f'\n__all__ = [\n "' + '",\n "'.join(message_names) + '",\n]\n'
9293
)
94+
# gRPC imports
95+
if "service_pb2_grpc" in imports:
96+
message_names = []
97+
f.write("\n# gRPC is optional\ntry:\n import grpc\n")
98+
for message in imports["service_pb2_grpc"]:
99+
# MyPy protobuf does not document this experimental class, see
100+
# https://github.com/nipunn1313/mypy-protobuf/issues/212#issuecomment-885300106
101+
import_suffix = ""
102+
if (
103+
message == "WorkflowService"
104+
or message == "OperatorService"
105+
or message == "TestService"
106+
):
107+
import_suffix = " # type: ignore"
108+
f.write(f" from .service_pb2_grpc import {message}{import_suffix}\n")
109+
message_names.append(message)
110+
# __all__
111+
message_names = sorted(message_names)
112+
f.write(f' __all__.extend(["' + '", "'.join(message_names) + '"])\n')
113+
f.write("except ImportError:\n pass")
93114

94115

95116
if __name__ == "__main__":
@@ -102,6 +123,7 @@ def fix_generated_output(base_path: Path):
102123
"-mgrpc_tools.protoc",
103124
f"--proto_path={api_proto_dir}",
104125
f"--proto_path={core_proto_dir}",
126+
f"--proto_path={testsrv_proto_dir}",
105127
f"--python_out={temp_dir}",
106128
f"--grpc_python_out={temp_dir}",
107129
f"--mypy_out={temp_dir}",

temporalio/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""Python SDK for Temporal."""
22

3-
from .workflow_service import __version__ as __sdk_version
3+
from .service import __version__ as __sdk_version
44

55
__version__ = __sdk_version

temporalio/api/command/v1/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
from .message_pb2 import (
2+
AcceptWorkflowUpdateCommandAttributes,
23
CancelTimerCommandAttributes,
34
CancelWorkflowExecutionCommandAttributes,
45
Command,
56
CompleteWorkflowExecutionCommandAttributes,
7+
CompleteWorkflowUpdateCommandAttributes,
68
ContinueAsNewWorkflowExecutionCommandAttributes,
79
FailWorkflowExecutionCommandAttributes,
810
RecordMarkerCommandAttributes,
@@ -16,10 +18,12 @@
1618
)
1719

1820
__all__ = [
21+
"AcceptWorkflowUpdateCommandAttributes",
1922
"CancelTimerCommandAttributes",
2023
"CancelWorkflowExecutionCommandAttributes",
2124
"Command",
2225
"CompleteWorkflowExecutionCommandAttributes",
26+
"CompleteWorkflowUpdateCommandAttributes",
2327
"ContinueAsNewWorkflowExecutionCommandAttributes",
2428
"FailWorkflowExecutionCommandAttributes",
2529
"RecordMarkerCommandAttributes",

0 commit comments

Comments
 (0)