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 #600

Merged
merged 11 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 3 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,9 @@ jobs:
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- run: python -m pip install --upgrade wheel poetry poethepoet
- run: poetry install --no-root
- uses: astral-sh/setup-uv@v5
- run: uv tool install poethepoet
- run: uv sync
- run: poe lint

build-php:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/php.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:

- name: Download docker artifacts
if: ${{ inputs.docker-image-artifact-name }}
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: ${{ inputs.docker-image-artifact-name }}
path: /tmp/server-docker
Expand Down
10 changes: 4 additions & 6 deletions .github/workflows/python.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- run: python -m pip install --upgrade wheel poetry poethepoet
- uses: astral-sh/setup-uv@v5

# Build SDK ==================================================
- name: Install Protoc
Expand All @@ -92,13 +92,11 @@ jobs:
if: ${{ inputs.version-is-repo-ref }}
with:
workspaces: sdk-python/temporalio/bridge
- run: poetry install --no-root
- uses: astral-sh/setup-uv@v5
- run: uv sync
if: ${{ inputs.version-is-repo-ref }}
working-directory: sdk-python
- run: poetry build
if: ${{ inputs.version-is-repo-ref }}
working-directory: sdk-python
- run: poe fix-wheel
- run: uv build
if: ${{ inputs.version-is-repo-ref }}
working-directory: sdk-python
# ============================================================
Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ Prerequisites:
- [Go](https://golang.org/) 1.17+
- [JDK](https://adoptium.net/?variant=openjdk11&jvmVariant=hotspot) 11+
- [Node](https://nodejs.org) 16+
- [Python](https://www.python.org/) 3.10+
- [Poetry](https://python-poetry.org/): `poetry install`
- `setuptools`: `python -m pip install -U setuptools`
- [uv](https://docs.astral.sh/uv/)
- [.NET](https://dotnet.microsoft.com) 7+
- [PHP](https://www.php.net/) 8.1+
- [Composer](https://getcomposer.org/)
Expand Down
7 changes: 3 additions & 4 deletions cmd/run_python.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@ func (p *Preparer) BuildPythonProgram(ctx context.Context) (sdkbuild.Program, er
}

prog, err := sdkbuild.BuildPythonProgram(ctx, sdkbuild.BuildPythonProgramOptions{
BaseDir: p.rootDir,
DirName: p.config.DirName,
Version: version,
DependencyName: "features",
BaseDir: p.rootDir,
DirName: p.config.DirName,
Version: version,
})
if err != nil {
return nil, fmt.Errorf("failed preparing: %w", err)
Expand Down
17 changes: 6 additions & 11 deletions dockerfiles/py.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ RUN wget -q -O - https://sh.rustup.rs | sh -s -- -y

ENV PATH="$PATH:/root/.cargo/bin"

# Install poetry
RUN pip install --no-cache-dir "poetry==1.2.2"
# Install uv
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/

WORKDIR /app

Expand All @@ -33,8 +33,7 @@ COPY go.mod go.sum main.go ./
# Build the CLI
RUN CGO_ENABLED=0 /usr/local/go/bin/go build -o temporal-features

# Copy poetry config
COPY poetry.lock pyproject.toml ./
COPY uv.lock pyproject.toml ./

ARG SDK_VERSION
ARG SDK_REPO_URL
Expand All @@ -44,23 +43,19 @@ ARG SDK_REPO_REF
ARG REPO_DIR_OR_PLACEHOLDER
COPY ./${REPO_DIR_OR_PLACEHOLDER} ./${REPO_DIR_OR_PLACEHOLDER}

# Prepare the feature for running. We need to use in-project venv so it is copied into smaller img.
ENV POETRY_VIRTUALENVS_IN_PROJECT=true
# Prepare the feature for running.
RUN CGO_ENABLED=0 ./temporal-features prepare --lang py --dir prepared --version "$SDK_VERSION"

# Copy the CLI and prepared feature to a smaller container for running
FROM python:3.11-slim-bullseye

# Poetry needed for running python tests
RUN pip install --no-cache-dir "poetry==1.2.2"

COPY --from=build /app/temporal-features /app/temporal-features
COPY --from=build /app/features /app/features
COPY --from=build /app/prepared /app/prepared
COPY --from=build /app/harness/python /app/harness/python
COPY --from=build /app/${REPO_DIR_OR_PLACEHOLDER} /app/${REPO_DIR_OR_PLACEHOLDER}
COPY --from=build /app/poetry.lock /app/pyproject.toml /app/
COPY --from=build /app/uv.lock /app/pyproject.toml /app/
COPY --from=build /bin/uv /bin/uvx /bin/

# Use entrypoint instead of command to "bake" the default command options
ENV POETRY_VIRTUALENVS_IN_PROJECT=true
ENTRYPOINT ["/app/temporal-features", "run", "--lang", "py", "--prepared-dir", "prepared"]
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ async def get_event_types(run_id: str) -> set[EventType.ValueType]:
update_event_types & await get_event_types(handle.first_execution_run_id)
), "Update should not appear in pre-CAN history"

assert update_event_types <= await get_event_types(
update_run_id
), "Update events should appear in post-CAN history"
assert update_event_types <= await get_event_types(update_run_id), (
"Update events should appear in post-CAN history"
)


register_feature(
Expand Down
1 change: 1 addition & 0 deletions features/data_converter/binary_protobuf/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

EXPECTED_RESULT = DataBlob(data=bytes.fromhex("deadbeef"))


# An echo workflow
@workflow.defn
class Workflow:
Expand Down
1 change: 1 addition & 0 deletions features/data_converter/codec/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

CODEC_ENCODING = "my_encoding"


# An echo workflow
@workflow.defn
class Workflow:
Expand Down
1 change: 1 addition & 0 deletions features/data_converter/json/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

EXPECTED_RESULT: Result = {"spec": True}


# An echo workflow
@workflow.defn
class Workflow:
Expand Down
1 change: 1 addition & 0 deletions features/data_converter/json_protobuf/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
EXPECTED_RESULT = DataBlob(data=bytes.fromhex("deadbeef"))
JSONP_decoder = JSONProtoPayloadConverter()


# An echo workflow
@workflow.defn
class Workflow:
Expand Down
6 changes: 3 additions & 3 deletions harness/python/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@ async def assert_eq_eventually(
if expected == last_value:
return
await asyncio.sleep(interval.total_seconds())
assert (
expected == last_value
), f"timed out waiting for equal, asserted against last value of {last_value}"
assert expected == last_value, (
f"timed out waiting for equal, asserted against last value of {last_value}"
)
Loading
Loading