Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: migrate packaging to uv #847

Merged
merged 9 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
- [ ] The new commits follow conventions outlined in the [conventional commit spec](https://www.conventionalcommits.org/en/v1.0.0/), such as "fix(api): prevent racing of requests".

> - If pre-commit.ci is failing, try `pre-commit run -a` for further information.
> - If CI / test is failing, try `poetry run pytest` for further information.
> - If CI / test is failing, try `uv run pytest` for further information.

<!--
🎉 Thank you for contributing!
Expand Down
29 changes: 10 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,13 @@ jobs:
name: "Template: ${{ matrix.python-version }} - ${{ matrix.os }}"
steps:
- uses: actions/checkout@v4
- name: Install poetry
run: pipx install poetry
- name: Set up Python
uses: actions/setup-python@v5
- uses: actions/setup-python@v5
with:
cache: poetry
python-version: ${{ matrix.python-version }}
- name: Install Dependencies
run: poetry install
- uses: astral-sh/setup-uv@v5
- run: uv sync --no-python-downloads
shell: bash
- name: Test with Pytest
run: poetry run pytest
- run: uv run pytest
shell: bash

# Generate package, run test, run linting and build docs
Expand All @@ -49,13 +44,13 @@ jobs:
fail-fast: false
matrix:
script:
- run: "poetry run python -m pytest tests"
- run: "uv run python -m pytest tests"
dir: ""
name: "pytest"
- run: "git init && git add . && pipx run pre-commit run -a"
- run: "git init && git add . && uvx --with pre-commit-uv pre-commit run -a"
dir: ""
name: "pre-commit"
- run: "poetry run make html"
- run: "uv run make html"
dir: "docs"
name: "docs"
extra_options:
Expand All @@ -76,8 +71,9 @@ jobs:
id: setup-python
with:
python-version: "3.11"
- uses: astral-sh/setup-uv@v5
- run: |
pipx run copier copy \
uvx copier copy \
. \
my-project \
--UNSAFE \
Expand All @@ -90,14 +86,9 @@ jobs:
--data 'open_source_license=MIT' \
${{ matrix.extra_options.value }} \
--defaults
env:
PIPX_DEFAULT_PYTHON: ${{ steps.setup-python.outputs.python-path }}
- run: cat pyproject.toml
working-directory: my-project
- run: pipx install poetry
env:
PIPX_DEFAULT_PYTHON: ${{ steps.setup-python.outputs.python-path }}
- run: poetry install --with docs
- run: uv sync --group docs
working-directory: my-project
- run: ${{ matrix.script.run }}
working-directory: my-project/${{ matrix.script.dir }}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ on:

jobs:
upgrade:
uses: browniebroke/github-actions/.github/workflows/poetry-upgrade.yml@v1
uses: browniebroke/github-actions/.github/workflows/uv-upgrade.yml@v1
secrets:
gh_pat: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
4 changes: 2 additions & 2 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
tasks:
- command: |
pip install poetry
PIP_USER=false poetry install
pip install uv
PIP_USER=false uv sync
- command: |
pip install pre-commit
pre-commit install
Expand Down
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
exclude: "{{package_name}}|.all-contributorsrc"
default_stages: [commit]
default_stages: [pre-commit]

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
Expand All @@ -22,10 +22,10 @@ repos:
rev: "v2.5.0"
hooks:
- id: pyproject-fmt
- repo: https://github.com/python-poetry/poetry
rev: 1.8.5
- repo: https://github.com/astral-sh/uv-pre-commit
rev: 0.5.11
hooks:
- id: poetry-check
- id: uv-lock
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.1.0
hooks:
Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Project template for a Python Package using Copier.

- Project for Python 3.8+.
- Testing with Pytest using GitHub actions.
- Packaging powered by [poetry].
- Packaging powered by [uv].
- Optionally generates a CLI entry point powered by [Typer] and [Rich].
- Optionally makes it a Django package.
- Uses [Ruff] for formatting and linting.
Expand Down Expand Up @@ -39,19 +39,19 @@ This will prompt you for a few questions and create new directory with the name

### Start developing

The project uses [Poetry] for dependencies management and packaging. Make sure you have it installed in your development machine. To install the development dependencies in a virtual environment, type:
The project uses [uv] for dependencies management and packaging. Make sure you have it installed in your development machine. To install the development dependencies in a virtual environment, type:

```shell
poetry install
uv sync
```

This will also generate a `poetry.lock` file, you should track this file in version control. To execute the test suite, call pytest inside Poetry's virtual environment via `poetry run`:
This will also generate a `uv.lock` file, you should track this file in version control. To execute the test suite, call pytest inside uv's virtual environment via `uv run`:

```shell
poetry run pytest
uv run pytest
```

Check out the [Poetry] documentation for more information on the available commands.
Check out the [uv] documentation for more information on the available commands.

### GitHub Actions

Expand All @@ -68,7 +68,7 @@ A `labels` workflow will also run and synchronise the GitHub labels based on the

The workflows need [a few secrets][gh-secrets] to be setup in your GitHub repository:

- `GH_PAT` a [personal access token (PAT) with the `repo` scope][create-pat] for opening pull requests and updating the repository topics. This is used by the `poetry-upgrade` and `labels` workflows.
- `GH_PAT` a [personal access token (PAT) with the `repo` scope][create-pat] for opening pull requests and updating the repository topics. This is used by the `upgrader` and `labels` workflows.
- `CODECOV_TOKEN` to upload coverage data to [codecov.io][codecov] in the Test workflow.

If you have the GitHub CLI installed and chose to set up GitHub, they will be created with a dummy value (`changeme`).
Expand Down Expand Up @@ -117,7 +117,7 @@ If your package is a reusable Django app, you should answer "yes" to the questio

#### Migrations

You should be able to use the provided `manage.py` to create migrations for your reusable app. Create or change your models and run `poetry run python manage.py makemigrations`.
You should be able to use the provided `manage.py` to create migrations for your reusable app. Create or change your models and run `uv run python manage.py makemigrations`.

### Pre-commit

Expand All @@ -133,7 +133,7 @@ To enable it, you might need to go [into your dashboard][rtd-dashboard] and impo

The project dependencies are kept up to date with [Renovate] which requires [the Github app][renovate-gh-app] to be installed.

The main advantage of Renovate over Dependabot is the auto-merge option, which is configured to automatically merge minor/patch updates with all the CI checks passing. It supports a variety of package managers, including Poetry, GitHub actions and pre-commit hooks which are used by default.
The main advantage of Renovate over Dependabot is the auto-merge option, which is configured to automatically merge minor/patch updates with all the CI checks passing. It supports a variety of package managers, including uv, GitHub actions and pre-commit hooks which are used by default.

### All contributors

Expand Down Expand Up @@ -168,7 +168,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!

[poetry]: https://python-poetry.org
[uv]: https://docs.astral.sh/uv/
[Typer]: https://typer.tiangolo.com
[Rich]: https://rich.readthedocs.io
[Ruff]: https://pypi.org/project/ruff/
Expand Down
10 changes: 5 additions & 5 deletions copier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ cli_name:
default: "{{ project_slug }}"
when: "{{ has_cli }}"

run_poetry_install:
run_uv_sync:
type: bool
help: "Run poetry install after {{ package_name }} generation?"
help: "Run uv sync install after {{ package_name }} generation?"
default: no

initial_commit:
Expand All @@ -102,12 +102,12 @@ add_me_as_contributor:
_min_copier_version: "9.0.0"
_subdirectory: "project"
_tasks:
# Remove license file if no license
# Remove licence file if no license
- "{% if open_source_license == 'Not open source' %}rm LICENSE{% endif %}"
# Cleanup docs
- "{% if not documentation %}rm -rf docs .readthedocs.yml{% endif %}"
# Run poetry install
- "{% if run_poetry_install %}poetry install{% endif %}"
# Run 'uv sync' to generate lockfile
- "{% if run_uv_sync %}uv sync{% endif %}"
# Initial commit
- "{% if initial_commit %}git init{% endif %}"
- "{% if initial_commit %}git add .{% endif %}"
Expand Down
Loading
Loading