Skip to content

Commit 2921bf1

Browse files
authored
Merge pull request #109 from smkent/poetry
Migrate to Poetry 2.0
2 parents dee411e + 3ebdf29 commit 2921bf1

37 files changed

+474
-401
lines changed

.github/workflows/actions/python-poetry/action.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ runs:
3333
# https://github.com/actions/runner-images/issues/6185
3434
PYTHON_KEYRING_BACKEND: "keyring.backends.null.Keyring"
3535
run: |
36-
poetry install
37-
poetry lock --check
36+
poetry check --lock
37+
poetry sync
3838
PROJECT_VERSION=$(poetry version -s)
3939
[ "${PROJECT_VERSION}" != "0.0.0" ] \
4040
|| { echo "Versioning broken"; exit 1; }

.github/workflows/cd.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ env:
55
ENABLE_PYPI_PUBLISH: true
66
ENABLE_TEST_PYPI_PUBLISH: true
77
RELEASE_PYTHON_VERSION: "3.12"
8-
RELEASE_POETRY_VERSION: "1.8"
8+
RELEASE_POETRY_VERSION: "2.0"
99

1010
on:
1111
push:

.github/workflows/ci.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,12 @@ jobs:
2020
os:
2121
- Ubuntu
2222
python-version:
23-
- "3.8"
2423
- "3.9"
2524
- "3.10"
2625
- "3.11"
2726
- "3.12"
2827
poetry-version:
29-
- "1.8"
28+
- "2.0"
3029

3130
runs-on: ${{ matrix.os }}-latest
3231
steps:

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ repos:
4242
rev: v3.16.0
4343
hooks:
4444
- id: pyupgrade
45-
args: ["--keep-runtime-typing"]
45+
args: ["--py39-plus", "--keep-runtime-typing"]
4646
- repo: local
4747
hooks:
4848
- id: mypy

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ Via [`pipx`][pipx]:
3131
```console
3232
pip install pipx
3333
pipx install poetry
34-
pipx inject poetry poetry-dynamic-versioning poetry-pre-commit-plugin
34+
pipx inject poetry poetry-pre-commit-plugin
3535
```
3636

3737
Via `pip`:
3838

3939
```console
4040
pip install poetry
41-
poetry self add poetry-dynamic-versioning poetry-pre-commit-plugin
41+
poetry self add poetry-pre-commit-plugin
4242
```
4343

4444
## New project creation

cookie_python/manage/repo.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def run(
117117
return subprocess.run(*popenargs, check=check, **kwargs)
118118

119119
def shell(self) -> None:
120-
if sys.__stdin__.isatty():
120+
if sys.__stdin__ and sys.__stdin__.isatty():
121121
self.logger.info('Starting shell. Run "exit 1" to abort.')
122122
self.run([os.environ.get("SHELL", "/bin/bash")])
123123

cookie_python/manage/update.py

+1
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,4 @@ def update_action(repo: RepoSandbox) -> None:
134134
repo.logger.info(f"Updated {actions_str}")
135135
repo.commit_changes(message)
136136
repo.open_pr(message)
137+
repo.run(["poetry", "env", "remove", "--all"], check=False)

cookie_python/new.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
import subprocess
44
import time
55
from pathlib import Path
6-
from typing import List, Tuple
76

87
TEMPLATE_REPOSITORY_URL = "https://github.com/smkent/cookie-python"
98

109

11-
def parse_args() -> Tuple[argparse.Namespace, List[str]]:
10+
def parse_args() -> tuple[argparse.Namespace, list[str]]:
1211
ap = argparse.ArgumentParser()
1312
ap.add_argument(
1413
"project_dir", help="New project parent directory", type=str

hooks/post_gen_project.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
import os
33
import shutil
44
import subprocess
5-
from typing import Dict, List
65

76
import yaml
87

98
TEMPLATE_ONLY_DATA = "cookiecutter_template_data"
109

1110

12-
def _run(call: List[str], env: Dict[str, str]) -> None:
11+
def _run(call: list[str], env: dict[str, str]) -> None:
1312
subprocess.run(call, env=env).check_returncode()
1413

1514

poetry.lock

+300-229
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+24-15
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
[build-system]
2-
requires = ["poetry-core>=1.2.0", "poetry-dynamic-versioning"]
3-
build-backend = "poetry_dynamic_versioning.backend"
2+
requires = ["poetry-core>=2.0.0,<3.0.0", "poetry-dynamic-versioning"]
3+
build-backend = "poetry.core.masonry.api"
44

5-
[tool.poetry]
5+
[project]
66
name = "cookie-python"
7-
version = "0.0.0"
87
description = ""
98
license = "MIT"
10-
authors = ["Stephen Kent <smkent@smkent.net>"]
9+
authors = [ { name = "Stephen Kent", email = "smkent@smkent.net" } ]
1110
readme = "README.md"
1211
repository = "https://github.com/smkent/cookie-python"
1312
classifiers = [
@@ -17,19 +16,31 @@ classifiers = [
1716
"Topic :: Software Development :: Libraries :: Python Modules",
1817
"Typing :: Typed",
1918
]
19+
requires-python = ">=3.9"
20+
dynamic = [ "version" ]
21+
dependencies = [
22+
"loguru",
23+
"pygithub",
24+
"pyyaml",
25+
"semver",
26+
"toml ; python_version < '3.11'",
27+
]
28+
29+
[project.scripts]
30+
new-cookie = "cookie_python.new:main"
31+
manage-cookie = "cookie_python.manage.main:main"
32+
33+
[tool.poetry]
2034
packages = [
2135
{ include = "{{cookiecutter.project_name}}" }
2236
]
37+
requires-poetry = ">=2.0"
38+
version = "0.0.0"
2339

24-
[tool.poetry.dependencies]
25-
python = "^3.8"
26-
loguru = "*"
27-
poetry-dynamic-versioning = "*"
28-
pygithub = "*"
29-
pyyaml = "*"
30-
semver = "*"
40+
[tool.poetry.requires-plugins]
41+
poetry-dynamic-versioning = { version = ">=1.0.0,<2.0.0", extras = ["plugin"] }
3142

32-
[tool.poetry.dev-dependencies]
43+
[tool.poetry.group.dev.dependencies]
3344
bandit = {extras = ["toml"], version = "*"}
3445
black = "*"
3546
build = "*"
@@ -51,8 +62,6 @@ pytest-sugar = "*"
5162
types-PyYAML = "*"
5263

5364
[tool.poetry.scripts]
54-
new-cookie = "cookie_python.new:main"
55-
manage-cookie = "cookie_python.manage.main:main"
5665

5766
[tool.poetry-dynamic-versioning]
5867
enable = true

tests/conftest.py

+68-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,41 @@
1+
import json
12
import os
3+
import subprocess
4+
import sys
5+
from pathlib import Path
26
from tempfile import TemporaryDirectory
3-
from typing import Iterator
7+
from collections.abc import Iterator
8+
from unittest.mock import patch
49

510
import pytest
611

12+
from cookie_python.new import main as new_cookie_main
13+
14+
AUTHOR_NAME = "Ness"
15+
AUTHOR_EMAIL = "ness@onett.example"
16+
PROJECT_NAME = "unit-test-1"
17+
18+
19+
@pytest.fixture
20+
def project_environment() -> Iterator[None]:
21+
add_values = dict(
22+
GIT_AUTHOR_NAME=AUTHOR_NAME,
23+
GIT_AUTHOR_EMAIL=AUTHOR_EMAIL,
24+
GIT_COMMITTER_NAME=AUTHOR_NAME,
25+
GIT_COMMITTER_EMAIL=AUTHOR_EMAIL,
26+
GITHUB_API_TOKEN="unittest_token",
27+
)
28+
with patch.dict(os.environ, add_values):
29+
yield
30+
31+
32+
@pytest.fixture(scope="session", autouse=True)
33+
def subprocess_environment() -> Iterator[None]:
34+
with patch.dict(os.environ, {}) as patched_env:
35+
if "VIRTUAL_ENV" in patched_env:
36+
del patched_env["VIRTUAL_ENV"]
37+
yield
38+
739

840
def pytest_addoption(parser: pytest.Parser) -> None:
941
group = parser.getgroup("cookie", "python-cookie test helpers")
@@ -23,6 +55,39 @@ def opt_update_expected_outputs(request: pytest.FixtureRequest) -> bool:
2355

2456

2557
@pytest.fixture
26-
def temp_dir() -> Iterator[str]:
58+
def temp_dir() -> Iterator[Path]:
2759
with TemporaryDirectory(prefix="cookie-python.unittest.") as td:
28-
yield os.path.join(td)
60+
yield Path(td)
61+
62+
63+
@pytest.fixture(params=["@"])
64+
def new_cookie(
65+
request: pytest.FixtureRequest, project_environment: None, temp_dir: Path
66+
) -> Iterator[Path]:
67+
testargs = [
68+
"new-cookie",
69+
"--local",
70+
str(temp_dir),
71+
"--",
72+
"-d",
73+
"-y",
74+
"--extra-context",
75+
json.dumps(
76+
{
77+
"author_email": AUTHOR_EMAIL,
78+
"author_name": AUTHOR_NAME,
79+
"github_user": "ness.unittest.example",
80+
"project_description": "Unit test project",
81+
"project_name": PROJECT_NAME,
82+
"enable_container_publish": "yes",
83+
}
84+
),
85+
"-c",
86+
request.param,
87+
]
88+
with patch.object(sys, "argv", testargs):
89+
new_cookie_main()
90+
project_dir = temp_dir / PROJECT_NAME
91+
yield project_dir
92+
if (project_dir / "pyproject.toml").is_file():
93+
subprocess.run(["poetry", "env", "remove", "--all"], cwd=project_dir)

tests/data/readme-github_user_only.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ Via [`pipx`][pipx]:
1212
```console
1313
pip install pipx
1414
pipx install poetry
15-
pipx inject poetry poetry-dynamic-versioning poetry-pre-commit-plugin
15+
pipx inject poetry poetry-pre-commit-plugin
1616
```
1717

1818
Via `pip`:
1919

2020
```console
2121
pip install poetry
22-
poetry self add poetry-dynamic-versioning poetry-pre-commit-plugin
22+
poetry self add poetry-pre-commit-plugin
2323
```
2424

2525
### Development tasks

tests/data/readme-github_user_with_container.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ Via [`pipx`][pipx]:
3737
```console
3838
pip install pipx
3939
pipx install poetry
40-
pipx inject poetry poetry-dynamic-versioning poetry-pre-commit-plugin
40+
pipx inject poetry poetry-pre-commit-plugin
4141
```
4242

4343
Via `pip`:
4444

4545
```console
4646
pip install poetry
47-
poetry self add poetry-dynamic-versioning poetry-pre-commit-plugin
47+
poetry self add poetry-pre-commit-plugin
4848
```
4949

5050
### Development tasks

tests/data/readme-github_user_with_coverage.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ Via [`pipx`][pipx]:
1313
```console
1414
pip install pipx
1515
pipx install poetry
16-
pipx inject poetry poetry-dynamic-versioning poetry-pre-commit-plugin
16+
pipx inject poetry poetry-pre-commit-plugin
1717
```
1818

1919
Via `pip`:
2020

2121
```console
2222
pip install poetry
23-
poetry self add poetry-dynamic-versioning poetry-pre-commit-plugin
23+
poetry self add poetry-pre-commit-plugin
2424
```
2525

2626
### Development tasks

tests/data/readme-github_user_with_coverage_and_container.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ Via [`pipx`][pipx]:
3838
```console
3939
pip install pipx
4040
pipx install poetry
41-
pipx inject poetry poetry-dynamic-versioning poetry-pre-commit-plugin
41+
pipx inject poetry poetry-pre-commit-plugin
4242
```
4343

4444
Via `pip`:
4545

4646
```console
4747
pip install poetry
48-
poetry self add poetry-dynamic-versioning poetry-pre-commit-plugin
48+
poetry self add poetry-pre-commit-plugin
4949
```
5050

5151
### Development tasks

tests/data/readme-github_user_with_coverage_and_pypi.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ Via [`pipx`][pipx]:
4848
```console
4949
pip install pipx
5050
pipx install poetry
51-
pipx inject poetry poetry-dynamic-versioning poetry-pre-commit-plugin
51+
pipx inject poetry poetry-pre-commit-plugin
5252
```
5353

5454
Via `pip`:
5555

5656
```console
5757
pip install poetry
58-
poetry self add poetry-dynamic-versioning poetry-pre-commit-plugin
58+
poetry self add poetry-pre-commit-plugin
5959
```
6060

6161
### Development tasks

tests/data/readme-github_user_with_coverage_pypi_and_container.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ Via [`pipx`][pipx]:
4848
```console
4949
pip install pipx
5050
pipx install poetry
51-
pipx inject poetry poetry-dynamic-versioning poetry-pre-commit-plugin
51+
pipx inject poetry poetry-pre-commit-plugin
5252
```
5353

5454
Via `pip`:
5555

5656
```console
5757
pip install poetry
58-
poetry self add poetry-dynamic-versioning poetry-pre-commit-plugin
58+
poetry self add poetry-pre-commit-plugin
5959
```
6060

6161
### Development tasks

tests/data/readme-github_user_with_pypi.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ Via [`pipx`][pipx]:
2222
```console
2323
pip install pipx
2424
pipx install poetry
25-
pipx inject poetry poetry-dynamic-versioning poetry-pre-commit-plugin
25+
pipx inject poetry poetry-pre-commit-plugin
2626
```
2727

2828
Via `pip`:
2929

3030
```console
3131
pip install poetry
32-
poetry self add poetry-dynamic-versioning poetry-pre-commit-plugin
32+
poetry self add poetry-pre-commit-plugin
3333
```
3434

3535
### Development tasks

tests/data/readme-github_user_with_pypi_and_container.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ Via [`pipx`][pipx]:
2222
```console
2323
pip install pipx
2424
pipx install poetry
25-
pipx inject poetry poetry-dynamic-versioning poetry-pre-commit-plugin
25+
pipx inject poetry poetry-pre-commit-plugin
2626
```
2727

2828
Via `pip`:
2929

3030
```console
3131
pip install poetry
32-
poetry self add poetry-dynamic-versioning poetry-pre-commit-plugin
32+
poetry self add poetry-pre-commit-plugin
3333
```
3434

3535
### Development tasks

0 commit comments

Comments
 (0)