Skip to content

Commit

Permalink
feat: Use uv instead of poetry
Browse files Browse the repository at this point in the history
uv is faster and simpler than poetry. It solves the issue of managing
different python version very conveniently. It is from the creators of
ruff.

https://github.com/astral-sh/uv
  • Loading branch information
rumpelsepp committed Oct 17, 2024
1 parent 96c717d commit 71673b1
Show file tree
Hide file tree
Showing 17 changed files with 1,464 additions and 2,404 deletions.
28 changes: 13 additions & 15 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,25 @@ jobs:

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5

- name: Install uv
uses: astral-sh/setup-uv@v3
with:
python-version: '3.11'
- uses: Gr1N/setup-poetry@v9
- uses: actions/cache@v4
enable-cache: true

- name: "Set up Python"
uses: actions/setup-python@v5
with:
path: ~/.cache/pypoetry/virtualenvs
key: ${{ runner.os }}-poetry-${{ hashFiles('poetry.lock') }}-${{ hashFiles('pyproject.toml') }}
python-version-file: ".python-version"

- name: Install Dependencies
- name: Install the project
run: |
poetry install
uv sync --all-extras --dev
- name: Invoke sphinx-build
run: |
poetry run make -C docs SPHINXOPTS="-W" html
uv run make -C docs SPHINXOPTS="-W" html
- name: Archive webpage
uses: actions/upload-artifact@v4
with:
Expand All @@ -51,12 +55,6 @@ jobs:
if: github.ref == 'refs/heads/master'

steps:
- uses: Gr1N/setup-poetry@v9
- uses: actions/cache@v4
with:
path: ~/.cache/pypoetry/virtualenvs
key: ${{ runner.os }}-poetry-${{ hashFiles('poetry.lock') }}

- name: Download all workflow run artifacts
uses: actions/download-artifact@v4

Expand Down
23 changes: 13 additions & 10 deletions .github/workflows/linters-win32.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,21 @@ jobs:

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- uses: Gr1N/setup-poetry@v9
- uses: actions/cache@v4

- name: Install uv
uses: astral-sh/setup-uv@v3
with:
path: ~/.cache/pypoetry/virtualenvs
key: ${{ runner.os }}-poetry-${{ hashFiles('poetry.lock') }}-${{ hashFiles('pyproject.toml') }}
enable-cache: true

- name: Install Dependencies
- name: Set up Python ${{ matrix.python-version }}
run: |
poetry install
uv python install ${{ matrix.python-version }}
uv python pin ${{ matrix.python-version }}
- name: Install the project
run: |
uv sync --all-extras --dev
- name: Run mypy
run: |
poetry run make lint-win32
uv run make lint-win32
34 changes: 20 additions & 14 deletions .github/workflows/linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:
pull_request:
paths:
- 'pyproject.toml'
- 'poetry.lock'
- 'uv.lock'
- '.github/**'
- 'src/**'
- 'tests/**'
Expand All @@ -29,27 +29,33 @@ jobs:

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- uses: Gr1N/setup-poetry@v9
- uses: actions/cache@v4

- name: Install uv
uses: astral-sh/setup-uv@v3
with:
path: ~/.cache/pypoetry/virtualenvs
key: ${{ runner.os }}-poetry-${{ hashFiles('poetry.lock') }}-${{ hashFiles('pyproject.toml') }}
enable-cache: true

- name: Set up Python ${{ matrix.python-version }}
run: |
uv python install ${{ matrix.python-version }}
uv python pin ${{ matrix.python-version }}
- name: Install Dependencies
- name: Install the project
run: |
poetry install
uv sync --all-extras --dev
- name: Run ruff
run: |
poetry run ruff check src tests
uv run ruff check src tests
- name: Run mypy
run: |
poetry run mypy src tests
uv run mypy src tests
- name: Run ruff format
run: |
poetry run ruff format --check src tests
uv run ruff format --check src tests
- name: Run reuse lint
run: |
poetry run reuse lint
uv run reuse lint
19 changes: 10 additions & 9 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,23 @@ jobs:

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5

- name: Install uv
uses: astral-sh/setup-uv@v3
with:
python-version: '3.11'
- uses: Gr1N/setup-poetry@v9
- uses: actions/cache@v4
enable-cache: true

- uses: actions/setup-python@v5
with:
path: ~/.cache/pypoetry/virtualenvs
key: ${{ runner.os }}-poetry-${{ hashFiles('poetry.lock') }}-${{ hashFiles('pyproject.toml') }}
python-version-file: ".python-version"

- name: Install Dependencies
- name: Install the project
run: |
poetry install
uv sync --all-extras
- name: Build package
run: |
poetry build
uv build
- name: Publish a Python distribution to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
43 changes: 28 additions & 15 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,24 @@ jobs:

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- uses: Gr1N/setup-poetry@v9
- uses: actions/cache@v4

- name: Install uv
uses: astral-sh/setup-uv@v3
with:
path: ~/.cache/pypoetry/virtualenvs
key: ${{ runner.os }}-poetry-${{ hashFiles('poetry.lock') }}-${{ hashFiles('pyproject.toml') }}
enable-cache: true

- name: Install Dependencies
- name: Set up Python ${{ matrix.python-version }}
run: |
poetry install
uv python install ${{ matrix.python-version }}
uv python pin ${{ matrix.python-version }}
- name: Install the project
run: |
uv sync --all-extras --dev
- name: Run pytest
run: |
poetry run make pytest
uv run make pytest
bats:
strategy:
Expand All @@ -52,14 +55,24 @@ jobs:

steps:
- uses: actions/checkout@v4
- uses: actions/cache@v4

- name: Install uv
uses: astral-sh/setup-uv@v3
with:
path: ~/.cache/pypoetry/virtualenvs
key: ${{ runner.os }}-poetry-${{ hashFiles('poetry.lock') }}-${{ hashFiles('pyproject.toml') }}
enable-cache: true

- name: Set up Python ${{ matrix.python-version }}
run: |
uv python install ${{ matrix.python-version }}
- name: Install Dependencies
run: |
apt-get update -y && apt-get install -y bats python3 python3-poetry jq zstd
poetry install
- name: Install the project
run: |
uv sync --all-extras --dev
- name: Run bats
run: |
poetry run make bats
uv run make bats
39 changes: 0 additions & 39 deletions .github/workflows/upload-artifacts.yml

This file was deleted.

1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12
File renamed without changes.
9 changes: 6 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ FROM debian:stable

LABEL org.opencontainers.image.authors="[email protected]"

RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y python3 python3-poetry
RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y pipx

WORKDIR /app/gallia
COPY . .
RUN ["poetry", "install"]

ENTRYPOINT [ "poetry", "run", "gallia" ]
ENV PATH="/root/.local/bin:$PATH"
RUN ["pipx", "install", "uv"]
RUN ["uv", "sync"]

ENTRYPOINT [ "uv", "run", "gallia" ]
34 changes: 12 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
default:
@echo "available targets:"
@echo ""
@echo " zipapp build a standalone python zipapp"
@echo " fmt run autoformatters"
@echo " lint run linters"
@echo " docs build docs"
Expand All @@ -15,49 +14,40 @@ default:
@echo " bats run bats end to end tests"
@echo " clean delete build artifacts"

.PHONY: zipapp
TEMPDIR = $(shell mktemp -d)
zipapp:
poetry build -f wheel
poetry run python -m pip install --target $(TEMPDIR) gallia dist/*.whl
poetry run python -m zipapp -o gallia.pyz -c -p "/usr/bin/env python3" -m "gallia.cli:main" $(TEMPDIR)
$(RM) -r $(TEMPDIR)

.PHONY: lint
lint:
mypy src tests
ruff check src tests
ruff format --check src tests
uv run mypy src tests
uv run ruff check src tests
uv run ruff format --check src tests
find tests/bats \( -iname "*.bash" -or -iname "*.bats" -or -iname "*.sh" \) | xargs shellcheck
reuse lint
uv run reuse lint

.PHONY: lint-win32
lint-win32:
mypy --platform win32 --exclude "gallia\/log\.py" --exclude "hr" src tests
ruff check src tests
uv run mypy --platform win32 --exclude "gallia\/log\.py" --exclude "hr" src tests
uv run ruff check src tests

.PHONY: fmt
fmt:
ruff check --fix-only src tests/pytest
ruff format src tests/pytest
uv run ruff check --fix-only src tests/pytest
uv run ruff format src tests/pytest
find tests/bats \( -iname "*.bash" -or -iname "*.bats" -or -iname "*.sh" \) | xargs shfmt -w

.PHONY: docs
docs:
$(MAKE) -C docs html
uv run $(MAKE) -C docs html

.PHONY: tests
tests: pytest bats

.PHONY: pytest
pytest:
python -m pytest -v --cov=$(PWD) --cov-report html tests/pytest
uv run python -m pytest -v --cov=$(PWD) --cov-report html tests/pytest

.PHONY: bats
bats:
./tests/bats/run_bats.sh
uv run ./tests/bats/run_bats.sh

.PHONY: clean
clean:
$(RM) gallia.pyz
$(MAKE) -C docs clean
uv run $(MAKE) -C docs clean
Loading

0 comments on commit 71673b1

Please sign in to comment.