Skip to content

Commit bf11879

Browse files
authored
feat: upgrade to Poetry v2.0 (#266)
1 parent 6e72fd9 commit bf11879

File tree

5 files changed

+62
-56
lines changed

5 files changed

+62
-56
lines changed

{{ cookiecutter.__project_name_kebab_case }}/.github/workflows/test.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,3 @@ jobs:
4040

4141
- name: Test {{ cookiecutter.project_type }}
4242
run: devcontainer exec --workspace-folder . poe test
43-
44-
- name: Upload coverage
45-
uses: codecov/codecov-action@v5
46-
with:
47-
files: reports/coverage.xml

{{ cookiecutter.__project_name_kebab_case }}/.pre-commit-config.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ repos:
1616
- id: rst-inline-touching-normal
1717
- id: text-unicode-replacement-char
1818
- repo: https://github.com/pre-commit/pre-commit-hooks
19-
rev: v4.5.0
19+
rev: v5.0.0
2020
hooks:
2121
- id: check-added-large-files
2222
- id: check-ast
2323
- id: check-builtin-literals
2424
- id: check-case-conflict
2525
- id: check-docstring-first
26+
- id: check-illegal-windows-names
2627
- id: check-json
2728
- id: check-merge-conflict
2829
- id: check-shebang-scripts-are-executable

{{ cookiecutter.__project_name_kebab_case }}/Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ FROM base AS poetry
3737
USER root
3838

3939
# Install Poetry in separate venv so it doesn't pollute the main venv.
40-
ENV POETRY_VERSION 1.8.0
40+
ENV POETRY_VERSION 2.0.1
4141
ENV POETRY_VIRTUAL_ENV /opt/poetry-env
4242
RUN --mount=type=cache,target=/root/.cache/pip/ \
4343
python -m venv $POETRY_VIRTUAL_ENV && \
@@ -60,7 +60,7 @@ RUN --mount=type=cache,uid=$UID,gid=$GID,target=/home/user/.cache/pypoetry/ \
6060
{%- if cookiecutter.private_package_repository_name %}
6161
--mount=type=secret,id=poetry-auth,uid=$UID,gid=$GID,target=/home/user/.config/pypoetry/auth.toml \
6262
{%- endif %}
63-
poetry install --only main --all-extras --no-interaction
63+
poetry install --without test,dev --all-extras --no-interaction
6464

6565

6666

@@ -93,7 +93,7 @@ RUN mkdir -p /opt/build/poetry/ && cp poetry.lock /opt/build/poetry/ && \
9393
mkdir -p /opt/build/git/ && cp .git/hooks/commit-msg .git/hooks/pre-commit /opt/build/git/
9494

9595
# Configure the non-root user's shell.
96-
ENV ANTIDOTE_VERSION 1.8.6
96+
ENV ANTIDOTE_VERSION 1.9.7
9797
RUN git clone --branch v$ANTIDOTE_VERSION --depth=1 https://github.com/mattmc3/antidote.git ~/.antidote/ && \
9898
echo 'zsh-users/zsh-syntax-highlighting' >> ~/.zsh_plugins.txt && \
9999
echo 'zsh-users/zsh-autosuggestions' >> ~/.zsh_plugins.txt && \

{{ cookiecutter.__project_name_kebab_case }}/pyproject.toml

Lines changed: 56 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,69 +2,72 @@
22
requires = ["poetry-core>=1.0.0"]
33
build-backend = "poetry.core.masonry.api"
44

5-
[tool.poetry] # https://python-poetry.org/docs/pyproject/
5+
[project] # https://packaging.python.org/en/latest/specifications/pyproject-toml/
66
name = "{{ cookiecutter.__project_name_kebab_case }}"
77
version = "0.0.0"
88
description = "{{ cookiecutter.project_description }}"
9-
authors = ["{{ cookiecutter.author_name }} <{{ cookiecutter.author_email }}>"]
109
readme = "README.md"
11-
repository = "{{ cookiecutter.project_url }}"
12-
{%- if cookiecutter.with_conventional_commits|int %}
13-
14-
[tool.commitizen] # https://commitizen-tools.github.io/commitizen/config/
15-
bump_message = "bump(release): v$current_version → v$new_version"
16-
tag_format = "v$version"
17-
update_changelog_on_bump = true
18-
version_provider = "poetry"
19-
{%- endif %}
10+
license-files = ["LICENSE*"]
11+
authors = [
12+
{ name = "{{ cookiecutter.author_name }}", email = "{{ cookiecutter.author_email }}" },
13+
]
14+
requires-python = ">={{ cookiecutter.python_version }},<4.0"
15+
dependencies = [
16+
{%- if cookiecutter.with_fastapi_api|int %}
17+
"fastapi[all] (>=0.115.6)",
18+
"gunicorn (>=23.0.0)",
19+
{%- endif %}
20+
{%- if cookiecutter.project_type == "app" %}
21+
"poethepoet (>=0.32.1)",
22+
{%- endif %}
23+
{%- if cookiecutter.with_typer_cli|int %}
24+
"typer[all] (>=0.15.1)",
25+
{%- endif %}
26+
{%- if cookiecutter.with_fastapi_api|int %}
27+
"uvicorn[standard] (>=0.34.0)",
28+
{%- endif %}
29+
]
2030
{%- if cookiecutter.with_typer_cli|int %}
2131

22-
[tool.poetry.scripts] # https://python-poetry.org/docs/pyproject/#scripts
32+
[project.scripts] # https://python-poetry.org/docs/pyproject/#scripts
2333
{{ cookiecutter.__project_name_kebab_case }} = "{{ cookiecutter.__project_name_snake_case }}.cli:app"
2434
{%- endif %}
2535

26-
[tool.poetry.dependencies] # https://python-poetry.org/docs/dependency-specification/
27-
{%- if cookiecutter.with_fastapi_api|int %}
28-
coloredlogs = ">=15.0.1"
29-
fastapi = { extras = ["all"], version = ">=0.110.1" }
30-
gunicorn = ">=21.2.0"
31-
{%- endif %}
32-
{%- if cookiecutter.project_type == "app" %}
33-
poethepoet = ">=0.25.0"
34-
{%- endif %}
35-
python = ">={{ cookiecutter.python_version }},<4.0"
36-
{%- if cookiecutter.with_typer_cli|int %}
37-
typer = { extras = ["all"], version = ">=0.12.0" }
38-
{%- endif %}
39-
{%- if cookiecutter.with_fastapi_api|int %}
40-
uvicorn = { extras = ["standard"], version = ">=0.29.0" }
36+
[project.urls] # https://packaging.python.org/en/latest/specifications/well-known-project-urls/#well-known-labels
37+
homepage = "{{ cookiecutter.project_url }}"
38+
source = "{{ cookiecutter.project_url }}"
39+
{%- if cookiecutter.with_conventional_commits|int %}
40+
changelog = "{{ cookiecutter.project_url }}/{% if cookiecutter.continuous_integration == "GitLab" %}-/{% endif %}blob/main/CHANGELOG.md"
4141
{%- endif %}
42+
releasenotes = "{{ cookiecutter.project_url }}/{% if cookiecutter.continuous_integration == "GitLab" %}-/{% endif %}releases"
43+
documentation = "{{ cookiecutter.project_url }}"
44+
issues = "{{ cookiecutter.project_url }}/{% if cookiecutter.continuous_integration == "GitLab" %}-/{% endif %}issues"
4245

43-
[tool.poetry.group.test.dependencies] # https://python-poetry.org/docs/master/managing-dependencies/
46+
[tool.poetry.group.test.dependencies] # https://python-poetry.org/docs/managing-dependencies#dependency-groups
4447
{%- if cookiecutter.with_conventional_commits|int %}
45-
commitizen = ">=3.21.3"
48+
commitizen = ">=4.1.0"
4649
{%- endif %}
47-
coverage = { extras = ["toml"], version = ">=7.4.4" }
48-
mypy = ">=1.9.0"
50+
coverage = { extras = ["toml"], version = ">=7.6.10" }
51+
mypy = ">=1.14.1"
4952
{%- if cookiecutter.project_type == "package" %}
50-
poethepoet = ">=0.25.0"
53+
poethepoet = ">=0.32.1"
5154
{%- endif %}
52-
pre-commit = ">=3.7.0"
53-
pytest = ">=8.1.1"
55+
pre-commit = ">=4.0.1"
56+
pytest = ">=8.3.4"
5457
pytest-mock = ">=3.14.0"
55-
pytest-xdist = ">=3.5.0"
56-
ruff = ">=0.5.7"
58+
pytest-xdist = ">=3.6.1"
59+
ruff = ">=0.9.2"
5760
{%- if cookiecutter.development_environment == "strict" %}
5861
shellcheck-py = ">=0.10.0.1"
59-
typeguard = ">=4.2.1"
62+
typeguard = ">=4.4.1"
6063
{%- endif %}
6164

62-
[tool.poetry.group.dev.dependencies] # https://python-poetry.org/docs/master/managing-dependencies/
63-
cruft = ">=2.15.0"
65+
[tool.poetry.group.dev.dependencies] # https://python-poetry.org/docs/managing-dependencies#dependency-groups
66+
cruft = ">=2.16.0"
6467
ipykernel = ">=6.29.4"
6568
ipython = ">=8.18.0"
6669
ipywidgets = ">=8.1.2"
67-
pdoc = ">=14.4.0"
70+
pdoc = ">=15.0.1"
6871
{%- if cookiecutter.private_package_repository_name %}
6972

7073
[[tool.poetry.source]]
@@ -76,6 +79,14 @@ name = "{{ cookiecutter.private_package_repository_name|slugify }}"
7679
url = "{{ cookiecutter.private_package_repository_url }}"
7780
priority = "explicit"
7881
{%- endif %}
82+
{%- if cookiecutter.with_conventional_commits|int %}
83+
84+
[tool.commitizen] # https://commitizen-tools.github.io/commitizen/config/
85+
bump_message = "bump(release): v$current_version → v$new_version"
86+
tag_format = "v$version"
87+
update_changelog_on_bump = true
88+
version_provider = "poetry"
89+
{%- endif %}
7990

8091
[tool.coverage.report] # https://coverage.readthedocs.io/en/latest/config.html#report
8192
{%- if cookiecutter.development_environment == "strict" %}
@@ -127,15 +138,18 @@ filterwarnings = ["error", "ignore::DeprecationWarning"]
127138
testpaths = ["src", "tests"]
128139
xfail_strict = true
129140

130-
[tool.ruff] # https://github.com/charliermarsh/ruff
141+
[tool.ruff] # https://docs.astral.sh/ruff/settings/
131142
fix = true
132143
line-length = 100
133144
src = ["src", "tests"]
134145
target-version = "py{{ cookiecutter.python_version.split('.')[:2]|join }}"
135146

147+
[tool.ruff.format]
148+
docstring-code-format = true
149+
136150
[tool.ruff.lint]
137151
{%- if cookiecutter.development_environment == "strict" %}
138-
select = ["A", "ASYNC", "B", "BLE", "C4", "C90", "D", "DTZ", "E", "EM", "ERA", "F", "FBT", "FLY", "FURB", "G", "I", "ICN", "INP", "INT", "ISC", "LOG", "N", "NPY", "PERF", "PGH", "PIE", "PL", "PT", "PTH", "PYI", "Q", "RET", "RSE", "RUF", "S", "SIM", "SLF", "SLOT", "T10", "T20", "TCH", "TID", "TRY", "UP", "W", "YTT"]
152+
select = ["A", "ASYNC", "B", "BLE", "C4", "C90", "D", "DTZ", "E", "EM", "ERA", "F", "FBT", "FLY", "FURB", "G", "I", "ICN", "INP", "INT", "ISC", "LOG", "N", "NPY", "PERF", "PGH", "PIE", "PL", "PT", "PTH", "PYI", "Q", "RET", "RSE", "RUF", "S", "SIM", "SLF", "SLOT", "T10", "T20", "TC", "TID", "TRY", "UP", "W", "YTT"]
139153
ignore = ["D203", "D213", "E501", "RET504", "S101", "S307"]
140154
unfixable = ["ERA001", "F401", "F841", "T201", "T203"]
141155
{%- else %}

{{ cookiecutter.__project_name_kebab_case }}/src/{{ cookiecutter.__project_name_snake_case }}/api.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,15 @@
55
from collections.abc import AsyncGenerator
66
from contextlib import asynccontextmanager
77

8-
import coloredlogs
98
from fastapi import FastAPI
109

1110

1211
@asynccontextmanager
1312
async def lifespan(app: FastAPI) -> AsyncGenerator[None, None]:
1413
"""Handle FastAPI startup and shutdown events."""
15-
# Startup events:
16-
# - Remove all handlers associated with the root logger object.
14+
# Startup events.
1715
for handler in logging.root.handlers:
1816
logging.root.removeHandler(handler)
19-
# - Add coloredlogs' colored StreamHandler to the root logger.
20-
coloredlogs.install()
2117
yield
2218
# Shutdown events.
2319

0 commit comments

Comments
 (0)