Skip to content

Commit

Permalink
Migrate from poetry to uv (#560)
Browse files Browse the repository at this point in the history
* Migrate from poetry to uv

* Update docs

* Fix mypy

* Fix publishing

* Fix pyproject format

* Simplify workflows more
  • Loading branch information
KapJI authored Sep 13, 2024
1 parent 45d9e7d commit e83580e
Show file tree
Hide file tree
Showing 12 changed files with 1,083 additions and 1,676 deletions.
52 changes: 8 additions & 44 deletions .github/actions/install-deps/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,59 +9,23 @@ inputs:
runs:
using: "composite"
steps:
- name: Set up Python ${{ inputs.python-version }}
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}

- name: Setup environment
id: environment
shell: bash
run: |
PYTHON_USER_BASE="$(python -m site --user-base)"
echo "$PYTHON_USER_BASE/bin" >> $GITHUB_PATH
echo "pip-user-base=$PYTHON_USER_BASE" >> $GITHUB_OUTPUT
- name: Get poetry latest version
id: latest-versions
shell: bash
run: |
poetry_version=$(curl -s https://pypi.org/pypi/poetry/json | jq -r .info.version)
echo "poetry=$poetry_version" >> $GITHUB_OUTPUT
echo "Python user base: $(python -m site --user-base)"
- uses: actions/cache@v4
name: Cache Poetry
with:
path: ${{ steps.environment.outputs.pip-user-base }}
key: >
${{ format('pip-user-{0}-{1}-{2}',
runner.os,
inputs.python-version,
steps.latest-versions.outputs.poetry
) }}
- name: Install or update Poetry
shell: bash
run: |
pip install --user poetry==${{ steps.latest-versions.outputs.poetry }}
- name: Use local virtual environment
shell: bash
run: |
poetry config virtualenvs.create true --local
poetry config virtualenvs.in-project true --local
- name: Install uv
uses: yezz123/setup-uv@v4

- uses: actions/cache@v4
name: Cache Poetry dependencies
- name: Cache project dependencies
uses: actions/cache@v4
with:
path: ./.venv
key: deps-${{ runner.os }}-${{ inputs.python-version }}-${{ hashFiles('poetry.lock') }}
key: deps-${{ runner.os }}-${{ inputs.python-version }}-${{ hashFiles('uv.lock') }}
restore-keys: |
deps-${{ runner.os }}-${{ inputs.python-version }}-
- name: Install dependencies with Poetry
- name: Install dependencies with uv
shell: bash
run: |
poetry env use python3
poetry install
uv sync
2 changes: 1 addition & 1 deletion .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
dependencies:
- any: ["poetry.lock"]
- any: ["uv.lock"]
all: ["!**/*.py"]

documentation:
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,4 @@ jobs:
uses: ./.github/actions/install-deps

- name: Check if package builds
run: |
poetry build
run: uv build
13 changes: 5 additions & 8 deletions .github/workflows/linting-and-testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ on:
- master
pull_request:

env:
RUNS_ON: ubuntu-latest

jobs:
pre-commit:
name: Pre-commit
Expand All @@ -32,18 +29,18 @@ jobs:
path: ~/.cache/pre-commit/
key: >
${{ format('pre-commit-{0}-{1}-{2}',
env.RUNS_ON,
runner.os,
matrix.python-version,
hashFiles('.pre-commit-config.yaml')
) }}
restore-keys: |
pre-commit-${{ env.RUNS_ON }}-${{ matrix.python-version }}-
pre-commit-${{ env.RUNS_ON }}-
pre-commit-${{ runner.os }}-${{ matrix.python-version }}-
pre-commit-${{ runner.os }}-
- name: Run pre-commit on all files
run: |
poetry run pre-commit run --all-files --show-diff-on-failure --color=always
uv run pre-commit run --all-files --show-diff-on-failure --color=always
- name: Run python-typing-update
run: |
poetry run pre-commit run --hook-stage manual python-typing-update --all-files --show-diff-on-failure --color=always
uv run pre-commit run --hook-stage manual python-typing-update --all-files --show-diff-on-failure --color=always
15 changes: 5 additions & 10 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ on:
release:
types: [published]

env:
RUNS_ON: ubuntu-latest

jobs:
publish:
name: Publish
Expand All @@ -18,13 +15,11 @@ jobs:
- name: Prepare and install deps
uses: ./.github/actions/install-deps

- name: Set version
run: poetry version $(git describe --tags --abbrev=0 | sed -e "s/^v//")

- name: Build package
run: poetry build
run: uv build

- name: Publish to PyPI
run: |
poetry config pypi-token.pypi ${{ secrets.PYPI_TOKEN }}
poetry publish
env:
TWINE_USERNAME: "__token__"
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: uvx twine upload dist/*
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ __pycache__/
*.egg-info
/build/
/dist/

venv/
/.venv/
14 changes: 7 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,42 @@ repos:
hooks:
- id: black
name: black
entry: poetry run black
entry: uv run black
language: system
types: [python]
require_serial: true
- id: isort
name: isort
entry: poetry run isort
entry: uv run isort
language: system
types: [python]
require_serial: true
- id: mypy
name: mypy
entry: poetry run mypy
entry: uv run mypy
language: system
types: [python]
require_serial: true
- id: flake8
name: flake8
entry: poetry run flake8
entry: uv run flake8
language: system
types: [python]
- id: pylint
name: pylint
entry: poetry run pylint
entry: uv run pylint
language: system
types: [python]
require_serial: true
- id: pytest
name: pytest
language: system
entry: poetry run pytest
entry: uv run pytest
pass_filenames: false
always_run: true
- id: codespell
name: codespell
entry: poetry run codespell
entry: uv run codespell
language: system
pass_filenames: false
always_run: true
Expand Down
10 changes: 5 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ People _love_ thorough bug reports. I'm not even kidding.

## Use a Consistent Coding Style

Install [Poetry](https://python-poetry.org/docs/#installation) to setup the developer environment.
It uses [black](https://github.com/ambv/black) and [prettier](https://prettier.io/)
Install [uv](https://docs.astral.sh/uv/getting-started/installation/) and run `uv sync` to setup the developer environment.
We use [black](https://github.com/ambv/black) and [prettier](https://prettier.io/)
to make sure the code follows the style.

`pre-commit` can be used to run all checks with one command (see dedicated section below).
Expand All @@ -62,7 +62,7 @@ When writing unittests please follow the good practises like:

## Pre-commit

With Poetry installed, run `poetry install` in the repo root.
With uv installed, run `uv sync` in the repo root.
It will create a virtualenv with all required packages.

After that you can run [pre-commit](https://pre-commit.com/) with settings included in the
Expand All @@ -71,13 +71,13 @@ repository to have code style and linting checks.
Activate `pre-commit` git hook:

```console
$ poetry run pre-commit install
$ uv run pre-commit install
```

Now the pre-commit tests will be done every time you commit.

You can also run the tests on all repository files manually with this command:

```console
$ poetry run pre-commit run --all-files
$ uv run pre-commit run --all-files
```
Loading

0 comments on commit e83580e

Please sign in to comment.