Skip to content

Commit b327d7e

Browse files
yezz123commonism
andauthored
♻️ 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]>
1 parent 3668b3a commit b327d7e

34 files changed

+1176
-551
lines changed

.github/workflows/ci.yml

+60-34
Original file line numberDiff line numberDiff line change
@@ -8,60 +8,90 @@ on:
88
- '**'
99
pull_request: {}
1010

11+
env:
12+
COLUMNS: 150
13+
1114
jobs:
1215
lint:
1316
runs-on: ubuntu-latest
14-
17+
strategy:
18+
fail-fast: false
1519
steps:
1620
- uses: actions/checkout@v4
1721

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

23-
- name: install
24-
run: |
25-
pip install -r requirements/pyproject.txt && pip install -r requirements/linting.txt
26+
- name: Install dependencies
27+
run: uv sync --python 3.12 --group lint --all-extras
2628

27-
- uses: pre-commit/[email protected].1
29+
- uses: pre-commit/[email protected].0
2830
with:
2931
extra_args: --all-files --verbose
32+
env:
33+
SKIP: no-commit-to-branch
3034

3135
test:
32-
name: test py${{ matrix.python-version }} on ${{ matrix.os }}
36+
name: test py${{ matrix.python-version }}
37+
runs-on: ubuntu-latest
3338

3439
strategy:
3540
fail-fast: false
3641
matrix:
37-
os: [ubuntu, macos, windows]
38-
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
42+
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
43+
44+
env:
45+
UV_PYTHON: ${{ matrix.python-version }}
3946

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

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

49-
- run: |
50-
pip install -r requirements/pyproject.txt && pip install -r requirements/testing.txt
54+
- name: Install dependencies
55+
run: uv sync --extra all
5156

52-
- run: pip freeze
57+
- name: Make coverage directory
58+
run: mkdir coverage
5359

54-
- run: make test
60+
- run: uv run --frozen coverage run -m pytest
5561
env:
56-
CONTEXT: ${{ runner.os }}-py${{ matrix.python-version }}-with-deps
62+
COVERAGE_FILE: coverage/.coverage.${{ runner.os }}-py${{ matrix.python-version }}
63+
64+
- name: store coverage files
65+
uses: actions/upload-artifact@v4
66+
with:
67+
name: coverage-${{ matrix.python-version }}
68+
path: coverage
69+
include-hidden-files: true
70+
71+
coverage:
72+
runs-on: ubuntu-latest
73+
needs: [test]
74+
steps:
75+
- uses: actions/checkout@v4
76+
77+
- uses: astral-sh/setup-uv@v3
78+
with:
79+
enable-cache: true
5780

58-
- run: coverage xml
59-
- uses: codecov/codecov-action@v4
81+
- name: get coverage files
82+
uses: actions/download-artifact@v4
83+
with:
84+
merge-multiple: true
85+
path: coverage
86+
87+
- run: uv run --frozen coverage combine coverage
88+
89+
- run: uv run --frozen coverage report --fail-under 85
6090

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

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

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

93118
- name: check GITHUB_REF matches package version
94119
uses: samuelcolvin/[email protected]
95120
with:
96-
version_file_path: pydantic_extra_types/__init__.py
121+
version_file_path: pyproject.toml
97122

98-
- name: build
99-
run: python -m build
123+
- run: uv build
100124

101-
- name: Upload package to PyPI
125+
- name: Publish to PyPI
102126
uses: pypa/gh-action-pypi-publish@release/v1
127+
with:
128+
skip-existing: true

.gitignore

+2-4
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

+16-14
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
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

Makefile

+36-57
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,49 @@
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 pip install pre-commit
12+
pre-commit install --install-hooks
1813

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

24-
.PHONY: lint
23+
.PHONY: lint # Lint the code
2524
lint:
26-
ruff check $(sources)
27-
ruff format --check $(sources)
28-
29-
.PHONY: mypy
30-
mypy:
31-
mypy pydantic_extra_types
25+
uv run ruff format --check
26+
uv run ruff check
3227

3328
.PHONY: test
3429
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
30+
uv run pytest
31+
32+
.PHONY: test-all-python # Run tests on Python 3.9 to 3.13
33+
test-all-python:
34+
UV_PROJECT_ENVIRONMENT=.venv39 uv run --python 3.9 coverage run -p -m pytest
35+
UV_PROJECT_ENVIRONMENT=.venv310 uv run --python 3.10 coverage run -p -m pytest
36+
UV_PROJECT_ENVIRONMENT=.venv311 uv run --python 3.11 coverage run -p -m pytest
37+
UV_PROJECT_ENVIRONMENT=.venv312 uv run --python 3.12 coverage run -p -m pytest
38+
UV_PROJECT_ENVIRONMENT=.venv313 uv run --python 3.13 coverage run -p -m pytest
39+
@uv run coverage combine
40+
@uv run coverage report
41+
42+
.PHONY: testcov # Run tests and collect coverage data
43+
testcov:
44+
uv run coverage run -m pytest
45+
@uv run coverage report
46+
@uv run coverage html
4647

4748
.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
49+
all: format lint testcov

0 commit comments

Comments
 (0)