Skip to content

Commit

Permalink
build: migrate to uv (#612)
Browse files Browse the repository at this point in the history
Co-authored-by: Alc-Alc <45509143+Alc-Alc@users.noreply.github.com>
  • Loading branch information
adhtruong and Alc-Alc authored Dec 8, 2024
1 parent 1e0c847 commit 9fa4ad9
Show file tree
Hide file tree
Showing 9 changed files with 2,322 additions and 2,318 deletions.
47 changes: 23 additions & 24 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,38 +53,38 @@ jobs:
- name: Create cache file
run: echo '${{ matrix.pydantic-version }}-${{ matrix.sqla-version }}' > ./matrix-file.txt

- uses: pdm-project/setup-pdm@v4
name: Set up PDM
- name: Set up python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
version: ${{ matrix.python-version == '3.8' && '2.20.1' || ''}}
allow-python-prereleases: true
cache: true
cache-dependency-path: |
./pdm.lock
./matrix-file.txt

- name: Install uv
uses: astral-sh/setup-uv@v4
with:
version: "0.5.4"
enable-cache: true
cache-dependency-glob: |
uv.lock
matrix-file.txt
- name: Install pydantic
if: matrix.pydantic-version == '1.10'
run: pdm add --no-sync -G pydantic "pydantic[email]==1.10.17"
run: uv add --group pydantic "pydantic[email]==1.10.17"

- name: Install SQLAlchemy
if: matrix.sqla-version == '1.4'
run: pdm add --no-sync -dG sqlalchemy "sqlalchemy[asyncio]==1.4.49"
run: uv add --group sqlalchemy "sqlalchemy[asyncio]==1.4.49"

- name: Install dependencies
run: pdm sync -G:all

- name: Set pythonpath
run: echo "PYTHONPATH=$PWD" >> $GITHUB_ENV
- name: Sync
run: uv sync --all-extras

- name: Test
if: matrix.python-version != '3.12' || matrix.pydantic-version != '2.0' || matrix.sqla-version != '2'
run: pdm run pytest tests
run: uv run pytest tests

- name: Test with Coverage
if: matrix.python-version == '3.12' && matrix.pydantic-version == '2.0' && matrix.sqla-version == '2'
run: pdm run pytest tests docs/examples --cov=. --cov-report=xml
run: uv run pytest tests docs/examples --cov=. --cov-report=xml

- uses: actions/upload-artifact@v4
if: matrix.python-version == '3.12' && matrix.pydantic-version == '2.0' && matrix.sqla-version == '2'
Expand All @@ -106,18 +106,17 @@ jobs:
with:
python-version: "3.12"

- uses: pdm-project/setup-pdm@v4
name: Set up PDM
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
python-version: "3.12"
allow-python-prereleases: true
cache: true
version: "0.5.4"
enable-cache: true

- name: Install dependencies
run: pdm install -G:all
run: uv sync --all-extras

- name: Build docs
run: pdm run make docs
run: uv run make docs

- name: Save PR number
env:
Expand Down
20 changes: 12 additions & 8 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,29 @@ jobs:
with:
python-version: "3.12"

- uses: pdm-project/setup-pdm@v4
name: Set up PDM
- name: Set up python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: "3.12"
allow-python-prereleases: true
cache: true
python-version: ${{ matrix.python-version }}

- name: Install uv
uses: astral-sh/setup-uv@v4
with:
version: "0.5.4"
enable-cache: true

- name: Install dependencies
run: pdm install -G:all
run: uv sync --all-extras

- name: Fetch gh pages
run: git fetch origin gh-pages --depth=1

- name: Build release docs
run: pdm run python tools/build_docs.py docs-build
run: uv run python tools/build_docs.py docs-build
if: github.event_name == 'release'

- name: Build dev docs
run: pdm run python tools/build_docs.py docs-build
run: uv run python tools/build_docs.py docs-build
if: github.event_name == 'push'

- name: Deploy
Expand Down
35 changes: 16 additions & 19 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ jobs:
with:
python-version: "3.12"

- uses: pdm-project/setup-pdm@v4
name: Set up PDM
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
python-version: "3.12"
allow-python-prereleases: true
cache: true
version: "0.5.4"
enable-cache: true

- name: Build package
run: pdm build
run: uv build

- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
Expand All @@ -38,27 +37,25 @@ jobs:
contents: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Check out repository
uses: actions/checkout@v4

- uses: actions/setup-python@v5
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"

- uses: pdm-project/setup-pdm@v4
name: Set up PDM
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
python-version: "3.12"
allow-python-prereleases: true
cache: true

- name: Build package
run: pdm build
version: "0.5.4"
enable-cache: true

- name: Install docs dependencies
run: pdm install -G:all
- name: Install dependencies
run: uv sync --all-extras

- name: Build docs
run: pdm run make docs
run: uv run make docs

- name: Deploy
uses: JamesIves/github-pages-deploy-action@v4
Expand Down
6 changes: 1 addition & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
default_language_version:
python: "3"
python: "3.12"
repos:
- repo: https://github.com/compilerla/conventional-pre-commit
rev: v3.6.0
Expand All @@ -17,10 +17,6 @@ repos:
- id: end-of-file-fixer
- id: mixed-line-ending
- id: trailing-whitespace
- repo: https://github.com/pdm-project/pdm
rev: 2.21.0
hooks:
- id: pdm-lock-check
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.8.1"
hooks:
Expand Down
11 changes: 5 additions & 6 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ Contributing
Setting up the environment
--------------------------

1. Install `Pizza Delivery Man <https://pdm.fming.dev/latest/>`_
2. Run ``pdm install -G:all`` to create a `virtual environment <https://docs.python.org/3/tutorial/venv.html>`_ and install
1. Install `uv <https://github.com/astral-sh/uv>`_
2. Run ``uv sync --all-extras`` to create a `virtual environment <https://docs.python.org/3/tutorial/venv.html>`_ and install
the dependencies
3. If you're working on the documentation and need to build it locally, install the extra dependencies with ``pdm install -G:docs``
4. Install `pre-commit <https://pre-commit.com/>`_
5. Run ``pre-commit install`` to install pre-commit hooks
3. Install `pre-commit <https://pre-commit.com/>`_
4. Run ``pre-commit install`` to install pre-commit hooks

Code contributions
------------------
Expand Down Expand Up @@ -57,7 +56,7 @@ To run or build the docs locally, you need to first install the required depende
.. code-block:: console
:caption: Installing the docs dependencies
pdm install -G:docs
uv sync --all-extras
Then you can serve the documentation with ``make docs-serve``, or build them with ``make docs``

Expand Down
49 changes: 15 additions & 34 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@ SHELL := /bin/bash
# =============================================================================

.DEFAULT_GOAL:=help
.ONESHELL:
USING_PDM = $(shell grep "tool.pdm" pyproject.toml && echo "yes")
ENV_PREFIX := $(shell if [ -d .venv ]; then echo ".venv/bin/"; fi)
VENV_EXISTS := $(shell if [ -d .venv ]; then echo "yes"; fi)
PDM_OPTS ?=
PDM ?= pdm $(PDM_OPTS)

.EXPORT_ALL_VARIABLES:


Expand All @@ -21,36 +14,28 @@ help: ## Display this help text for Makefile
.PHONY: upgrade
upgrade: ## Upgrade all dependencies to the latest stable versions
@echo "=> Updating all dependencies"
@if [ "$(USING_PDM)" ]; then $(PDM) update; fi
@uv sync --upgrade
@echo "=> Dependencies Updated"
@$(ENV_PREFIX)pre-commit autoupdate
@uv run pre-commit autoupdate
@echo "=> Updated Pre-commit"

# =============================================================================
# Developer Utils
# =============================================================================
.PHONY: install-pdm
install-pdm: ## Install latest version of PDM
@curl -sSLO https://pdm.fming.dev/install-pdm.py && \
curl -sSL https://pdm.fming.dev/install-pdm.py.sha256 | shasum -a 256 -c - && \
python3 install-pdm.py

.PHONY: install
install: ## Install the project, dependencies, and pre-commit for local development
@if ! $(PDM) --version > /dev/null; then echo '=> Installing PDM'; $(MAKE) install-pdm; fi
@if [ "$(VENV_EXISTS)" ]; then echo "=> Removing existing virtual environment"; fi
if [ "$(VENV_EXISTS)" ]; then $(MAKE) destroy; fi
if [ "$(VENV_EXISTS)" ]; then $(MAKE) clean; fi
@if [ "$(USING_PDM)" ]; then $(PDM) config venv.in_project true && python3 -m venv --copies .venv && . $(ENV_PREFIX)/activate && $(ENV_PREFIX)/pip install --quiet -U wheel setuptools cython pip; fi
@if [ "$(USING_PDM)" ]; then $(PDM) install -G:all; fi
@uv sync --all-extras
@echo "=> Installing pre-commit hooks"
pre-commit install --install-hooks
@echo "=> Install complete! Note: If you want to re-install re-run 'make install'"

.PHONY: clean
clean: ## Cleanup temporary build artifacts
@echo "=> Cleaning working directory"
@rm -rf .pytest_cache .ruff_cache .hypothesis build/ -rf dist/ .eggs/
@rm -rf .pytest_cache .ruff_cache .hypothesis build/ dist/ .eggs/
@find . -name '*.egg-info' -exec rm -rf {} +
@find . -name '*.egg' -exec rm -f {} +
@find . -name '*.pyc' -exec rm -f {} +
Expand All @@ -65,40 +50,36 @@ clean: ## Cleanup temporary build artifacts
destroy: ## Destroy the virtual environment
@rm -rf .venv

.PHONY: refresh-lockfiles
refresh-lockfiles: ## Sync lockfiles with requirements files.
pdm update --update-reuse --group :all

.PHONY: lock
lock: ## Rebuild lockfiles from scratch, updating all dependencies
pdm update --update-eager --group :all
@uv lock

# =============================================================================
# Tests, Linting, Coverage
# =============================================================================
.PHONY: lint
lint: ## Runs pre-commit hooks; includes ruff linting, ruff formatting, codespell
@echo "=> Running pre-commit process"
@$(ENV_PREFIX)pre-commit run --all-files
@uv run pre-commit run --all-files
@echo "=> Pre-commit complete"

.PHONY: coverage
coverage: ## Run the tests and generate coverage report
@echo "=> Running tests with coverage"
@$(ENV_PREFIX)pytest tests --cov=polyfactory
@$(ENV_PREFIX)coverage html
@$(ENV_PREFIX)coverage xml
@uv run pytest tests --cov=polyfactory
@uv run coverage html
@uv run coverage xml
@echo "=> Coverage report generated"

.PHONY: test
test: ## Run the tests
@echo "=> Running test cases"
@$(ENV_PREFIX)pytest tests
@uv run pytest tests
@echo "=> Tests complete"

.PHONY: test-examples
test-examples: ## Run the examples tests
pytest docs/examples
@uv run pytest docs/examples

.PHONY: test-all
test-all: test test-examples ## Run all tests
Expand All @@ -112,7 +93,7 @@ check-all: lint test-all coverage ## Run all linting, tests, and coverage c
.PHONY: docs-install
docs-install: ## Install docs dependencies
@echo "=> Installing documentation dependencies"
@$(PDM) install --group docs
@uv sync --group docs
@echo "=> Installed documentation dependencies"

docs-clean: ## Dump the existing built docs
Expand All @@ -122,12 +103,12 @@ docs-clean: ## Dump the existing built docs

docs-serve: docs-clean ## Serve the docs locally
@echo "=> Serving documentation"
$(ENV_PREFIX)sphinx-autobuild docs docs/_build/ -j auto --watch polyfactory --watch docs --watch tests --watch CONTRIBUTING.rst --port 8002
@uv run sphinx-autobuild docs docs/_build/ -j auto --watch polyfactory --watch docs --watch tests --watch CONTRIBUTING.rst --port 8002

docs: docs-clean ## Dump the existing built docs and rebuild them
@echo "=> Building documentation"
@$(ENV_PREFIX)sphinx-build -M html docs docs/_build/ -E -a -j auto --keep-going
@uv run sphinx-build -M html docs docs/_build/ -E -a -j auto --keep-going

changelog:
@echo "=> Generating changelog"
@$(ENV_PREFIX)git-cliff -c pyproject.toml -o docs/changelog.rst --github-repo litestar-org/polyfactory --github-token $(GITHUB_TOKEN)
@uv run git-cliff -c pyproject.toml -o docs/changelog.rst --github-repo litestar-org/polyfactory --github-token $(GITHUB_TOKEN)
Loading

0 comments on commit 9fa4ad9

Please sign in to comment.