Skip to content

[MISC] Switch to uv #613

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .github/renovate.json5
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// MySQL 8.X does not follow semantic versioning (e.g. 8.0.1 -> 8.0.2 can include a breaking change)
// Therefore, use a separate Renovate group so that it has a separate PR
{
"matchManagers": ["poetry"],
"matchManagers": ["pep621"],
"matchPackageNames": ["mysql-connector-python"],
"groupName": "MySQL Connector/Python"
}
Expand Down
20 changes: 17 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,23 @@ on:
value: ${{ jobs.build.outputs.artifact-prefix }}

jobs:
# TODO install uv in reusable and re-enable
# lint:
# name: Lint
# uses: canonical/data-platform-workflows/.github/workflows/[email protected]
lint:
name: Lint
uses: canonical/data-platform-workflows/.github/workflows/[email protected]
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install tox & uv
run: |
pipx install tox
pipx install uv
- name: Run linters
run: tox run -e lint

unit-test:
name: Unit test charm
Expand All @@ -33,10 +47,10 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install tox & poetry
- name: Install tox & uv
run: |
pipx install tox
pipx install poetry
pipx install uv
- name: Run tests
run: tox run -e unit
- name: Upload Coverage to Codecov
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/integration_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ jobs:
- name: Set up environment
run: |
sudo snap install charmcraft --classic
pipx install tox poetry
pipx install tox
pipx install uv
- name: Collect spread jobs
id: collect-jobs
shell: python
Expand Down Expand Up @@ -100,7 +101,9 @@ jobs:
uses: actions/checkout@v4
- name: Set up environment
timeout-minutes: 5
run: sudo snap install charmcraft --classic
run: |
sudo snap install charmcraft --classic
sudo snap install astral-uv --classic
# TODO: remove when https://github.com/canonical/charmcraft/issues/2105 and
# https://github.com/canonical/charmcraft/issues/2130 fixed
- run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tiobe_scan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ jobs:
- name: Add pipx to PATH
run: echo "${HOME}/.local/bin" >> "${GITHUB_PATH}"

- name: Install tox and poetry using pipx
- name: Install tox and uv
run: |
pipx install tox
pipx install poetry
pipx install uv

- name: Run tox tests to create coverage.xml
run: tox run -e unit
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ this operator.
the `main` branch. This also avoids merge commits and creates a linear Git commit history.

## Developing
Install `tox`, `poetry`, and `charmcraftcache`
Install `tox`, `uv`, and `charmcraftcache`

Install pipx: https://pipx.pypa.io/stable/installation/
```shell
pipx install tox
pipx install poetry
pipx install uv
pipx install charmcraftcache
```

Expand Down
48 changes: 9 additions & 39 deletions charmcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,48 +14,20 @@ platforms:
# (https://github.com/canonical/charmcraft/blob/9ff19c328e23b50cc06f04e8a5ad4835740badf4/charmcraft/services/package.py#L290-L293
# https://github.com/canonical/charmcraft/blob/9ff19c328e23b50cc06f04e8a5ad4835740badf4/charmcraft/services/package.py#L156-L157)
parts:
# "poetry-deps" part name is a magic constant
# https://github.com/canonical/craft-parts/pull/901
poetry-deps:
plugin: nil
build-packages:
- curl
override-build: |
# Use environment variable instead of `--break-system-packages` to avoid failing on older
# versions of pip that do not recognize `--break-system-packages`
# `--user` needed (in addition to `--break-system-packages`) for Ubuntu >=24.04
PIP_BREAK_SYSTEM_PACKAGES=true python3 -m pip install --user --upgrade pip==24.3.1 # renovate: charmcraft-pip-latest

# Use uv to install poetry so that a newer version of Python can be installed if needed by poetry
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/astral-sh/uv/releases/download/0.5.15/uv-installer.sh | sh # renovate: charmcraft-uv-latest
# poetry 2.0.0 requires Python >=3.9
if ! "$HOME/.local/bin/uv" python find '>=3.9'
then
# Use first Python version that is >=3.9 and available in an Ubuntu LTS
# (to reduce the number of Python versions we use)
"$HOME/.local/bin/uv" python install 3.10.12 # renovate: charmcraft-python-ubuntu-22.04
fi
"$HOME/.local/bin/uv" tool install --no-python-downloads --python '>=3.9' poetry==2.0.0 --with poetry-plugin-export==1.8.0 # renovate: charmcraft-poetry-latest

ln -sf "$HOME/.local/bin/poetry" /usr/local/bin/poetry
# "charm-poetry" part name is arbitrary; use for consistency
# Avoid using "charm" part name since that has special meaning to charmcraft
charm-poetry:
# By default, the `poetry` plugin creates/stages these directories:
# - lib, src
# (https://github.com/canonical/charmcraft/blob/9ff19c328e23b50cc06f04e8a5ad4835740badf4/charmcraft/parts/plugins/_poetry.py#L76-L78)
# - venv
# (https://github.com/canonical/charmcraft/blob/9ff19c328e23b50cc06f04e8a5ad4835740badf4/charmcraft/parts/plugins/_poetry.py#L95
# https://github.com/canonical/craft-parts/blob/afb0d652eb330b6aaad4f40fbd6e5357d358de47/craft_parts/plugins/base.py#L270)
plugin: poetry
charm-uv:
plugin: uv
source: .
after:
- poetry-deps
poetry-export-extra-args: ['--only', 'main,charm-libs']
build-snaps:
- astral-uv
build-environment:
- UV_NO_BINARY: "true"
build-packages:
- libffi-dev # Needed to build Python dependencies with Rust from source
- libssl-dev # Needed to build Python dependencies with Rust from source
- pkg-config # Needed to build Python dependencies with Rust from source
uv-groups:
- charm
- libs
override-build: |
# Workaround for https://github.com/canonical/charmcraft/issues/2068
# rustup used to install rustc and cargo, which are needed to build Python dependencies with Rust from source
Expand All @@ -77,8 +49,6 @@ parts:
rustup default 1.83.0 # renovate: charmcraft-rust-latest

craftctl default
# Include requirements.txt in *.charm artifact for easier debugging
cp requirements.txt "$CRAFT_PART_INSTALL/requirements.txt"
# "files" part name is arbitrary; use for consistency
files:
plugin: dump
Expand Down
Loading
Loading