Skip to content

Commit

Permalink
feat: more uv related changes
Browse files Browse the repository at this point in the history
  • Loading branch information
browniebroke committed Dec 20, 2024
1 parent a168df0 commit 3bf7cc7
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 92 deletions.
36 changes: 10 additions & 26 deletions project/.github/workflows/ci.yml.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -48,44 +48,27 @@ jobs:
steps:
- uses: actions/checkout@v4{% endraw %}
{%- if is_django_package %}{% raw %}
- name: Install poetry with export plugin
run: |
pipx install poetry
pipx inject poetry poetry-plugin-export
poetry config warnings.export false
- name: Poetry export dev deps
run: poetry export --without-hashes --only=dev --format=requirements.txt --output=requirements-dev.txt
shell: bash
- name: Set up Python
uses: actions/setup-python@v5
- uses: actions/setup-python@v5
with:
cache: pip
python-version: ${{ matrix.python-version }}
- name: Install test dependencies
run: pip install tox
- uses: astral-sh/setup-uv@v5
- run: uv pip install --system tox tox-uv
shell: bash
- name: Run tests
run: tox -f py$(echo ${{ matrix.python-version }} | tr -d .)
- run: tox -f py$(echo ${{ matrix.python-version }} | tr -d .)
shell: bash
{% endraw %}
{%- else %}{% raw %}
- name: Install poetry
run: pipx install poetry
- name: Set up Python
uses: actions/setup-python@v5
- uses: actions/setup-python@v5
id: setup-python
with:
python-version: ${{ matrix.python-version }}
cache: poetry
- 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{% endraw %}
{%- endif %}{% raw %}
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
- uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}

Expand Down Expand Up @@ -119,6 +102,7 @@ jobs:
if: github.ref_name != 'main'
with:
root_options: --noop
github_token: noop

# On main branch: actual PSR + upload to PyPI & GitHub
- name: Release
Expand Down
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: {% raw %}${{ secrets.GH_PAT }}{% endraw %}
4 changes: 2 additions & 2 deletions project/.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 project/.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: "CHANGELOG.md|.copier-answers.yml|.all-contributorsrc|project"
default_stages: [commit]
default_stages: [pre-commit]

ci:
autofix_commit_msg: "chore(pre-commit.ci): auto fixes"
Expand Down Expand Up @@ -31,10 +31,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
13 changes: 6 additions & 7 deletions project/.readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ build:
os: ubuntu-22.04
tools:
python: "3.12"
jobs:
post_create_environment:
# Install poetry
- python -m pip install poetry
post_install:
# Install dependencies, reusing RTD virtualenv
- VIRTUAL_ENV=$READTHEDOCS_VIRTUALENV_PATH poetry install --with docs
commands:
- asdf plugin add uv
- asdf install uv latest
- asdf global uv latest
- uv sync --only-group docs --frozen
- uv run -m sphinx -T -b html -d docs/_build/doctrees -D language=en docs $READTHEDOCS_OUTPUT/html

# Build documentation in the docs directory with Sphinx
sphinx:
Expand Down
6 changes: 3 additions & 3 deletions project/CONTRIBUTING.md.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ Ready to contribute? Here's how to set yourself up for local development.
$ git clone [email protected]:your_name_here/{{ project_slug }}.git
```

3. Install the project dependencies with [Poetry](https://python-poetry.org):
3. Install the project dependencies with [uv](https://docs.astral.sh/uv/):

```shell
$ poetry install
$ uv sync
```

4. Create a branch for local development:
Expand All @@ -63,7 +63,7 @@ Ready to contribute? Here's how to set yourself up for local development.
5. When you're done making changes, check that your changes pass our tests:

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

6. Linting is done through [pre-commit](https://pre-commit.com). Provided you have the tool installed globally, you can run them all as one-off:
Expand Down
4 changes: 2 additions & 2 deletions project/README.md.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
</a>
</p>
<p align="center">
<a href="https://python-poetry.org/">
<img src="https://img.shields.io/endpoint?url=https://python-poetry.org/badge/v0.json" alt="Poetry">
<a href="https://github.com/astral-sh/uv">
<img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json" alt="uv">
</a>
<a href="https://github.com/astral-sh/ruff">
<img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json" alt="Ruff">
Expand Down
91 changes: 48 additions & 43 deletions project/pyproject.toml.jinja
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
[build-system]
build-backend = "poetry.core.masonry.api"
requires = [ "poetry-core>=1.0.0" ]
build-backend = "setuptools.build_meta"
requires = [ "setuptools" ]

[tool.poetry]
[project]
name = "{{ project_slug }}"
version = "0.0.0"
description = "{{ project_short_description }}"
authors = [ "{{ full_name }} <{{ email }}>" ]
license = "{{ open_source_license }}"
readme = "README.md"
repository = "https://github.com/{{ github_username }}/{{ project_slug }}"
{%- if documentation %}
documentation = "https://{{ project_slug }}.readthedocs.io"
{%- endif %}
license = { text = "{{ open_source_license }}" }
authors = [
{ name = "{{ full_name }}", email = "{{ email }}" },
]
requires-python = ">=3.9"
classifiers = [
"Development Status :: 2 - Pre-Alpha",
"Intended Audience :: Developers",
Expand All @@ -24,47 +23,48 @@ classifiers = [
"Framework :: Django :: 5.0",
"Framework :: Django :: 5.1",
{%- endif %}
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Topic :: Software Development :: Libraries",
]
packages = [
{ include = "{{ package_name }}", from = "src" },
]

[tool.poetry.urls]
"Bug Tracker" = "https://github.com/{{ github_username }}/{{ project_slug }}/issues"
"Changelog" = "https://github.com/{{ github_username }}/{{ project_slug }}/blob/main/CHANGELOG.md"
dependencies = [
{%- if is_django_package %}
"django>=4.2",
{%- endif %}
{%- if has_cli %}
"rich>=10",
"typer>=0.15,<1",
{%- endif %}
]
urls."Bug Tracker" = "https://github.com/{{ github_username }}/{{ project_slug }}/issues"
urls.Changelog = "https://github.com/{{ github_username }}/{{ project_slug }}/blob/main/CHANGELOG.md"
{%- if documentation %}
urls.documentation = "https://{{ project_slug }}.readthedocs.io"
{%- endif %}
urls.repository = "https://github.com/{{ github_username }}/{{ project_slug }}"
{%- if has_cli %}

[tool.poetry.scripts]
{{ cli_name }} = "{{ package_name }}.cli:app"
scripts.{{ cli_name }} = "{{ package_name }}.cli:app"
{%- endif %}
[tool.poetry.dependencies]
python = "^3.9"
{%- if is_django_package %}
django = ">=4.2"
{%- endif %}
{%- if has_cli %}
rich = ">=10"
typer = { extras = [ "all" ], version = "^0.9.0" }
{%- endif %}

[tool.poetry.group.dev.dependencies]
pytest = "^8.0.0"
pytest-cov = "^5.0.0"
[dependency-groups]
dev = [
"pytest>=8,<9",
"pytest-cov>=6,<7",
{%- if is_django_package %}
pytest-django = "^4.5"
"pytest-django>=4.5,<5",
{%- endif %}
]
{%- if documentation %}

[tool.poetry.group.docs]
optional = true

[tool.poetry.group.docs.dependencies]
myst-parser = { version = ">=0.16", python = ">=3.11" }
sphinx = { version = ">=4.0", python = ">=3.11" }
furo = { version = ">=2023.5.20", python = ">=3.11" }
sphinx-autobuild = { version = ">=2024.0.0", python = ">=3.11" }
docs = [
"furo>=2023.5.20; python_version>='3.11'",
"myst-parser>=0.16; python_version>='3.11'",
"sphinx>=4; python_version>='3.11'",
"sphinx-autobuild>=2024,<2025; python_version>='3.11'",
]
{%- endif %}

[tool.ruff]
Expand Down Expand Up @@ -161,14 +161,19 @@ ignore_errors = true
{%- endif %}

[tool.semantic_release]
version_toml = [ "pyproject.toml:tool.poetry.version" ]
version_toml = [ "pyproject.toml:project.version" ]
version_variables = [
"src/{{ package_name }}/__init__.py:__version__",
{%- if documentation %}
"docs/conf.py:release",
{%- endif %}
]
build_command = "pip install poetry && poetry build"
build_command = """
pip install uv
uv lock
git add uv.lock
uv build
"""

[tool.semantic_release.changelog]
exclude_commit_patterns = [
Expand Down
6 changes: 2 additions & 4 deletions project/{% if is_django_package %}tox.ini{% endif %}.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ env_list =
[testenv]
set_env =
PYTHONDONTWRITEBYTECODE=1
dependency_groups =
dev
deps =
# Dev dependencies only, generated from Poetry deps with:
# poetry export --without-hashes --only=dev --format=requirements.txt --output=requirements-dev.txt
-r requirements-dev.txt
# All supported Django versions
django51: Django>=5.1,<5.2
django50: Django>=5.0,<5.1
django42: Django>=4.2,<5.0
Expand Down

0 comments on commit 3bf7cc7

Please sign in to comment.