Skip to content

Commit

Permalink
chore: migrate from poetry to uv for the sake of improving performanc…
Browse files Browse the repository at this point in the history
…e and dealing with conflicting sub-dependencies
  • Loading branch information
sassanh committed Oct 3, 2024
1 parent 9a2172d commit 65838c4
Show file tree
Hide file tree
Showing 8 changed files with 2,118 additions and 3,001 deletions.
174 changes: 60 additions & 114 deletions .github/workflows/integration_delivery.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,38 +27,18 @@ jobs:
python-version: ${{ env.PYTHON_VERSION }}
architecture: x64

- name: Install Poetry
uses: snok/install-poetry@v1
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
virtualenvs-create: true
enable-cache: true
cache-suffix: ubuntu-latest

- name: Check Cached Poetry
id: cached-poetry
uses: actions/cache/restore@v4
with:
lookup-only: true
path: |
~/.cache
~/.local
key:
poetry-ubuntu-latest-python${{ env.PYTHON_VERSION
}}-${{hashFiles('poetry.lock') }}

- name: Install dependencies
if: steps.cached-poetry.outputs.cache-hit != 'true'
- name: Create virtualenv
run: |
poetry install --no-interaction --no-root --extras=dev --with dev
uv venv --system-site-packages
- name: Save Cached Poetry
if: steps.cached-poetry.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: |
~/.cache
~/.local
key:
poetry-ubuntu-latest-python${{ env.PYTHON_VERSION
}}-${{hashFiles('poetry.lock') }}
- name: Install dependencies
run: uv sync --frozen

ubo-pod-dependencies:
name: Install Ubo Pod Dependencies
Expand All @@ -75,44 +55,19 @@ jobs:
echo "PYTHON_VERSION=$(python --version | cut -d' ' -f2)" >> $GITHUB_OUTPUT
echo "PYTHON_VERSION=$(python --version | cut -d' ' -f2)"
- name: Check Cached Poetry
id: cached-poetry
uses: actions/cache/restore@v4
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
lookup-only: true
path: |
~/.cache
~/.local
key:
poetry-ubo-pod-python${{
steps.get-python-version.outputs.PYTHON_VERSION }}-${{
hashFiles('poetry.lock') }}

- name: Install Poetry
if: steps.cached-poetry.outputs.cache-hit != 'true'
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
enable-cache: true
cache-suffix: ubo-pod

- name: Create virtualenv
run: |
uv venv --system-site-packages
- name: Install dependencies
if: steps.cached-poetry.outputs.cache-hit != 'true'
run: |
poetry env remove 3.11 || true
poetry config virtualenvs.options.system-site-packages true --local
poetry env use 3.11
poetry install --no-interaction --no-root --extras=dev --with dev
- name: Save Cached Poetry
if: steps.cached-poetry.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: |
~/.cache
~/.local
key:
poetry-ubo-pod-python${{
steps.get-python-version.outputs.PYTHON_VERSION }}-${{
hashFiles('poetry.lock') }}
uv sync --frozen
type-check:
name: Type Check
Expand All @@ -123,26 +78,23 @@ jobs:
- uses: actions/checkout@v4
name: Checkout

- name: Load Cached Poetry
id: cached-poetry
uses: actions/cache/restore@v4
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
path: |
~/.cache
~/.local
key:
poetry-ubo-pod-python${{
needs.ubo-pod-dependencies.outputs.python-version }}-${{
hashFiles('poetry.lock') }}
fail-on-cache-miss: true
enable-cache: true
cache-suffix: ubo-pod

- name: Create virtualenv
run: |
uv venv --system-site-packages
- name: Create stub files
run: |
poetry run pyright --createstub kivy
uv run --frozen pyright --createstub kivy
- name: Type Check
run: |
poetry run poe typecheck
uv run --frozen poe typecheck
lint:
name: Lint
Expand All @@ -159,20 +111,18 @@ jobs:
python-version: ${{ env.PYTHON_VERSION }}
architecture: x64

- name: Load Cached Poetry
id: cached-poetry
uses: actions/cache/restore@v4
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
path: |
~/.cache
~/.local
key:
poetry-ubuntu-latest-python${{ env.PYTHON_VERSION
}}-${{hashFiles('poetry.lock') }}
fail-on-cache-miss: true
enable-cache: true
cache-suffix: ubuntu-latest

- name: Create virtualenv
run: |
uv venv --system-site-packages
- name: Lint
run: poetry run poe lint
run: uv run --frozen poe lint

test:
name: Test
Expand Down Expand Up @@ -203,23 +153,21 @@ jobs:
python-version: ${{ env.PYTHON_VERSION }}
architecture: x64

- name: Load Cached Poetry
id: cached-poetry
uses: actions/cache/restore@v4
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
path: |
~/.cache
~/.local
key:
poetry-${{ startsWith(matrix.runner, 'ubo-pod') && 'ubo-pod' ||
'ubuntu-latest' }}-python${{ startsWith(matrix.runner, 'ubo-pod') &&
needs.ubo-pod-dependencies.outputs.python-version ||
env.PYTHON_VERSION }}-${{hashFiles('poetry.lock') }}
fail-on-cache-miss: true
enable-cache: true
cache-suffix:
${{ startsWith(matrix.runner, 'ubo-pod') && 'ubo-pod' ||
'ubuntu-latest' }}

- name: Create virtualenv
run: |
uv venv --system-site-packages
- name: Run Tests
run: |
poetry run poe test --verbosity=2 --make-screenshots --cov-report=xml --cov-report=html --log-level=DEBUG --log-cli-level=5 -n ${{ startsWith(matrix.runner, 'ubo-pod') && '1' || 'auto' }}
uv run --frozen poe test --verbosity=2 --make-screenshots --cov-report=xml --cov-report=html --log-level=DEBUG --log-cli-level=5 -n ${{ startsWith(matrix.runner, 'ubo-pod') && '1' || 'auto' }}
- name: Collect Window Screenshots
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -269,25 +217,23 @@ jobs:
python-version: ${{ env.PYTHON_VERSION }}
architecture: x64

- name: Load Cached Poetry
id: cached-poetry
uses: actions/cache/restore@v4
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
path: |
~/.cache
~/.local
key:
poetry-ubuntu-latest-python${{ env.PYTHON_VERSION
}}-${{hashFiles('poetry.lock') }}
fail-on-cache-miss: true
enable-cache: true
cache-suffix: ubuntu-latest

- name: Create virtualenv
run: |
uv venv --system-site-packages
- name: Extract Version
id: extract-version
run: |
echo "VERSION=$(poetry version --short)" >> "$GITHUB_OUTPUT"
echo "VERSION=$(poetry version --short)"
echo "NAME=$(poetry version | cut -d' ' -f1)" >> "$GITHUB_OUTPUT"
echo "NAME=$(poetry version | cut -d' ' -f1)"
echo "VERSION=$(uv run --frozen python -c 'from importlib.metadata import version; print(version("ubo_app"))')" >> "$GITHUB_OUTPUT"
echo "VERSION=$(uv run --frozen python -c 'from importlib.metadata import version; print(version("ubo_app"))')"
echo "NAME=$(uv run --frozen python -c 'from importlib.metadata import metadata; print(metadata("ubo_app")["Name"])')" >> "$GITHUB_OUTPUT"
echo "NAME=$(uv run --frozen python -c 'from importlib.metadata import metadata; print(metadata("ubo_app")["Name"])')"
- name: Extract Version from CHANGELOG.md
run: |
Expand Down Expand Up @@ -324,7 +270,7 @@ jobs:
cat ubo_app/.env
- name: Build
run: poetry build
run: uv build

- name: Upload wheel
uses: actions/upload-artifact@v4
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Upcoming

- chore: migrate from poetry to uv for the sake of improving performance and dealing with conflicting sub-dependencies

## Version 0.17.1

- feat(display): add `DisplayCompressedRenderEvent` as a compressed version of `DisplayRenderEvent`
Expand Down
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Be aware that at the moment, Ubo app sends crash reports to Sentry. Soon we will
- Easy headless remote access with SSH and VS Code tunnel
- Install and run Docker apps headlessly
- Access and control basic RPi utilities and settings
- gRPC API for remote control - find sample clients [here](https://github.com/ubopod/ubo-grpc-clients)

## 📋 Requirements

Expand Down Expand Up @@ -126,50 +127,50 @@ Contributions following Python best practices are welcome.

#### Setting up the development environment

To set up the development environment, you need to have Python 3.11+ and [`poetry`](https://python-poetry.org) installed.
To set up the development environment, you need to have Python 3.11+ and [`uv`](https://docs.astral.sh/uv/) installed.

First, clone the repository, then install the dependencies:

```bash
poetry install --with dev --extras=dev
uv install --with dev --extras=dev
```

Now you can run the app with:

```bash
poetry run ubo
uv run ubo
```

#### Running tests

Easiest way to run tests is to use the provided `Dockerfile`s. To run the tests in a container, you first need to create the development images by running:

```bash
poetry run poe build-docker-images
uv run poe build-docker-images
```

Then you can run the tests with:

```bash
docker run --rm -it --name ubo-app-test -v .:/ubo-app -v ubo-app-dev-pypoetry-cache:/root/.cache/pypoetry ubo-app-test
docker run --rm -it --name ubo-app-test -v .:/ubo-app -v ubo-app-dev-uv-cache:/root/.cache/uv ubo-app-test
```

You can add arguments to the `pytest` command to run specific tests like this:

```bash
docker run --rm -it --name ubo-app-test -v .:/ubo-app -v ubo-app-dev-pypoetry-cache:/root/.cache/pypoetry ubo-app-test -- <pytest-args>
docker run --rm -it --name ubo-app-test -v .:/ubo-app -v ubo-app-dev-uv-cache:/root/.cache/uv ubo-app-test -- <pytest-args>
```

For example, to run only the tests in the `tests/test_app.py` file, you can run:
For example, to run only the tests in the `tests/integration/test_core.py` file, you can run:

```bash
docker run --rm -it --name ubo-app-test -v .:/ubo-app -v ubo-app-dev-pypoetry-cache:/root/.cache/pypoetry ubo-app-test -- -n3 tests/test_some_test.py
docker run --rm -it --name ubo-app-test -v .:/ubo-app -v ubo-app-dev-uv-cache:/root/.cache/uv ubo-app-test -- -n3 tests/integration/test_core.py
```

You can also run the tests in your local environment by running:

```bash
poetry run poe test
uv run poe test
```

⚠️**Note:** When running the tests in your local environment, the window snapshots produced by tests may mismatch the expected snapshots. This is because the snapshots are taken with a certain DPI and some environments may have different DPI settings. For example, we are aware that the snapshots taken in macOS have different DPI settings. If you encounter this issue, you should run the tests in a Docker container as described above.
Expand Down
Loading

0 comments on commit 65838c4

Please sign in to comment.