Skip to content

Commit

Permalink
chore: switch to uv (#832)
Browse files Browse the repository at this point in the history
* chore: switch to `uv`

* chore: avoid depending on `pre-commit`

* ci: remove duplicated `rustfmt` installation
  • Loading branch information
mkniewallner authored Sep 2, 2024
1 parent 173d583 commit bbab080
Show file tree
Hide file tree
Showing 14 changed files with 1,033 additions and 1,300 deletions.
42 changes: 0 additions & 42 deletions .github/actions/setup-env/action.yml

This file was deleted.

30 changes: 30 additions & 0 deletions .github/actions/setup-python-env/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: 'Setup Python Environment'
description: 'Set up Python environment for the given Python version'

inputs:
python-version:
description: 'Python version for setup-python'
required: true
default: '3.12'
build-project:
description: 'Whether to build the project itself'
required: true
default: 'false'

runs:
using: 'composite'
steps:
- uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}

- name: Install uv
run: pipx install uv
env:
# renovate: datasource=pypi depName=uv
UV_VERSION: '0.4.1'
shell: bash

- name: Install Python dependencies
run: uv sync --frozen ${{ inputs.build-project == 'false' && '--no-install-project' || '' }}
shell: bash
32 changes: 20 additions & 12 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,21 @@ jobs:
uses: actions/checkout@v4

- name: Set up the environment
uses: ./.github/actions/setup-env
uses: ./.github/actions/setup-python-env
with:
build-project: 'true'

- name: Setup Rust toolchain
run: rustup component add clippy rustfmt

- name: Run pre-commit
run: |
rustup component add rustfmt
pdm run pre-commit run -a --show-diff-on-failure
run: uvx pre-commit@${{ env.PRE_COMMIT_VERSION }} run -a --show-diff-on-failure
env:
# renovate: datasource=pypi depName=pre-commit
PRE_COMMIT_VERSION: '3.8.0'

- name: Inspect dependencies with deptry
run: |
pdm run deptry python
run: uv run deptry python

tests:
strategy:
Expand All @@ -48,19 +53,20 @@ jobs:
uses: actions/checkout@v4

- name: Set up the environment
uses: ./.github/actions/setup-env
uses: ./.github/actions/setup-python-env
with:
python-version: ${{ matrix.python-version }}
build-project: 'true'

- name: Check typing
run: pdm run mypy
run: uv run mypy
if: ${{ matrix.os.name == 'linux' }}

- name: Run unit tests
run: pdm run pytest tests/unit --cov --cov-config=pyproject.toml --cov-report=xml
run: uv run pytest tests/unit --cov --cov-config=pyproject.toml --cov-report=xml

- name: Run functional tests
run: pdm run pytest tests/functional -n auto --dist loadgroup
run: uv run pytest tests/functional -n auto --dist loadgroup

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
Expand All @@ -75,7 +81,9 @@ jobs:
uses: actions/checkout@v4

- name: Set up the environment
uses: ./.github/actions/setup-env
uses: ./.github/actions/setup-python-env

- name: Check if documentation can be built
run: pdm run mkdocs build --strict
# `--no-project` is a workaround to avoid the installation of deptry
# itself (https://github.com/astral-sh/uv/issues/6578)
run: uv run --no-project mkdocs build --strict
6 changes: 4 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ jobs:
uses: actions/checkout@v4

- name: Set up the environment
uses: ./.github/actions/setup-env
uses: ./.github/actions/setup-python-env

- name: Deploy documentation
run: pdm run mkdocs gh-deploy --force
# `--no-project` is a workaround to avoid the installation of deptry
# itself (https://github.com/astral-sh/uv/issues/6578)
run: uv run --no-project mkdocs gh-deploy --force
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ deptry.json
.DS_Store
.vscode

.pdm-python

# From https://raw.githubusercontent.com/github/gitignore/main/Python.gitignore

Byte-compiled / optimized / DLL files
Expand Down Expand Up @@ -92,8 +90,6 @@ target/
profile_default/
ipython_config.py

.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

Expand Down
10 changes: 6 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ repos:
args: [--exit-non-zero-on-fix]
- id: ruff-format

- repo: https://github.com/pdm-project/pdm
rev: "2.18.1"
- repo: https://github.com/astral-sh/uv-pre-commit
rev: "0.4.1"
hooks:
- id: pdm-lock-check
- id: uv-lock
name: check uv lock file consistency
args: ["--locked"]

- repo: local
hooks:
- id: cargo-check-lock
name: check cargo lock file validity
name: check cargo lock file consistency
entry: cargo check
args: ["--locked", "--all-targets", "--all-features"]
language: system
Expand Down
24 changes: 11 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,44 +1,42 @@
.PHONY: install
install: ## Install the PDM environment.
@echo "🚀 Creating virtual environment using PDM"
@pdm install
install: ## Install the uv environment.
@echo "🚀 Creating virtual environment using uv"
@uv sync

.PHONY: check
check: ## Run code quality tools.
@echo "🚀 Checking PDM lock file consistency with 'pyproject.toml': Running pdm lock --check"
@pdm lock --check
@echo "🚀 Linting code: Running pre-commit"
@pdm run pre-commit run -a
@pre-commit run -a
@echo "🚀 Static type checking: Running mypy"
@pdm run mypy
@uv run mypy
@echo "🚀 Checking for dependency issues: Running deptry"
@pdm run deptry python
@uv run deptry python

.PHONY: test
test: test-unit test-functional

.PHONY: test-unit
test-unit: ## Run unit tests.
@echo "🚀 Running unit tests"
@pdm run pytest tests/unit
@uv run pytest tests/unit

.PHONY: test-functional
test-functional: ## Run functional tests.
@echo "🚀 Running functional tests"
@pdm run pytest tests/functional -n auto --dist loadgroup
@uv run pytest tests/functional -n auto --dist loadgroup

.PHONY: build
build: ## Build wheel and sdist files using PDM.
build: ## Build wheel and sdist files using maturin.
@echo "🚀 Creating wheel and sdist files"
@maturin build

.PHONY: docs-test
docs-test: ## Test if documentation can be built without warnings or errors.
@pdm run mkdocs build -s
@uv run mkdocs build -s

.PHONY: docs
docs: ## Build and serve the documentation.
@pdm run mkdocs serve
@uv run mkdocs serve

.PHONY: help
help: ## Show help for the commands.
Expand Down
15 changes: 6 additions & 9 deletions docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ If you are proposing a new feature:

## Get started!

Ready to contribute? Here's how to set up _deptry_ for local development. Please note this documentation assumes you already have [PDM](https://pdm-project.org/latest/) and [Git](https://git-scm.com/) installed and ready to go.
Ready to contribute? Here's how to set up _deptry_ for local development. Please note this documentation assumes you
already have [uv](https://docs.astral.sh/uv/), [Git](https://git-scm.com/) and [pre-commit](https://pre-commit.com/)
installed and ready to go.

1. [Fork](https://github.com/fpgmaas/deptry/fork) the _deptry_ repository on GitHub.

Expand All @@ -55,19 +57,14 @@ Ready to contribute? Here's how to set up _deptry_ for local development. Please
cd deptry
```

If you are using [pyenv](https://github.com/pyenv/pyenv), select a version to use locally (see installed versions with `pyenv versions`):
```bash
pyenv local <x.y.z>
```

Then, install the virtual environment with:
```bash
pdm install
uv sync
```

4. Install [pre-commit](https://pre-commit.com/) to run linters/formatters at commit time:
4. Install `pre-commit` hooks to run linters/formatters at commit time:
```bash
pdm run pre-commit install
pre-commit install
```

5. Create a branch for local development:
Expand Down
Loading

0 comments on commit bbab080

Please sign in to comment.