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

migrate from poetry to uv #4952

Merged
merged 10 commits into from
Mar 12, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"image": "mcr.microsoft.com/devcontainers/python:1-3.11-bookworm",
"postCreateCommand": "/bin/bash -c 'python -m pip install poetry && python -m poetry install & git clone https://github.com/reflex-dev/reflex-examples; wait'",
"postCreateCommand": "/bin/bash -c 'python -m pip install uv && python -m uv sync & git clone https://github.com/reflex-dev/reflex-examples; wait'",
"forwardPorts": [3000, 8000],
"portsAttributes": {
"3000": {
Expand Down
88 changes: 23 additions & 65 deletions .github/actions/setup_build_env/action.yml
Original file line number Diff line number Diff line change
@@ -1,95 +1,58 @@
# Entry conditions:
# - `setup/checkout` has already happened
# - working dir is the root directory of your project (e.g. `reflex/`).
# - You have a `poetry.lock` file in the root directory of your project
# - You have a `uv.lock` file in the root directory of your project
# - You have a `pyproject.toml` file in the root directory of your project
#
# Exit conditions:
# - Python of version `python-version` is ready to be invoked as `python`.
# - Poetry of version `poetry-version` is ready to be invoked as `poetry`.
# - If `run-poetry-install` is true, deps as defined in `pyproject.toml` will have been installed into the venv at `create-venv-at-path`.
# - Uv of version `uv-version` is ready to be invoked as `uv`.
# - If `run-uv-sync` is true, deps as defined in `pyproject.toml` will have been installed into the venv at `create-venv-at-path`.

name: 'Setup Reflex build environment'
description: 'Sets up Python, install poetry (cached), install project deps (cached)'
description: 'Sets up Python, install uv (cached), install project deps (cached)'
inputs:
python-version:
description: 'Python version setup'
required: true
poetry-version:
description: 'Poetry version to install'
uv-version:
description: 'Uv version to install'
required: false
default: '2.1.1'
run-poetry-install:
description: 'Whether to run poetry install on current dir'
default: '0.6.5'
run-uv-sync:
description: 'Whether to run uv sync on current dir'
required: false
default: false
create-venv-at-path:
description: 'Path to venv (if poetry install is enabled)'
description: 'Path to venv (if uv sync is enabled)'
required: false
default: '.venv'

runs:
using: 'composite'
steps:
- name: Set up Python ${{ inputs.python-version }}
uses: actions/setup-python@v5
- name: Install UV
uses: astral-sh/setup-uv@v5
with:
version: ${{ inputs.uv-version }}
python-version: ${{ inputs.python-version }}

# This is required for OS portability in presence of caching.
#
# The act of installing poetry has the side effect of adding
# poetry bin path to system path.
#
# But, if we get a cache hit on the poetry installation, we
# don't get this important side effect. As a result, bare calls
# to "poetry" fails.
- name: Prepare PATH env to include where poetry will be installed into
shell: bash
run: |
echo "~/.local/bin/" >> $GITHUB_PATH

- name: Restore cached poetry install
id: restore-poetry-cache
uses: actions/cache/restore@v4
with:
path: ~/.local
key: ${{ runner.os }}-python-${{ inputs.python-version }}-poetry-${{ inputs.poetry-version }}

- if: steps.restore-poetry-cache.outputs.cache-hit != 'true'
name: Install Poetry
uses: snok/install-poetry@v1
with:
version: ${{ inputs.poetry-version }}
virtualenvs-create: true
virtualenvs-in-project: true
virtualenvs-path: ${{ inputs.create-venv-at-path }}

- if: steps.restore-poetry-cache.outputs.cache-hit != 'true'
name: Save poetry install to cache
uses: actions/cache/save@v4
with:
path: ~/.local
key: ${{ steps.restore-poetry-cache.outputs.cache-primary-key }}
enable-cache: true
cache-dependency-glob: "uv.lock"

- name: Restore cached project python deps
id: restore-pydeps-cache
uses: actions/cache/restore@v4
with:
path: ${{ inputs.create-venv-at-path }}
key: ${{ runner.os }}-python-${{ inputs.python-version }}-pydeps-${{ hashFiles('**/poetry.lock') }}
key: ${{ runner.os }}-python-${{ inputs.python-version }}-pydeps-${{ hashFiles('**/uv.lock') }}

- if: ${{ inputs.run-poetry-install == 'true' && steps.restore-pydeps-cache.outputs.cache-hit != 'true' }}
name: Run poetry install (will get cached)
- if: ${{ inputs.run-uv-sync == 'true' && steps.restore-pydeps-cache.outputs.cache-hit != 'true' }}
name: Run uv sync (will get cached)
# We skip over installing the root package (the current project code under CI)
# Root package should not be cached - its content is not reflected in poetry.lock / cache key

# On Windows, it is scripts/activate. On Linux and MacOS, it is bin/activate
# Root package should not be cached - its content is not reflected in uv.lock / cache key
shell: bash
run: |
python -m venv ${{ inputs.create-venv-at-path }}
source ${{ inputs.create-venv-at-path }}/*/activate
poetry install --no-interaction --no-root
uv sync --all-extras --dev --no-install-project

- if: steps.restore-pydeps-cache.outputs.cache-hit != 'true'
name: Save Python deps to cache
Expand All @@ -98,16 +61,11 @@ runs:
path: ${{ inputs.create-venv-at-path }}
key: ${{ steps.restore-pydeps-cache.outputs.cache-primary-key }}

- if: ${{ inputs.run-poetry-install == 'true' }}
name: Run poetry install (root package)
- if: ${{ inputs.run-uv-sync == 'true' }}
name: Run uv sync (root package)
# Here we really install the root package (the current project code under CI).env:
# This should not be cached.
shell: bash
run: |
source ${{ inputs.create-venv-at-path }}/*/activate
poetry install --only-root --no-interaction
uv sync --all-extras --dev

- name: Install uv
shell: bash
run: |
poetry run pip install uv
42 changes: 16 additions & 26 deletions .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ jobs:
- uses: ./.github/actions/setup_build_env
with:
python-version: ${{ matrix.python-version }}
run-poetry-install: true
create-venv-at-path: .venv
run-uv-sync: true


- name: Clone Reflex Website Repo
uses: actions/checkout@v4
Expand All @@ -53,20 +53,20 @@ jobs:

- name: Install Requirements for reflex-web
working-directory: ./reflex-web
run: poetry run uv pip install -r requirements.txt
run: uv pip install -r requirements.txt
- name: Init Website for reflex-web
working-directory: ./reflex-web
run: poetry run reflex init
run: uv run reflex init
- name: Install LightHouse Pre-reqs / Run LightHouse
run: |
# Check that npm is home
npm -v
poetry run bash benchmarks/lighthouse.sh ./reflex-web prod
uv run bash benchmarks/lighthouse.sh ./reflex-web prod
env:
LHCI_GITHUB_APP_TOKEN: $
- name: Run Benchmarks
# Only run if the database creds are available in this context.
run: poetry run python benchmarks/benchmark_lighthouse.py "$GITHUB_SHA" ./integration/benchmarks/.lighthouseci
run: uv run python benchmarks/benchmark_lighthouse.py "$GITHUB_SHA" ./integration/benchmarks/.lighthouseci
env:
GITHUB_SHA: ${{ github.sha }}

Expand All @@ -82,15 +82,15 @@ jobs:
- uses: ./.github/actions/setup_build_env
with:
python-version: 3.12.8
run-poetry-install: true
create-venv-at-path: .venv
run-uv-sync: true

- name: Build reflex
run: |
poetry build
uv build
- name: Upload benchmark results
# Only run if the database creds are available in this context.
run:
poetry run python benchmarks/benchmark_package_size.py --os ubuntu-latest
uv run python benchmarks/benchmark_package_size.py --os ubuntu-latest
--python-version 3.12.8 --commit-sha "${{ github.sha }}" --pr-id "${{ github.event.pull_request.id }}"
--branch-name "${{ github.head_ref || github.ref_name }}"
--path ./dist
Expand All @@ -114,29 +114,19 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install Poetry
uses: snok/install-poetry@v1
- name: Install UV
uses: astral-sh/setup-uv@v5
with:
version: 1.3.1
virtualenvs-create: true
virtualenvs-in-project: true
virtualenvs-path: .venv

- name: Run poetry install
shell: bash
run: |
python -m venv .venv
source .venv/*/activate
poetry install --without dev --no-interaction --no-root
version: 0.6.5

- name: Install uv
- name: Run uv sync
shell: bash
run: |
poetry run pip install uv
uv install --no-install-project --no-dev

- name: calculate and upload size
run:
poetry run python benchmarks/benchmark_package_size.py --os "${{ matrix.os }}"
uv run python benchmarks/benchmark_package_size.py --os "${{ matrix.os }}"
--python-version "${{ matrix.python-version }}" --commit-sha "${{ github.sha }}"
--pr-id "${{ github.event.pull_request.id }}"
--branch-name "${{ github.head_ref || github.ref_name }}"
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/check_generated_pyi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ jobs:
- uses: ./.github/actions/setup_build_env
with:
python-version: "3.12.8"
run-poetry-install: true
create-venv-at-path: .venv
run-uv-sync: true
- run: |
poetry run python scripts/make_pyi.py
uv run python scripts/make_pyi.py
if [[ $(git status --porcelain) ]]; then
git status
git diff
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/check_node_latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ jobs:
- uses: ./.github/actions/setup_build_env
with:
python-version: ${{ matrix.python-version }}
run-poetry-install: true
create-venv-at-path: .venv
run-uv-sync: true

- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: |
poetry run uv pip install pyvirtualdisplay pillow pytest-split
poetry run playwright install --with-deps
uv pip install pyvirtualdisplay pillow pytest-split
uv run playwright install --with-deps
- run: |
poetry run pytest tests/test_node_version.py
poetry run pytest tests/integration --splits 2 --group ${{matrix.split_index}}
uv run pytest tests/test_node_version.py
uv run pytest tests/integration --splits 2 --group ${{matrix.split_index}}
18 changes: 9 additions & 9 deletions .github/workflows/check_outdated_dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ jobs:
- uses: ./.github/actions/setup_build_env
with:
python-version: '3.10'
run-poetry-install: true
create-venv-at-path: .venv
run-uv-sync: true


- name: Check outdated backend dependencies
run: |
outdated=$(poetry show -oT)
outdated=$(uv pip list --outdated)
echo "Outdated:"
echo "$outdated"

Expand All @@ -45,8 +45,8 @@ jobs:
- uses: ./.github/actions/setup_build_env
with:
python-version: "3.10.16"
run-poetry-install: true
create-venv-at-path: .venv
run-uv-sync: true

- name: Clone Reflex Website Repo
uses: actions/checkout@v4
with:
Expand All @@ -55,15 +55,15 @@ jobs:
path: reflex-web
- name: Install Requirements for reflex-web
working-directory: ./reflex-web
run: poetry run uv pip install $(grep -ivE "reflex " requirements.txt)
run: uv pip install $(grep -ivE "reflex " requirements.txt)
- name: Install additional dependencies for DB access
run: poetry run uv pip install psycopg
run: uv pip install psycopg
- name: Init Website for reflex-web
working-directory: ./reflex-web
run: poetry run reflex init
run: uv run reflex init
- name: Run Website and Check for errors
run: |
poetry run bash scripts/integration.sh ./reflex-web dev
uv run bash scripts/integration.sh ./reflex-web dev
- name: Check outdated frontend dependencies
working-directory: ./reflex-web/.web
run: |
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/integration_app_harness.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ jobs:
- uses: ./.github/actions/setup_build_env
with:
python-version: ${{ matrix.python-version }}
run-poetry-install: true
create-venv-at-path: .venv
- run: poetry run uv pip install pyvirtualdisplay pillow pytest-split pytest-retry
run-uv-sync: true

- run: uv pip install pyvirtualdisplay pillow pytest-split pytest-retry
- name: Run app harness tests
env:
REDIS_URL: ${{ matrix.state_manager == 'redis' && 'redis://localhost:6379' || '' }}
run: |
poetry run playwright install chromium
poetry run pytest tests/integration --retries 3 --maxfail=5 --splits 2 --group ${{matrix.split_index}}
uv run playwright install chromium
uv run pytest tests/integration --retries 3 --maxfail=5 --splits 2 --group ${{matrix.split_index}}
Loading
Loading