From f3bc880b7e56f2684616109065bc7f6f4cd6ae9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexis=20M=C3=A9taireau?= Date: Mon, 6 Jan 2025 15:17:24 +0100 Subject: [PATCH] Update the github actions to support uv instead of poetry --- .github/workflows/build-deb.yml | 0 .github/workflows/build.yml | 7 +++--- .github/workflows/ci.yml | 39 +++++++++++++++++++-------------- dev_scripts/dangerzone-cli.bat | 2 +- dev_scripts/dangerzone.bat | 2 +- dev_scripts/env.py | 16 +++++--------- docs/developer/TESTING.md | 4 ++-- docs/developer/doit.md | 14 ++++++------ docs/developer/environments.md | 6 ++--- 9 files changed, 46 insertions(+), 44 deletions(-) create mode 100644 .github/workflows/build-deb.yml diff --git a/.github/workflows/build-deb.yml b/.github/workflows/build-deb.yml new file mode 100644 index 0000000..e69de29 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 35f9597..d7fd9c6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -85,16 +85,17 @@ jobs: id: cache-container-image uses: actions/cache@v4 with: - key: v3-${{ steps.date.outputs.date }}-${{ hashFiles('Dockerfile', 'dangerzone/conversion/common.py', 'dangerzone/conversion/doc_to_pixels.py', 'dangerzone/conversion/pixels_to_pdf.py', 'poetry.lock', 'gvisor_wrapper/entrypoint.py') }} + key: v3-${{ steps.date.outputs.date }}-${{ hashFiles('Dockerfile', 'dangerzone/conversion/common.py', 'dangerzone/conversion/doc_to_pixels.py', 'dangerzone/conversion/pixels_to_pdf.py', 'uv.lock', 'gvisor_wrapper/entrypoint.py') }} path: | share/container.tar.gz share/image-id.txt + - name: Install uv + uses: astral-sh/setup-uv@v5 - name: Build and push Dangerzone image if: ${{ steps.cache-container-image.outputs.cache-hit != 'true' }} run: | - sudo apt-get install -y python3-poetry - python3 ./install/common/build-image.py + uv run ./install/common/build-image.py echo ${{ github.token }} | podman login ghcr.io -u USERNAME --password-stdin gunzip -c share/container.tar.gz | podman load tag=$(cat share/image-id.txt) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ab30080..c714708 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,9 +36,9 @@ jobs: run: |- apt-get update apt-get install -y git make python3 --no-install-recommends - poetry install --only lint,test + uv sync --only-group test --only-group lint - name: Run linters to enforce code style - run: poetry run make lint + run: uv run make lint - name: Check that the QA script is up to date with the docs run: "./dev_scripts/qa.py --check-refs" @@ -59,16 +59,18 @@ jobs: id: cache-container-image uses: actions/cache@v4 with: - key: v3-${{ steps.date.outputs.date }}-${{ hashFiles('Dockerfile', 'dangerzone/conversion/common.py', 'dangerzone/conversion/doc_to_pixels.py', 'dangerzone/conversion/pixels_to_pdf.py', 'poetry.lock', 'gvisor_wrapper/entrypoint.py') }} + key: v3-${{ steps.date.outputs.date }}-${{ hashFiles('Dockerfile', 'dangerzone/conversion/common.py', 'dangerzone/conversion/doc_to_pixels.py', 'dangerzone/conversion/pixels_to_pdf.py', 'uv.lock', 'gvisor_wrapper/entrypoint.py') }} path: |- share/container.tar.gz share/image-id.txt + - name: Install uv + uses: astral-sh/setup-uv@v5 + - name: Build Dangerzone container image if: ${{ steps.cache-container-image.outputs.cache-hit != 'true' }} run: | - sudo apt-get install -y python3-poetry - python3 ./install/common/build-image.py + uv run ./install/common/build-image.py - name: Upload container image uses: actions/upload-artifact@v4 @@ -110,8 +112,9 @@ jobs: - uses: actions/setup-python@v5 with: python-version: "3.12" - - run: pip install poetry - - run: poetry install + - name: Install uv + uses: astral-sh/setup-uv@v5 + - run: uv sync - name: Restore cached tessdata uses: actions/cache/restore@v4 with: @@ -120,7 +123,7 @@ jobs: fail-on-cache-miss: true key: v1-tessdata-${{ hashFiles('./install/common/download-tessdata.py') }} - name: Run CLI tests - run: poetry run make test + run: uv run make test - name: Set up .NET CLI environment uses: actions/setup-dotnet@v4 with: @@ -131,7 +134,7 @@ jobs: run: wix extension add --global WixToolset.UI.wixext - name: Build the MSI installer # NOTE: This also builds the .exe internally. - run: poetry run .\install\windows\build-app.bat + run: uv run .\install\windows\build-app.bat - name: Upload MSI installer uses: actions/upload-artifact@v4 with: @@ -166,12 +169,14 @@ jobs: enableCrossOsArchive: true fail-on-cache-miss: true key: v1-tessdata-${{ hashFiles('./install/common/download-tessdata.py') }} - - run: pip install poetry - - run: poetry install + + - name: Install uv + uses: astral-sh/setup-uv@v5 + - run: uv sync - name: Run CLI tests - run: poetry run make test + run: uv run make test - name: Build macOS app - run: poetry run python ./install/macos/build-app.py + run: uv run ./install/macos/build-app.py - name: Upload macOS app uses: actions/upload-artifact@v4 with: @@ -227,7 +232,7 @@ jobs: - name: Restore container cache uses: actions/cache/restore@v4 with: - key: v3-${{ steps.date.outputs.date }}-${{ hashFiles('Dockerfile', 'dangerzone/conversion/common.py', 'dangerzone/conversion/doc_to_pixels.py', 'dangerzone/conversion/pixels_to_pdf.py', 'poetry.lock', 'gvisor_wrapper/entrypoint.py') }} + key: v3-${{ steps.date.outputs.date }}-${{ hashFiles('Dockerfile', 'dangerzone/conversion/common.py', 'dangerzone/conversion/doc_to_pixels.py', 'dangerzone/conversion/pixels_to_pdf.py', 'uv.lock', 'gvisor_wrapper/entrypoint.py') }} path: |- share/container.tar.gz share/image-id.txt @@ -334,7 +339,7 @@ jobs: - name: Restore container image uses: actions/cache/restore@v4 with: - key: v3-${{ steps.date.outputs.date }}-${{ hashFiles('Dockerfile', 'dangerzone/conversion/common.py', 'dangerzone/conversion/doc_to_pixels.py', 'dangerzone/conversion/pixels_to_pdf.py', 'poetry.lock', 'gvisor_wrapper/entrypoint.py') }} + key: v3-${{ steps.date.outputs.date }}-${{ hashFiles('Dockerfile', 'dangerzone/conversion/common.py', 'dangerzone/conversion/doc_to_pixels.py', 'dangerzone/conversion/pixels_to_pdf.py', 'uv.lock', 'gvisor_wrapper/entrypoint.py') }} path: |- share/container.tar.gz share/image-id.txt @@ -429,7 +434,7 @@ jobs: - name: Restore container image uses: actions/cache/restore@v4 with: - key: v3-${{ steps.date.outputs.date }}-${{ hashFiles('Dockerfile', 'dangerzone/conversion/common.py', 'dangerzone/conversion/doc_to_pixels.py', 'dangerzone/conversion/pixels_to_pdf.py', 'poetry.lock', 'gvisor_wrapper/entrypoint.py') }} + key: v3-${{ steps.date.outputs.date }}-${{ hashFiles('Dockerfile', 'dangerzone/conversion/common.py', 'dangerzone/conversion/doc_to_pixels.py', 'dangerzone/conversion/pixels_to_pdf.py', 'uv.lock', 'gvisor_wrapper/entrypoint.py') }} path: |- share/container.tar.gz share/image-id.txt @@ -470,4 +475,4 @@ jobs: # that the command in the Podman container can read the Xauthority # file successfully. xvfb-run -s '-ac' ./dev_scripts/env.py --distro ${{ matrix.distro }} --version ${{ matrix.version }} run --dev \ - bash -c 'cd dangerzone; poetry run make test' + bash -c 'cd dangerzone; uv run make test' diff --git a/dev_scripts/dangerzone-cli.bat b/dev_scripts/dangerzone-cli.bat index 9f4f4be..2781d76 100644 --- a/dev_scripts/dangerzone-cli.bat +++ b/dev_scripts/dangerzone-cli.bat @@ -1,2 +1,2 @@ set DANGERZONE_MODE=cli -uv run python .\dev_scripts\dangerzone %* +uv run .\dev_scripts\dangerzone %* diff --git a/dev_scripts/dangerzone.bat b/dev_scripts/dangerzone.bat index 3a2e272..9403b3d 100644 --- a/dev_scripts/dangerzone.bat +++ b/dev_scripts/dangerzone.bat @@ -1,2 +1,2 @@ set DANGERZONE_MODE=gui -uv run python .\dev_scripts\dangerzone %* +uv run .\dev_scripts\dangerzone %* diff --git a/dev_scripts/env.py b/dev_scripts/env.py index eecfba1..e2b3d68 100755 --- a/dev_scripts/env.py +++ b/dev_scripts/env.py @@ -116,7 +116,6 @@ RUN apt-get update \ && apt-get install -y --no-install-recommends dh-python make build-essential \ git {qt_deps} pipx python3 python3-pip python3-venv dpkg-dev debhelper python3-setuptools \ && rm -rf /var/lib/apt/lists/* -# NOTE: `pipx install poetry` fails on Ubuntu Focal, when installed through APT. By # installing the latest version, we sidestep this issue. RUN bash -c 'if [[ "$(pipx --version)" < "1" ]]; then \ apt-get update \ @@ -138,9 +137,8 @@ DOCKERFILE_BUILD_DEV_FEDORA_41_DEPS = r""" RUN dnf install -y python3.12 """ -# FIXME: Install Poetry on Fedora via package manager. DOCKERFILE_BUILD_DEV_FEDORA_DEPS = r""" -RUN dnf install -y git rpm-build podman python3 python3-devel python3-poetry-core \ +RUN dnf install -y git rpm-build podman python3 python3-devel uv \ pipx make qt6-qtbase-gui \ && dnf clean all @@ -179,14 +177,12 @@ VOLUME /home/user/dangerzone RUN mkdir -p /home/user/.config/containers COPY storage.conf /home/user/.config/containers -# Install Poetry under ~/.local/bin. -# See https://github.com/freedomofpress/dangerzone/issues/351 -# FIXME: pipx install poetry does not work for Ubuntu Focal. +# Install uv under ~/.local/bin. ENV PATH="$PATH:/home/user/.local/bin" -RUN pipx install poetry +RUN pipx install uv -COPY pyproject.toml poetry.lock /home/user/dangerzone/ -RUN cd /home/user/dangerzone && poetry --no-ansi install +COPY pyproject.toml uv.lock /home/user/dangerzone/ +RUN cd /home/user/dangerzone && uv sync """ DOCKERFILE_BUILD_DEBIAN_DEPS = r""" @@ -291,7 +287,7 @@ def get_build_dir_sources(distro, version): """Return the files needed to build an image.""" sources = [ git_root() / "pyproject.toml", - git_root() / "poetry.lock", + git_root() / "uv.lock", git_root() / "dev_scripts" / "storage.conf", git_root() / "dev_scripts" / "containers.conf", ] diff --git a/docs/developer/TESTING.md b/docs/developer/TESTING.md index 9cb8205..961f43a 100644 --- a/docs/developer/TESTING.md +++ b/docs/developer/TESTING.md @@ -9,7 +9,7 @@ The following assumes that you have already setup the development environment. Unit / integration tests are run with: ```bash -poetry run make test +uv run make test ``` ## Run large tests @@ -17,7 +17,7 @@ poetry run make test We also have a larger set of tests that can take a day or more to run, where we evaluate the completeness of Dangerzone conversions. ```bash -poetry run make test-large +uv run make test-large ``` ### Test report generation diff --git a/docs/developer/doit.md b/docs/developer/doit.md index a461d96..bd16e7e 100644 --- a/docs/developer/doit.md +++ b/docs/developer/doit.md @@ -24,26 +24,26 @@ We picked Doit out of the various tools out there for the following reasons: ## How to Doit? -First, enter your Poetry shell. Then, make sure that your environment is clean, -and you have ample disk space. You can run: +Make sure that your environment is clean, and you have ample disk space. You +can run: ```bash -doit clean --dry-run # if you want to see what would happen -doit clean # you'll be asked to cofirm that you want to clean everything +uv run doit clean --dry-run # if you want to see what would happen +uv run doit clean # you'll be asked to cofirm that you want to clean everything ``` Finally, you can build all the release artifacts with `doit`, or a specific task with: ``` -doit +uv run doit ``` ## Tips and tricks -* You can run `doit list --all -s` to see the full list of tasks, their +* You can run `uv run doit list --all -s` to see the full list of tasks, their dependencies, and whether they are up to date. -* You can run `doit info ` to see which dependencies are missing. +* You can run `uv run doit info ` to see which dependencies are missing. * You can change this line in `pyproject.toml` to `true`, to allow using the Docker/Podman build cache: diff --git a/docs/developer/environments.md b/docs/developer/environments.md index 2cc5b0a..333e91b 100644 --- a/docs/developer/environments.md +++ b/docs/developer/environments.md @@ -9,11 +9,11 @@ It supports two types of environments: 1. Dev environment. This environment has developer tools, necessary for Dangerzone, baked in. Also, it mounts the Dangerzone source under `/home/user/dangerzone` in the container. The developer can then run - Dangerzone from source, with `poetry run ./dev_scripts/dangerzone`. + Dangerzone from source, with `uv run ./dev_scripts/dangerzone`. 2. End-user environment. This environment has only Dangerzone installed in it, from the .deb/.rpm package that we have created. For convenience, it also has the Dangerzone source mounted under `/home/user/dangerzone`, but it lacks - Poetry and other build tools. The developer can run Dangerzone there with + uv and other build tools. The developer can run Dangerzone there with `dangerzone`. This environment is the most vanilla Dangerzone environment, and should be closer to the end user's environment, than the development environment. @@ -92,7 +92,7 @@ In order to build Dangerzone environments, the script uses the following inputs: * Dev environment: - Distro name and version. Together, these comprise the base container image. - - `poetry.lock` and `pyproject.toml`. Together, these comprise the build + - `uv.lock` and `pyproject.toml`. Together, these comprise the build context. * End-user environment: - Distro name and version. Together, these comprise the base container image.