Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uv + maturin migration #768

Merged
merged 38 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
829845e
uvx migrate-to-uv
dandavison Feb 15, 2025
4b14fb3
Reinstate comments
dandavison Jan 10, 2025
34ef739
Fix license: `poe build-develop` works
dandavison Feb 16, 2025
0bd94a9
Pin mypy
dandavison Feb 16, 2025
0dd9410
Migrate CI and README
dandavison Feb 16, 2025
c8c08bc
Revert build system changes
dandavison Feb 16, 2025
8a07c88
Fix type errors
dandavison Feb 16, 2025
dbb54e0
Pin pyright
dandavison Feb 16, 2025
ca4a8c5
Partial revert
dandavison Feb 16, 2025
e76eb5c
tool.uv package = false
dandavison Feb 16, 2025
58dd5a3
Use uv for poe tasks
dandavison Feb 16, 2025
00534fa
Use features branch
dandavison Feb 16, 2025
1a21c69
Get rid of single-test poe task
dandavison Feb 17, 2025
38f0064
Do not use `--no-install-project`.
dandavison Feb 16, 2025
c90f0a3
Migrate CI and README
dandavison Feb 16, 2025
1eeb976
Use maturin
dandavison Feb 16, 2025
6da07fe
s/temporalio.bridge.temporal_sdk_bridge/rg-replace temporal_sdk_bridge/
dandavison Feb 16, 2025
3c7ec74
maturin versions of commands
dandavison Feb 16, 2025
43d2a2f
Include temporalio
dandavison Feb 17, 2025
12ef4d4
Install maturin as a dev dependency
dandavison Feb 17, 2025
6935476
Need to explicitly install the rust extension now
dandavison Feb 17, 2025
222817f
Revert "s/temporalio.bridge.temporal_sdk_bridge/rg-replace temporal_s…
dandavison Feb 17, 2025
0d98712
Set module-name
dandavison Feb 17, 2025
a7f3b50
Get rid of fix-wheel hacks
dandavison Feb 17, 2025
a36040f
Use `uv tool` to install poe
dandavison Feb 17, 2025
de3b55e
Add Cargo.toml metadata
dandavison Feb 17, 2025
e7ea8f1
fixup uv.lock after rebase
dandavison Feb 18, 2025
670e0d2
TEMP: Remove warnings
dandavison Feb 18, 2025
6246db0
Get rid of redundant `uv build`
dandavison Feb 19, 2025
b114ccd
Smoke test
dandavison Feb 19, 2025
83a82ef
DEV: run build-binaries workflow
dandavison Feb 19, 2025
ba38732
Windows
dandavison Feb 19, 2025
bc54894
Revert "TEMP: Remove warnings"
dandavison Feb 19, 2025
962a055
MANIFEST.in is having no effect
dandavison Feb 19, 2025
805e674
Tweak wheel contents
dandavison Feb 19, 2025
40e21f2
Run entire test suite
dandavison Feb 19, 2025
ec4557f
Revert "Run entire test suite"
dandavison Feb 19, 2025
f730e85
Revert "DEV: run build-binaries workflow"
dandavison Feb 19, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions .github/workflows/build-binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,31 @@ jobs:
uses: Swatinem/rust-cache@v2
with:
workspaces: temporalio/bridge -> target

# Prepare
# Using fixed Poetry version until
# https://github.com/python-poetry/poetry/issues/7611 and
# https://github.com/python-poetry/poetry/pull/7694 are fixed
- run: python -m pip install --upgrade wheel "poetry==1.3.2" poethepoet
- run: poetry install --no-root --all-extras
- uses: astral-sh/setup-uv@v5
- run: uv sync --all-extras

# Add the source dist only for Linux x64 for now
- if: ${{ matrix.package-suffix == 'linux-amd64' }}
run: poetry build --format sdist
run: uv build --sdist

# Build and fix the wheel
- run: poetry run cibuildwheel --output-dir dist
- run: poe fix-wheel
# Build the wheel
- run: uv run cibuildwheel --output-dir dist

# Simple test
- run: poe test-dist-single
# Install the wheel in a new venv and run a test
- name: Test wheel
shell: bash
run: |
mkdir __test_wheel__
cd __test_wheel__
cp -r ../tests .
python -m venv .venv
bindir=bin
if [ "$RUNNER_OS" = "Windows" ]; then
bindir=Scripts
fi
./.venv/$bindir/pip install 'protobuf>=3.20' 'types-protobuf>=3.20' 'typing-extensions<5,>=4.2.0' pytest pytest_asyncio grpcio pydantic opentelemetry-api opentelemetry-sdk python-dateutil
./.venv/$bindir/pip install --no-index --find-links=../dist temporalio
./.venv/$bindir/python -m pytest -s -k test_workflow_hello

# Upload dist
- uses: actions/upload-artifact@v4
Expand Down
13 changes: 8 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ jobs:
# TODO(cretz): Can upgrade proto when https://github.com/arduino/setup-protoc/issues/99 fixed
version: "23.x"
repo-token: ${{ secrets.GITHUB_TOKEN }}
- run: python -m pip install --upgrade wheel poetry poethepoet
- run: poetry install --no-root --all-extras
- uses: astral-sh/setup-uv@v5
- run: uv tool install poethepoet
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we get rid of poe? Does uv offer simple ways to define tasks?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was just commenting on the same thing -- we'll be able to switch away from poe when uv includes a task runner, which it sounds to me like will happen in next few months.

- run: uv sync --all-extras
- run: poe bridge-lint
if: ${{ matrix.clippyLinter }}
- run: poe lint
Expand Down Expand Up @@ -82,8 +83,9 @@ jobs:
env:
TEMPORAL_TEST_PROTO3: 1
run: |
poetry add --python 3.9 "protobuf<4"
poetry install --no-root --all-extras
uv add --python 3.9 "protobuf<4"
uv sync --all-extras
poe build-develop
poe gen-protos
poe format
[[ -z $(git status --porcelain temporalio) ]] || (git diff temporalio; echo "Protos changed"; exit 1)
Expand All @@ -107,8 +109,9 @@ jobs:

# Runs the sdk features repo tests with this repo's current SDK code
features-tests:
uses: temporalio/features/.github/workflows/python.yaml@main
uses: temporalio/features/.github/workflows/python.yaml@uv
with:
python-repo-path: ${{github.event.pull_request.head.repo.full_name}}
version: ${{github.event.pull_request.head.ref}}
version-is-repo-ref: true
features-repo-ref: uv
5 changes: 3 additions & 2 deletions .github/workflows/run-bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ jobs:
version: "23.x"
repo-token: ${{ secrets.GITHUB_TOKEN }}

- uses: astral-sh/setup-uv@v5
# Build
- run: python -m pip install --upgrade wheel poetry poethepoet
- run: poetry install --no-root --all-extras
- run: uv tool install poethepoet
- run: uv sync --all-extras
- run: poe build-develop-with-release

# Run a bunch of bench tests. We run multiple times since results vary.
Expand Down
57 changes: 22 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1390,28 +1390,27 @@ The Python SDK is built to work with Python 3.9 and newer. It is built using

To build the SDK from source for use as a dependency, the following prerequisites are required:

* [Python](https://www.python.org/) >= 3.9
* Make sure the latest version of `pip` is in use
* [uv](https://docs.astral.sh/uv/)
* [Rust](https://www.rust-lang.org/)
* [Protobuf Compiler](https://protobuf.dev/)
* [poetry](https://github.com/python-poetry/poetry) (e.g. `python -m pip install poetry`)
* [poe](https://github.com/nat-n/poethepoet) (e.g. `python -m pip install poethepoet`)

macOS note: If errors are encountered, it may be better to install Python and Rust as recommended from their websites
instead of via `brew`.
Use `uv` to install `poe`:

With the prerequisites installed, first clone the SDK repository recursively:
```bash
uv tool install poethepoet
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll probably switch away from poe when uv includes a task runner.

```

Now clone the SDK repository recursively:

```bash
git clone --recursive https://github.com/temporalio/sdk-python.git
cd sdk-python
```

Use `poetry` to install the dependencies with `--no-root` to not install this package (because we still need to build
it):
Install the dependencies:

```bash
poetry install --no-root --all-extras
uv sync --all-extras
```

#### Build
Expand All @@ -1422,16 +1421,11 @@ Now perform the release build:
environment](#local-sdk-development-environment) for the quicker approach to local development).

```bash
poetry build
uv build
```

The compiled wheel doesn't have the exact right tags yet for use, so run this script to fix it:

```bash
poe fix-wheel
```

The `whl` wheel file in `dist/` is now ready to use.
The `.whl` wheel file in `dist/` is now ready to use.

#### Use

Expand Down Expand Up @@ -1487,22 +1481,15 @@ It should output:

### Local SDK development environment

For local development, it is often quicker to use debug builds and a local virtual environment.

While not required, it often helps IDEs if we put the virtual environment `.venv` directory in the project itself. This
can be configured system-wide via:

```bash
poetry config virtualenvs.in-project true
```
For local development, it is quicker to use a debug build.

Now perform the same steps as the "Prepare" section above by installing the prerequisites, cloning the project,
installing dependencies, and generating the protobuf code:
Perform the same steps as the "Prepare" section above by installing the prerequisites, cloning the project, and
installing dependencies:

```bash
git clone --recursive https://github.com/temporalio/sdk-python.git
cd sdk-python
poetry install --no-root --all-extras
uv sync --all-extras
```

Now compile the Rust extension in develop mode which is quicker than release mode:
Expand Down Expand Up @@ -1535,14 +1522,14 @@ 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 `poetry add "protobuf<4"` +
`poetry install --no-root --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.
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 `poetry.lock` or `pyproject.toml` changes. To go back from this downgrade, restore both of those files
and run `poetry install --no-root --all-extras`. Make sure you `poe format` the results.
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 (note this approach [may have a bug](https://github.com/temporalio/sdk-python/issues/543)):
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" <just built image sha>
Expand All @@ -1552,7 +1539,7 @@ poe format
### Style

* Mostly [Google Style Guide](https://google.github.io/styleguide/pyguide.html). Notable exceptions:
* We use [Black](https://github.com/psf/black) for formatting, so that takes precedence
* We use [ruff](https://docs.astral.sh/ruff/) for formatting, so that takes precedence
* In tests and example code, can import individual classes/functions to make it more readable. Can also do this for
rarely in library code for some Python common items (e.g. `dataclass` or `partial`), but not allowed to do this for
any `temporalio` packages (except `temporalio.types`) or any classes/functions that aren't clear when unqualified.
Expand Down
28 changes: 0 additions & 28 deletions build.py

This file was deleted.

Loading
Loading