Skip to content

Commit 23aa7ae

Browse files
authored
@activity.defn support and other minor things (#16)
1 parent 256bc4a commit 23aa7ae

23 files changed

+441
-413
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
__pycache__
33
/build
44
/dist
5+
/docs/_autosummary
56
/docs/_build
67
temporalio/api/*
78
!temporalio/api/__init__.py

README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ import asyncio
125125
import logging
126126
from temporalio.client import Client
127127
from temporalio.worker import Worker
128+
from temporalio import activity
128129

130+
@activity.defn
129131
async def say_hello_activity(name: str) -> str:
130132
return f"Hello, {name}!"
131133

@@ -135,7 +137,7 @@ async def main(stop_event: asyncio.Event):
135137
client = await Client.connect("http://localhost:7233", namespace="my-namespace")
136138

137139
# Run the worker until the event is set
138-
worker = Worker(client, task_queue="my-task-queue", activities={"say-hello-activity": say_hello_activity})
140+
worker = Worker(client, task_queue="my-task-queue", activities=[say_hello_activity])
139141
async with worker:
140142
await stop_event.wait()
141143
```
@@ -148,6 +150,7 @@ Some things to note about the above code:
148150
* Activities are passed as a mapping with the key as a string activity name and the value as a callable
149151
* While this example accepts a stop event and uses `async with`, `run()` and `shutdown()` may be used instead
150152
* Workers can have many more options not shown here (e.g. data converters and interceptors)
153+
* A custom name for the activity can be set with a decorator argument, e.g. `@activity.defn(name="my activity")`
151154

152155
#### Types of Activities
153156

@@ -276,4 +279,14 @@ The Python SDK is built to work with Python 3.7 and newer. It is built using
276279

277280
```bash
278281
poe test
279-
```
282+
```
283+
284+
### Style
285+
286+
* Mostly [Google Style Guide](https://google.github.io/styleguide/pyguide.html). Notable exceptions:
287+
* We use [Black](https://github.com/psf/black) for formatting, so that takes precedence
288+
* In tests and example code, can import individual classes/functions to make it more readable. Can also do this for
289+
rarely in library code for some Python common items (e.g. `dataclass` or `partial`), but not allowed to do this for
290+
any `temporalio` packages or any classes/functions that aren't clear when unqualified.
291+
* We allow relative imports for private packages
292+
* We allow `@staticmethod`

docs/_static/temporal-logo-dark-mode.svg

Lines changed: 8 additions & 0 deletions
Loading

docs/_static/temporal-logo-light-mode.svg

Lines changed: 8 additions & 0 deletions
Loading
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
{{ fullname | escape | underline}}
3+
===============
4+
5+
.. automodule:: {{ fullname }}
6+
:members:
7+
8+
{% block modules %}
9+
{% if fullname != "temporalio.worker" %}
10+
{% if modules %}
11+
.. autosummary::
12+
:toctree:
13+
:template: custom_module_template.rst
14+
:recursive:
15+
{% for item in modules %}
16+
{{ item }}
17+
{%- endfor %}
18+
{% endif %}
19+
{% endif %}
20+
{% endblock %}

docs/api.rst

Lines changed: 0 additions & 42 deletions
This file was deleted.

docs/conf.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
# ones.
3131
extensions = [
3232
"sphinx.ext.autodoc",
33+
"sphinx.ext.autosummary",
3334
"sphinx.ext.intersphinx",
3435
"sphinx.ext.napoleon",
3536
]
@@ -54,12 +55,18 @@
5455
# relative to this directory. They are copied after the builtin static files,
5556
# so a file named "default.css" will overwrite the builtin "default.css".
5657
html_static_path = ["_static"]
58+
html_theme_options = {
59+
"light_logo": "temporal-logo-light-mode.svg",
60+
"dark_logo": "temporal-logo-dark-mode.svg",
61+
}
5762

5863
intersphinx_mapping = {
5964
"python": ("https://docs.python.org/3/", None),
6065
"protobuf": ("https://googleapis.dev/python/protobuf/latest/", None),
6166
}
6267

68+
html_title = "API Documentation"
69+
6370
autodoc_docstring_signature = True
6471

6572
autodoc_typehints = "description"
@@ -75,3 +82,5 @@
7582
autodoc_default_options = {
7683
"special-members": "__aenter__,__aexit__,__init__",
7784
}
85+
86+
autosummary_generate = True

docs/direct_api.rst

Lines changed: 0 additions & 69 deletions
This file was deleted.

docs/index.rst

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
1-
.. Temporal Python SDK documentation master file, created by
2-
sphinx-quickstart on Fri Feb 4 11:52:42 2022.
3-
You can adapt this file completely to your liking, but it should at least
4-
contain the root `toctree` directive.
51

6-
Temporal Python SDK
7-
===================
2+
Temporal Python SDK API Documentation
3+
=====================================
84

9-
.. toctree::
10-
:maxdepth: 2
11-
:caption: Contents:
5+
Modules
6+
-------
127

13-
api
14-
direct_api
8+
.. autosummary::
9+
:toctree: _autosummary
10+
:template: custom_module_template.rst
11+
:recursive:
1512

13+
temporalio.client
14+
temporalio.worker
15+
temporalio.activity
16+
temporalio.converter
17+
temporalio.exceptions
18+
temporalio.api
19+
temporalio.workflow_service
1620

1721

1822
Indices and tables
19-
==================
23+
------------------
2024

2125
* :ref:`genindex`
2226
* :ref:`modindex`

poetry.lock

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

0 commit comments

Comments
 (0)