Skip to content

Commit

Permalink
Merge pull request #4 from openscm/switch-to-uv
Browse files Browse the repository at this point in the history
Switch to uv
  • Loading branch information
znicholls authored Dec 26, 2024
2 parents 5a53ba8 + a76e091 commit 9ea90be
Show file tree
Hide file tree
Showing 16 changed files with 3,416 additions and 3,385 deletions.
4 changes: 2 additions & 2 deletions .copier-answers.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Changes here will be overwritten by Copier; NEVER EDIT MANUALLY
_commit: v0.4.1-60-gcf659d9
_commit: v0.4.1-62-gf6156ea
_src_path: ../copier-core-python-repository
conda_release: false
email: [email protected]
include_cli: false
name: Zebedee Nicholls
notebook_based_docs: true
package_manager: pdm
package_manager: uv
pandas_doctests: false
plot_dependencies: true
project_description_short: Representation of continuous timeseries.
Expand Down
40 changes: 12 additions & 28 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
@@ -1,45 +1,29 @@
name: "Setup Python and pdm"
description: "setup Python and pdm with caches"
name: "Setup Python and uv"
description: "setup Python and uv"

inputs:
python-version:
description: "Python version to use"
required: true
pdm-dependency-install-flags:
description: "Flags to pass to pdm when running `pdm install`"
uv-dependency-install-flags:
description: "Flags to pass to uv when running `uv install`"
required: true
run-pdm-install:
description: "Should we run the pdm install steps"
run-uv-install:
description: "Should we run the uv install steps"
required: false
default: true

runs:
using: "composite"
steps:
- name: Write file with install flags
shell: bash
run: |
echo "${{ inputs.pdm-dependency-install-flags }}" > pdm-install-flags.txt
- name: Setup PDM
id: setup-pdm
uses: pdm-project/[email protected]
- name: Setup uv
id: setup-uv
uses: astral-sh/setup-uv@v4
with:
version: "0.5.11"
python-version: ${{ inputs.python-version }}
cache: true
cache-dependency-path: |
./pdm.lock
./pdm-install-flags.txt
- name: Install dependencies
shell: bash
if: ${{ (inputs.run-pdm-install == 'true') && (steps.setup-pdm.outputs.cache-hit != 'true') }}
run: |
pdm install --no-self ${{ inputs.pdm-dependency-install-flags }}
# Now run same command but let the package install too
- name: Install package
shell: bash
# To ensure that the package is always installed, this step is run even if the cache was hit
if: ${{ inputs.run-pdm-install == 'true' }}
if: ${{ (inputs.run-uv-install == 'true') }}
run: |
pdm install ${{ inputs.pdm-dependency-install-flags }}
pdm run which python
pdm run python --version # Check python version just in case
uv sync ${{ inputs.uv-dependency-install-flags }}
8 changes: 6 additions & 2 deletions .github/workflows/bump.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
name: Bump version
# For the time being, we still do this with pdm.
# Honestly, it doesn't really matter,
# but one day uv will have a bump command too and we can switch to that.
# Relevant issue in uv: https://github.com/astral-sh/uv/issues/6298

on:
workflow_dispatch:
Expand Down Expand Up @@ -48,7 +52,7 @@ jobs:
- uses: ./.github/actions/setup
with:
python-version: ${{ matrix.python-version }}
pdm-dependency-install-flags: "-G dev"
uv-dependency-install-flags: "--all-extras --group dev"

- name: Create bump and changelog
run: |
Expand All @@ -65,7 +69,7 @@ jobs:
echo "Bumping to version $NEW_VERSION"
# Build CHANGELOG
pdm run towncrier build --yes --version v$NEW_VERSION
uv run towncrier build --yes --version v$NEW_VERSION
# Commit, tag and push
git commit -a -m "bump: version $BASE_VERSION -> $NEW_VERSION"
Expand Down
38 changes: 20 additions & 18 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ jobs:
- uses: ./.github/actions/setup
with:
python-version: ${{ matrix.python-version }}
pdm-dependency-install-flags: "--group :all --group dev --dev"
uv-dependency-install-flags: "--all-extras --group dev"
- name: mypy
run: |
MYPYPATH=stubs pdm run mypy src
MYPYPATH=stubs uv run mypy src
docs:
if: ${{ !github.event.pull_request.draft }}
Expand All @@ -34,19 +34,19 @@ jobs:
- uses: ./.github/actions/setup
with:
python-version: "3.11"
pdm-dependency-install-flags: "--group :all --group docs --dev"
uv-dependency-install-flags: "--all-extras --group docs"
- name: docs
run: |
pdm run mkdocs build --strict
uv run mkdocs build --strict
- uses: ./.github/actions/setup
with:
python-version: "3.11"
pdm-dependency-install-flags: "--group :all --group docs --group dev --dev"
uv-dependency-install-flags: "--all-extras --group docs --group dev"
- name: docs-with-changelog
run: |
# Check CHANGELOG will build too
pdm run towncrier build --yes
pdm run mkdocs build --strict
uv run towncrier build --yes
uv run mkdocs build --strict
# Just in case, undo the staged changes
git restore --staged . && git restore .
Expand Down Expand Up @@ -76,11 +76,11 @@ jobs:
# when people try to run without installing optional dependencies,
# we should add a CI step that runs the tests without optional dependencies too.
# We don't have that right now, because we're not sure this pain point exists.
pdm-dependency-install-flags: "--group :all --group tests --dev"
uv-dependency-install-flags: "--all-extras --group tests"
- name: Run tests
run: |
pdm run pytest -r a -v src tests --doctest-modules --cov=src --cov-report=term-missing --cov-report=xml
pdm run coverage report
uv run pytest -r a -v src tests --doctest-modules --cov=src --cov-report=term-missing --cov-report=xml
uv run coverage report
- name: Upload coverage reports to Codecov with GitHub Action
uses: codecov/[email protected]
env:
Expand All @@ -99,22 +99,24 @@ jobs:
- uses: ./.github/actions/setup
with:
python-version: ${{ matrix.python-version }}
pdm-dependency-install-flags: "--prod --without :all"
uv-dependency-install-flags: "--no-dev" # no extras is default
- name: Check importable without extras
run: pdm run python scripts/test-install.py
run: uv run python scripts/test-install.py

check-build:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Setup PDM
uses: pdm-project/[email protected]
- name: Setup uv
id: setup-uv
uses: astral-sh/setup-uv@v4
with:
version: "0.5.11"
python-version: "3.9"
- name: Build package
run: |
pdm build
uv build
- name: Check build
run: |
tar -tvf dist/continuous_timeseries-*.tar.gz --wildcards '*continuous_timeseries/py.typed'
Expand All @@ -128,11 +130,11 @@ jobs:
- uses: ./.github/actions/setup
with:
python-version: "3.9"
pdm-dependency-install-flags: "--group dev --dev"
uv-dependency-install-flags: "--group dev"
- name: Check licences of dependencies
shell: bash
run: |
TEMP_FILE=$(mktemp)
pdm export --prod > $TEMP_FILE
pdm run liccheck -r $TEMP_FILE -R licence-check.txt
uv export --no-dev > $TEMP_FILE
uv run liccheck -r $TEMP_FILE -R licence-check.txt
cat licence-check.txt
8 changes: 5 additions & 3 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup PDM
uses: pdm-project/setup-pdm@v4
- name: Setup uv
id: setup-uv
uses: astral-sh/setup-uv@v4
with:
version: "0.5.11"
python-version: ${{ matrix.python-version }}
- name: Publish to PyPI
run: |
pdm publish
uv publish
12 changes: 7 additions & 5 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,26 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup PDM
uses: pdm-project/setup-pdm@v4
- name: Setup uv
id: setup-uv
uses: astral-sh/setup-uv@v4
with:
version: "0.5.11"
python-version: ${{ matrix.python-version }}
- name: Add version to environment
run: |
PROJECT_VERSION=`sed -ne 's/^version = "\([0-9\.a]*\)"/\1/p' pyproject.toml`
echo "PROJECT_VERSION=$PROJECT_VERSION" >> $GITHUB_ENV
- name: Build package for PyPI
run: |
pdm build
uv build
- name: Generate Release Notes
run: |
echo "" >> ".github/release_template.md"
echo "## Changelog" >> ".github/release_template.md"
echo "" >> ".github/release_template.md"
pdm add typer
pdm run python scripts/changelog-to-release-template.py >> ".github/release_template.md"
uv add typer
uv run python scripts/changelog-to-release-template.py >> ".github/release_template.md"
echo "" >> ".github/release_template.md"
echo "## Changes" >> ".github/release_template.md"
echo "" >> ".github/release_template.md"
Expand Down
34 changes: 21 additions & 13 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ci:
autoupdate_schedule: quarterly
autoupdate_branch: pre-commit-autoupdate
# Currently network access isn't supported in the pre-commit CI product.
skip: [pdm-lock-check, pdm-export, pdm-sync]
skip: [uv-lock, uv-export, pdm-lock-check]

# See https://pre-commit.com/hooks.html for more hooks
repos:
Expand Down Expand Up @@ -38,22 +38,30 @@ repos:
- id: ruff
args: [ --fix, --exit-non-zero-on-fix ]
- id: ruff-format
- repo: https://github.com/astral-sh/uv-pre-commit
# uv version.
rev: 0.5.11
hooks:
- id: uv-lock
name: uv-lock-check
args: ["--check"]
# Put requirements.txt files in the repo too
- id: uv-export
name: export-requirements
args: ["-o", "requirements-locked.txt", "--no-hashes", "--no-dev", "--no-emit-project"]
- id: uv-export
name: export-requirements-optional
args: ["-o", "requirements-incl-optional-locked.txt", "--no-hashes", "--no-dev", "--no-emit-project", "--all-extras"]
- id: uv-export
name: export-requirements-docs
args: ["-o", "requirements-docs-locked.txt", "--no-hashes", "--no-dev", "--no-emit-project", "--all-extras", "--group", "docs"]
# # Not released yet
# - id: uv-sync
- repo: https://github.com/pdm-project/pdm
rev: 2.22.1
hooks:
# Check that the lock file is up to date.
# We need the pdm lock file too
# so that we can build the locked version of the package.
- id: pdm-lock-check
args: ["--group", ":all", "--group", "all-dev", "--dev", "--strategy", "inherit_metadata"]
# Put requirements.txt files in the repo too
- id: pdm-export
name: export-requirements
args: ["-o", "requirements-locked.txt", "--without-hashes", "--prod"]
- id: pdm-export
name: export-requirements-optional
args: ["-o", "requirements-incl-optional-locked.txt", "--without-hashes", "--prod", "--group", ":all"]
- id: pdm-export
name: export-requirements-docs
args: ["-o", "requirements-docs-locked.txt", "--without-hashes", "--group", ":all", "--group", "docs", "--dev"]
- id: pdm-sync
args: ["--group", ":all", "--strategy", "inherit_metadata"]
29 changes: 14 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@ help: ## print short description of each target

.PHONY: checks
checks: ## run all the linting checks of the codebase
@echo "=== pre-commit ==="; pdm run pre-commit run --all-files || echo "--- pre-commit failed ---" >&2; \
echo "=== mypy ==="; MYPYPATH=stubs pdm run mypy src || echo "--- mypy failed ---" >&2; \
@echo "=== pre-commit ==="; uv run pre-commit run --all-files || echo "--- pre-commit failed ---" >&2; \
echo "=== mypy ==="; MYPYPATH=stubs uv run mypy src || echo "--- mypy failed ---" >&2; \
echo "======"

.PHONY: ruff-fixes
ruff-fixes: ## fix the code using ruff
# format before and after checking so that the formatted stuff is checked and
# the fixed stuff is formatted
pdm run ruff format src tests scripts docs
pdm run ruff check src tests scripts docs --fix
pdm run ruff format src tests scripts docs
uv run ruff format src tests scripts docs
uv run ruff check src tests scripts docs --fix
uv run ruff format src tests scripts docs

.PHONY: test
test: ## run the tests
pdm run pytest src tests -r a -v --doctest-modules --cov=src
uv run pytest src tests -r a -v --doctest-modules --cov=src

# Note on code coverage and testing:
# You must specify cov=src.
Expand All @@ -55,30 +55,29 @@ test: ## run the tests

.PHONY: docs
docs: ## build the docs
pdm run mkdocs build
uv run mkdocs build

.PHONY: docs-strict
docs-strict: ## build the docs strictly (e.g. raise an error on warnings, this most closely mirrors what we do in the CI)
pdm run mkdocs build --strict
uv run mkdocs build --strict

.PHONY: docs-serve
docs-serve: ## serve the docs locally
pdm run mkdocs serve
uv run mkdocs serve

.PHONY: changelog-draft
changelog-draft: ## compile a draft of the next changelog
pdm run towncrier build --draft --version draft
uv run towncrier build --draft --version draft

.PHONY: licence-check
licence-check: ## Check that licences of the dependencies are suitable
# Will likely fail on Windows, but Makefiles are in general not Windows
# compatible so we're not too worried
pdm export --without=tests --without=docs --without=dev > $(TEMP_FILE)
pdm run liccheck -r $(TEMP_FILE) -R licence-check.txt
uv export --no-dev > $(TEMP_FILE)
uv run liccheck -r $(TEMP_FILE) -R licence-check.txt
rm -f $(TEMP_FILE)

.PHONY: virtual-environment
virtual-environment: ## update virtual environment, create a new one if it doesn't already exist
pdm lock --group :all --group all-dev --dev --strategy inherit_metadata
pdm install --dev --group :all
pdm run pre-commit install
uv sync --all-extras --group all-dev
uv run pre-commit install
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ Additional dependencies can be installed using

### For developers

For development, we rely on [pdm](https://pdm-project.org/en/latest/)
For development, we rely on [uv](https://docs.astral.sh/uv/)
for all our dependency management.
To get started, you will need to make sure that pdm is installed
([instructions here](https://pdm-project.org/en/latest/#installation),
although we found that installing with [pipx](https://pipx.pypa.io/stable/installation/)
worked perfectly for us).
To get started, you will need to make sure that uv is installed
([instructions here](https://docs.astral.sh/uv/getting-started/installation/)
(we found that the self-managed install was best,
particularly for upgrading uv later).

For all of our work, we use our `Makefile`.
You can read the instructions out and run the commands by hand if you wish,
Expand Down
1 change: 1 addition & 0 deletions changelog/4.trivial.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Switched to uv for environment management.
Loading

0 comments on commit 9ea90be

Please sign in to comment.