Skip to content

Commit 26d3b72

Browse files
committed
♻️ Migrate Pydantic Extra Types to use uv
1 parent f7875f0 commit 26d3b72

33 files changed

+1338
-549
lines changed

.github/workflows/ci.yml

Lines changed: 54 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,60 +8,82 @@ on:
88
- '**'
99
pull_request: {}
1010

11+
env:
12+
COLUMNS: 150
13+
1114
jobs:
1215
lint:
1316
runs-on: ubuntu-latest
14-
1517
steps:
1618
- uses: actions/checkout@v4
1719

18-
- name: set up python
19-
uses: actions/setup-python@v5
20+
- uses: astral-sh/setup-uv@v3
2021
with:
21-
python-version: '3.10'
22+
enable-cache: true
2223

23-
- name: install
24-
run: |
25-
pip install -r requirements/pyproject.txt && pip install -r requirements/linting.txt
24+
- run: uv sync --python 3.12 --frozen --no-dev --group lint
2625

27-
- uses: pre-commit/action@v3.0.1
26+
- uses: pre-commit/action@v3.0.0
2827
with:
2928
extra_args: --all-files --verbose
29+
env:
30+
SKIP: no-commit-to-branch
3031

3132
test:
32-
name: test py${{ matrix.python-version }} on ${{ matrix.os }}
33+
name: test py${{ matrix.python-version }}
34+
runs-on: ubuntu-latest
3335

3436
strategy:
3537
fail-fast: false
3638
matrix:
37-
os: [ubuntu, macos, windows]
38-
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
39+
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
40+
41+
env:
42+
UV_PYTHON: ${{ matrix.python-version }}
3943

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

44-
- name: set up python
45-
uses: actions/setup-python@v5
47+
- uses: astral-sh/setup-uv@v3
4648
with:
47-
python-version: ${{ matrix.python-version }}
49+
enable-cache: true
4850

49-
- run: |
50-
pip install -r requirements/pyproject.txt && pip install -r requirements/testing.txt
51+
- run: mkdir coverage
52+
- run: uv run --frozen coverage run -m pytest
53+
env:
54+
COVERAGE_FILE: coverage/.coverage.${{ runner.os }}-py${{ matrix.python-version }}
5155

52-
- run: pip freeze
56+
- name: store coverage files
57+
uses: actions/upload-artifact@v4
58+
with:
59+
name: coverage-${{ matrix.python-version }}
60+
path: coverage
61+
include-hidden-files: true
5362

54-
- run: make test
55-
env:
56-
CONTEXT: ${{ runner.os }}-py${{ matrix.python-version }}-with-deps
63+
coverage:
64+
runs-on: ubuntu-latest
65+
needs: [test]
66+
steps:
67+
- uses: actions/checkout@v4
5768

58-
- run: coverage xml
59-
- uses: codecov/codecov-action@v4
69+
- uses: astral-sh/setup-uv@v3
70+
with:
71+
enable-cache: true
72+
73+
- name: get coverage files
74+
uses: actions/download-artifact@v4
75+
with:
76+
merge-multiple: true
77+
path: coverage
78+
79+
- run: uv run --frozen coverage combine coverage
80+
81+
- run: uv run --frozen coverage report --fail-under 85
6082

6183
# https://github.com/marketplace/actions/alls-green#why used for branch protection checks
6284
check:
6385
if: always()
64-
needs: [lint, test]
86+
needs: [lint, test, coverage]
6587
runs-on: ubuntu-latest
6688
steps:
6789
- name: Decide whether the needed jobs succeeded or failed
@@ -70,7 +92,7 @@ jobs:
7092
jobs: ${{ toJSON(needs) }}
7193

7294
release:
73-
name: Release
95+
name: Deploy
7496
needs: [check]
7597
if: "success() && startsWith(github.ref, 'refs/tags/')"
7698
runs-on: ubuntu-latest
@@ -82,21 +104,18 @@ jobs:
82104
steps:
83105
- uses: actions/checkout@v4
84106

85-
- name: set up python
86-
uses: actions/setup-python@v5
107+
- uses: astral-sh/setup-uv@v3
87108
with:
88-
python-version: '3.10'
89-
90-
- name: install
91-
run: pip install -U build
109+
enable-cache: true
92110

93111
- name: check GITHUB_REF matches package version
94112
uses: samuelcolvin/check-python-version@v4.1
95113
with:
96-
version_file_path: pydantic_extra_types/__init__.py
114+
version_file_path: pyproject.toml
97115

98-
- name: build
99-
run: python -m build
116+
- run: uv build
100117

101-
- name: Upload package to PyPI
118+
- name: Publish to PyPI
102119
uses: pypa/gh-action-pypi-publish@release/v1
120+
with:
121+
skip-existing: true

.gitignore

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@ venv/
44
.venv/
55
env3*/
66
Pipfile
7-
*.lock
87
*.py[cod]
98
*.egg-info/
9+
.python-version
1010
/build/
1111
dist/
1212
.cache/
1313
.mypy_cache/
1414
test.py
1515
.coverage
16-
.hypothesis
1716
/htmlcov/
1817
/site/
1918
/site.zip
@@ -24,5 +23,4 @@ _build/
2423
/sandbox/
2524
/.ghtopdep_cache/
2625
/worktrees/
27-
.ruff_cache/
28-
.python-version
26+
/.ruff_cache/

.pre-commit-config.yaml

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,33 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.5.0
3+
rev: v4.3.0
44
hooks:
5+
- id: no-commit-to-branch # prevent direct commits to the `main` branch
56
- id: check-yaml
6-
args: ['--unsafe']
77
- id: check-toml
88
- id: end-of-file-fixer
99
- id: trailing-whitespace
1010

1111
- repo: local
1212
hooks:
13-
- id: lint
14-
name: Lint
15-
entry: make lint
16-
types: [python]
17-
language: system
18-
pass_filenames: false
19-
- id: mypy
20-
name: Mypy
21-
entry: make mypy
22-
types: [python]
23-
language: system
24-
pass_filenames: false
13+
- id: format
14+
name: Format
15+
entry: make
16+
args: [format]
17+
language: system
18+
types: [python]
19+
pass_filenames: false
20+
- id: lint
21+
name: Lint
22+
entry: make
23+
args: [lint]
24+
types: [python]
25+
language: system
26+
pass_filenames: false
27+
- id: typecheck
28+
name: Typecheck
29+
entry: make
30+
args: [typecheck]
31+
language: system
32+
types: [python]
33+
pass_filenames: false

Makefile

Lines changed: 38 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,52 @@
11
.DEFAULT_GOAL := all
22
sources = pydantic_extra_types tests
33

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

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

19-
.PHONY: format
13+
.PHONY: rebuild-lockfiles ## Rebuild lockfiles from scratch, updating all dependencies
14+
rebuild-lockfiles: .uv
15+
uv lock --upgrade
16+
17+
.PHONY: format # Format the code
2018
format:
21-
ruff check --fix $(sources)
22-
ruff format $(sources)
19+
uv run ruff format
20+
uv run ruff check --fix --fix-only
2321

24-
.PHONY: lint
22+
.PHONY: lint # Lint the code
2523
lint:
26-
ruff check $(sources)
27-
ruff format --check $(sources)
24+
uv run ruff format --check
25+
uv run ruff check
2826

29-
.PHONY: mypy
30-
mypy:
31-
mypy pydantic_extra_types
27+
.PHONY: typecheck
28+
typecheck:
29+
uv run pyright
3230

3331
.PHONY: test
3432
test:
35-
coverage run -m pytest --durations=10
36-
37-
.PHONY: testcov
38-
testcov: test
39-
@echo "building coverage html"
40-
@coverage html
41-
42-
.PHONY: testcov-compile
43-
testcov-compile: build-trace test
44-
@echo "building coverage html"
45-
@coverage html
33+
uv run pytest
34+
35+
.PHONY: test-all-python # Run tests on Python 3.9 to 3.13
36+
test-all-python:
37+
UV_PROJECT_ENVIRONMENT=.venv39 uv run --python 3.9 coverage run -p -m pytest
38+
UV_PROJECT_ENVIRONMENT=.venv310 uv run --python 3.10 coverage run -p -m pytest
39+
UV_PROJECT_ENVIRONMENT=.venv311 uv run --python 3.11 coverage run -p -m pytest
40+
UV_PROJECT_ENVIRONMENT=.venv312 uv run --python 3.12 coverage run -p -m pytest
41+
UV_PROJECT_ENVIRONMENT=.venv313 uv run --python 3.13 coverage run -p -m pytest
42+
@uv run coverage combine
43+
@uv run coverage report
44+
45+
.PHONY: testcov # Run tests and collect coverage data
46+
testcov:
47+
uv run coverage run -m pytest
48+
@uv run coverage report
49+
@uv run coverage html
4650

4751
.PHONY: all
48-
all: lint mypy testcov
49-
50-
.PHONY: clean
51-
clean:
52-
rm -rf `find . -name __pycache__`
53-
rm -f `find . -type f -name '*.py[co]'`
54-
rm -f `find . -type f -name '*~'`
55-
rm -f `find . -type f -name '.*~'`
56-
rm -rf .cache
57-
rm -rf .pytest_cache
58-
rm -rf .mypy_cache
59-
rm -rf htmlcov
60-
rm -rf *.egg-info
61-
rm -f .coverage
62-
rm -f .coverage.*
63-
rm -rf build
64-
rm -rf dist
65-
rm -rf coverage.xml
66-
rm -rf .ruff_cache
67-
68-
.PHONY: pre-commit
69-
pre-commit:
70-
pre-commit run --all-files --show-diff-on-failure
52+
all: format lint typecheck testcov

0 commit comments

Comments
 (0)