-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ Migrate Pydantic Extra Types to use
uv
(#241)
* ♻️ Migrate Pydantic Extra Types to use uv * ♻️ Update CI workflow and Makefile to remove pyright and install extra dependencies * ♻️ Update CI workflow to use uv for installing extra dependencies and remove typecheck from pre-commit config * ✨ add new type: Epoch Unix Timestamp (#240) * ✨ Fix formatting in epoch.py log entry comment * 🎨 Add blank line for improved readability in epoch * ♻️ Refactor dependency management in pyproject.toml and Makefile; update CI workflow for improved linting and coverage * ♻️ Refactor CI workflow and dependency management; unify optional dependencies under 'all' and 'extra' * ✨ Add step to install all extra dependencies in CI workflow --------- Co-authored-by: commonism <[email protected]>
- Loading branch information
Showing
34 changed files
with
1,176 additions
and
551 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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/[email protected].1 | ||
- uses: pre-commit/[email protected].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 | ||
|
@@ -70,7 +100,6 @@ jobs: | |
jobs: ${{ toJSON(needs) }} | ||
|
||
release: | ||
name: Release | ||
needs: [check] | ||
if: "success() && startsWith(github.ref, 'refs/tags/')" | ||
runs-on: ubuntu-latest | ||
|
@@ -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/[email protected] | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.