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 22, 2024
1 parent d4fe4de commit a3ea8ce
Show file tree
Hide file tree
Showing 26 changed files with 533 additions and 514 deletions.
166 changes: 77 additions & 89 deletions .github/workflows/integration_delivery.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ name: CI/CD

on:
push:
branches:
- main
tags:
- 'v*'
pull_request:
workflow_dispatch:

env:
PYTHON_VERSION: '3.11'
PYTHON_VERSION: '3.11.9'

jobs:
dependencies:
Expand All @@ -16,28 +20,22 @@ jobs:
- uses: actions/checkout@v4
name: Checkout

- name: Load Cached Poetry
id: cached-poetry
uses: actions/cache@v4
with:
path: |
~/.cache
~/.local
key: poetry-${{ hashFiles('poetry.lock') }}-${{ env.PYTHON_VERSION}}

- uses: actions/setup-python@v5
name: Setup Python
- name: Setup Python
uses: actions/setup-python@v5
with:
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

- name: Create virtualenv
run: |
uv venv --system-site-packages
- name: Install dependencies
run: poetry install --with dev
run: uv sync --frozen

type-check:
name: Type Check
Expand All @@ -48,23 +46,18 @@ jobs:
- uses: actions/checkout@v4
name: Checkout

- uses: actions/setup-python@v5
name: Setup Python
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
python-version: ${{ env.PYTHON_VERSION }}
architecture: x64
enable-cache: true

- name: Load Cached Poetry
id: cached-poetry
uses: actions/cache/restore@v4
with:
path: |
~/.cache
~/.local
key: poetry-${{ hashFiles('poetry.lock') }}-${{ env.PYTHON_VERSION}}
- name: Create virtualenv
run: |
uv venv --system-site-packages
- name: Type Check
run: poetry run poe typecheck
run: |
uv run --frozen poe typecheck
lint:
name: Lint
Expand All @@ -79,19 +72,14 @@ jobs:
uses: actions/setup-python@v5
with:
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-${{ hashFiles('poetry.lock') }}-${{ env.PYTHON_VERSION}}
enable-cache: true

- name: Lint
run: poetry run poe lint
run: uvx ruff check

test:
name: Test
Expand All @@ -109,19 +97,19 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
architecture: x64

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

- name: Create virtualenv
run: |
uv venv --system-site-packages
- name: Run Tests
run: poetry run poe test
run: |
uv run --frozen poe test --verbosity=2 --cov-report=xml --cov-report=html --log-level=DEBUG --log-cli-level=5
- name: Collect Store Snapshots
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -160,50 +148,47 @@ jobs:
name: Setup Python
with:
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-${{ hashFiles('poetry.lock') }}-${{ env.PYTHON_VERSION}}
enable-cache: true

- 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)"
git fetch --prune --unshallow
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
echo "VERSION=$(uvx hatch version)" >> "$GITHUB_OUTPUT"
echo "VERSION=$(uvx hatch version)"
echo "NAME=$(uvx hatch project metadata | jq -r .name)" >> "$GITHUB_OUTPUT"
echo "NAME=$(uvx hatch project metadata | jq -r .name)"
- name: Extract Version from CHANGELOG.md
run: |
VERSION_CHANGELOG=$(sed -n '3 s/## Version //p' CHANGELOG.md)
echo "VERSION_CHANGELOG=$VERSION_CHANGELOG"
if [ "${{ steps.extract-version.outputs.VERSION }}" != "$VERSION_CHANGELOG" ]; then
echo "Error: Version extracted from CHANGELOG.md does not match the version in pyproject.toml"
exit 1
FIRST_HEADER=$(sed -n '/## /s/## //p' CHANGELOG.md | head -n 1)
if [ "$FIRST_HEADER" == "Upcoming" ]; then
# Check the version coming from extract-version starts with of x.y.z.devn
if [[ "${{ steps.extract-version.outputs.VERSION }}" =~ ^[0-9]+\.[0-9]+\.[0-9]+\.dev[0-9]+ ]]; then
VERSION_CHANGELOG="This is a development version."
else
echo "Error: First header in CHANGELOG.md is 'Upcoming' but the version in pyproject.toml is not a development version."
exit 1
fi
else
echo "Versions are consistent."
fi
- name: Extract Version from Tag
if: startsWith(github.ref, 'refs/tags/v')
run: |
VERSION_TAG=$(sed 's/^v//' <<< ${{ github.ref_name }})
echo "VERSION_TAG=$VERSION_TAG"
if [ "${{ steps.extract-version.outputs.VERSION }}" != "$VERSION_TAG" ]; then
echo "Error: Version extracted from tag does not match the version in pyproject.toml"
exit 1
else
echo "Versions are consistent."
VERSION_CHANGELOG=$(echo $FIRST_HEADER | sed 's/Version //')
if [ "${{ steps.extract-version.outputs.VERSION }}" != "$VERSION_CHANGELOG" ]; then
echo "Error: Version extracted from CHANGELOG.md does not match the version in pyproject.toml"
exit 1
else
echo "Versions are consistent."
fi
fi
- name: Build
run: poetry build
run:
SETUPTOOLS_SCM_PRETEND_VERSION=${{
steps.extract-version.outputs.VERSION }} uv build

- name: Upload wheel
uses: actions/upload-artifact@v4
Expand All @@ -219,10 +204,12 @@ jobs:
path: dist/*.tar.gz
if-no-files-found: error

pypi-publish:
name: Publish to PyPI
publish:
name: Publish
if: >-
github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
github.event_name == 'push' && github.ref == 'refs/heads/main' ||
github.event_name == 'pull_request' && github.event.pull_request.base.ref
== 'main'
needs:
- type-check
- lint
Expand All @@ -231,7 +218,9 @@ jobs:
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/${{ needs.build.outputs.name }}
url:
https://pypi.org/project/${{ needs.build.outputs.name }}/${{
needs.build.outputs.version }}
permissions:
id-token: write
steps:
Expand All @@ -245,11 +234,10 @@ jobs:
name: binary
path: dist

- name: Publish package distributions to PyPI
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: dist
verbose: true

release:
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
Expand All @@ -259,7 +247,7 @@ jobs:
- lint
- test
- build
- pypi-publish
- publish
runs-on: ubuntu-latest
environment:
name: release
Expand All @@ -269,6 +257,9 @@ jobs:
permissions:
contents: write
steps:
- uses: actions/checkout@v4
name: Checkout

- name: Procure Wheel
uses: actions/download-artifact@v4
with:
Expand All @@ -281,9 +272,6 @@ jobs:
name: binary
path: artifacts

- uses: actions/checkout@v4
name: Checkout

- name: Extract Changelog
id: changelog
run: |
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ wheels/
*.manifest
*.spec

# Installer logs
# Installer Logs
pip-log.txt
pip-delete-this-directory.txt

Expand Down Expand Up @@ -99,3 +99,6 @@ ENV/

# mypy
.mypy_cache/

# hatch
redux/_version.py
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.18.0

- feat(autorun): add `auto_await` to `AutorunOptions` so that one can define an autorun/view as a decorator of a function without automatically awaiting its result, when `auto_await` is set to `False`, which activates the new behavior, the decorated function passes `asyncio.iscoroutinefunction` test, useful for certain libraries like quart
Expand Down
Loading

0 comments on commit a3ea8ce

Please sign in to comment.