Skip to content
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

♻️ Migrate Pydantic Extra Types to use uv #241

Merged
merged 10 commits into from
Nov 26, 2024
Merged
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
94 changes: 60 additions & 34 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,60 +8,90 @@ on:
- '**'
pull_request: {}

env:
COLUMNS: 150

jobs:
lint:
runs-on: ubuntu-latest

strategy:
fail-fast: false
steps:
- uses: actions/checkout@v4

- name: set up python
uses: actions/setup-python@v5
- uses: astral-sh/setup-uv@v3
with:
python-version: '3.10'
enable-cache: true

- name: install
run: |
pip install -r requirements/pyproject.txt && pip install -r requirements/linting.txt
- name: Install dependencies
run: uv sync --python 3.12 --group lint --all-extras

- uses: pre-commit/action@v3.0.1
- uses: pre-commit/action@v3.0.0
with:
extra_args: --all-files --verbose
env:
SKIP: no-commit-to-branch

test:
name: test py${{ matrix.python-version }} on ${{ matrix.os }}
name: test py${{ matrix.python-version }}
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
os: [ubuntu, macos, windows]
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']

env:
UV_PYTHON: ${{ matrix.python-version }}

runs-on: ${{ matrix.os }}-latest
steps:
- uses: actions/checkout@v4

- name: set up python
uses: actions/setup-python@v5
- uses: astral-sh/setup-uv@v3
with:
python-version: ${{ matrix.python-version }}
enable-cache: true

- run: |
pip install -r requirements/pyproject.txt && pip install -r requirements/testing.txt
- name: Install dependencies
run: uv sync --extra all

- run: pip freeze
- name: Make coverage directory
run: mkdir coverage

- run: make test
- run: uv run --frozen coverage run -m pytest
env:
CONTEXT: ${{ runner.os }}-py${{ matrix.python-version }}-with-deps
COVERAGE_FILE: coverage/.coverage.${{ runner.os }}-py${{ matrix.python-version }}

- name: store coverage files
uses: actions/upload-artifact@v4
with:
name: coverage-${{ matrix.python-version }}
path: coverage
include-hidden-files: true

coverage:
runs-on: ubuntu-latest
needs: [test]
steps:
- uses: actions/checkout@v4

- uses: astral-sh/setup-uv@v3
with:
enable-cache: true

- run: coverage xml
- uses: codecov/codecov-action@v4
- name: get coverage files
uses: actions/download-artifact@v4
with:
merge-multiple: true
path: coverage

- run: uv run --frozen coverage combine coverage

- run: uv run --frozen coverage report --fail-under 85

# https://github.com/marketplace/actions/alls-green#why used for branch protection checks
check:
if: always()
needs: [lint, test]
needs: [lint, test, coverage]
runs-on: ubuntu-latest
steps:
- name: Decide whether the needed jobs succeeded or failed
Expand All @@ -70,7 +100,6 @@ jobs:
jobs: ${{ toJSON(needs) }}

release:
name: Release
needs: [check]
if: "success() && startsWith(github.ref, 'refs/tags/')"
runs-on: ubuntu-latest
Expand All @@ -82,21 +111,18 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: set up python
uses: actions/setup-python@v5
- uses: astral-sh/setup-uv@v3
with:
python-version: '3.10'

- name: install
run: pip install -U build
enable-cache: true

- name: check GITHUB_REF matches package version
uses: samuelcolvin/check-python-version@v4.1
with:
version_file_path: pydantic_extra_types/__init__.py
version_file_path: pyproject.toml

- name: build
run: python -m build
- run: uv build

- name: Upload package to PyPI
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
skip-existing: true
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ venv/
.venv/
env3*/
Pipfile
*.lock
*.py[cod]
*.egg-info/
.python-version
/build/
dist/
.cache/
.mypy_cache/
test.py
.coverage
.hypothesis
/htmlcov/
/site/
/site.zip
Expand All @@ -24,5 +23,4 @@ _build/
/sandbox/
/.ghtopdep_cache/
/worktrees/
.ruff_cache/
.python-version
/.ruff_cache/
30 changes: 16 additions & 14 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.3.0
hooks:
- id: no-commit-to-branch # prevent direct commits to the `main` branch
- id: check-yaml
args: ['--unsafe']
- id: check-toml
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: local
hooks:
- id: lint
name: Lint
entry: make lint
types: [python]
language: system
pass_filenames: false
- id: mypy
name: Mypy
entry: make mypy
types: [python]
language: system
pass_filenames: false
- id: format
name: Format
entry: make
args: [format]
language: system
types: [python]
pass_filenames: false
- id: lint
name: Lint
entry: make
args: [lint]
types: [python]
language: system
pass_filenames: false
93 changes: 36 additions & 57 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,70 +1,49 @@
.DEFAULT_GOAL := all
sources = pydantic_extra_types tests

.PHONY: install
install:
python -m pip install -U pip
pip install -r requirements/all.txt
pip install -e .
.PHONY: .uv # Check that uv is installed
.uv:
@uv --version || echo 'Please install uv: https://docs.astral.sh/uv/getting-started/installation/'

.PHONY: refresh-lockfiles
refresh-lockfiles:
@echo "Updating requirements/*.txt files using pip-compile"
find requirements/ -name '*.txt' ! -name 'all.txt' -type f -delete
pip-compile -q --no-emit-index-url --resolver backtracking -o requirements/linting.txt requirements/linting.in
pip-compile -q --no-emit-index-url --resolver backtracking -o requirements/testing.txt requirements/testing.in
pip-compile -q --no-emit-index-url --resolver backtracking --extra all -o requirements/pyproject.txt pyproject.toml
pip install --dry-run -r requirements/all.txt
.PHONY: install ## Install the package, dependencies, and pre-commit for local development
install: .uv
uv sync --frozen --group all --all-extras
uv pip install pre-commit
pre-commit install --install-hooks

.PHONY: format
.PHONY: rebuild-lockfiles ## Rebuild lockfiles from scratch, updating all dependencies
rebuild-lockfiles: .uv
uv lock --upgrade

.PHONY: format # Format the code
format:
ruff check --fix $(sources)
ruff format $(sources)
uv run ruff format
uv run ruff check --fix --fix-only

.PHONY: lint
.PHONY: lint # Lint the code
lint:
ruff check $(sources)
ruff format --check $(sources)

.PHONY: mypy
mypy:
mypy pydantic_extra_types
uv run ruff format --check
uv run ruff check

.PHONY: test
test:
coverage run -m pytest --durations=10

.PHONY: testcov
testcov: test
@echo "building coverage html"
@coverage html

.PHONY: testcov-compile
testcov-compile: build-trace test
@echo "building coverage html"
@coverage html
uv run pytest

.PHONY: test-all-python # Run tests on Python 3.9 to 3.13
test-all-python:
UV_PROJECT_ENVIRONMENT=.venv39 uv run --python 3.9 coverage run -p -m pytest
UV_PROJECT_ENVIRONMENT=.venv310 uv run --python 3.10 coverage run -p -m pytest
UV_PROJECT_ENVIRONMENT=.venv311 uv run --python 3.11 coverage run -p -m pytest
UV_PROJECT_ENVIRONMENT=.venv312 uv run --python 3.12 coverage run -p -m pytest
UV_PROJECT_ENVIRONMENT=.venv313 uv run --python 3.13 coverage run -p -m pytest
@uv run coverage combine
@uv run coverage report

.PHONY: testcov # Run tests and collect coverage data
testcov:
uv run coverage run -m pytest
@uv run coverage report
@uv run coverage html

.PHONY: all
all: lint mypy testcov

.PHONY: clean
clean:
rm -rf `find . -name __pycache__`
rm -f `find . -type f -name '*.py[co]'`
rm -f `find . -type f -name '*~'`
rm -f `find . -type f -name '.*~'`
rm -rf .cache
rm -rf .pytest_cache
rm -rf .mypy_cache
rm -rf htmlcov
rm -rf *.egg-info
rm -f .coverage
rm -f .coverage.*
rm -rf build
rm -rf dist
rm -rf coverage.xml
rm -rf .ruff_cache

.PHONY: pre-commit
pre-commit:
pre-commit run --all-files --show-diff-on-failure
all: format lint testcov
Loading
Loading