Skip to content

Commit 29d97db

Browse files
authored
Merge pull request #91 from Pavkazzz/feature/poetry-2-support
Add py3.13 and poetry v2
2 parents 2da3dff + fbeb8cc commit 29d97db

File tree

7 files changed

+473
-282
lines changed

7 files changed

+473
-282
lines changed

.github/workflows/tests.yml

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,35 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- uses: actions/checkout@v4
14-
- name: Setup python3.10
14+
- name: Setup python3.12
1515
uses: actions/setup-python@v5
1616
with:
17-
python-version: "3.10"
18-
- run: python -m pip install poetry
17+
python-version: "3.12"
18+
- name: Install poetry
19+
uses: abatilo/actions-poetry@v3
20+
with:
21+
poetry-version: latest
1922
- run: poetry install
2023
- run: poetry run pylama poem_plugins
2124
env:
2225
FORCE_COLOR: 1
2326
mypy:
2427
runs-on: ubuntu-latest
28+
strategy:
29+
fail-fast: false
30+
31+
matrix:
32+
poetry-version: ["latest", "2.0.1", "1.8.4"]
2533
steps:
2634
- uses: actions/checkout@v4
27-
- name: Setup python3.10
35+
- name: Setup python3.12
2836
uses: actions/setup-python@v5
2937
with:
30-
python-version: "3.10"
31-
- run: python -m pip install poetry
38+
python-version: "3.12"
39+
- name: Install poetry
40+
uses: abatilo/actions-poetry@v3
41+
with:
42+
poetry-version: ${{ matrix.poetry-version }}
3243
- run: poetry install
3344
- run: poetry run mypy
3445
env:
@@ -45,13 +56,17 @@ jobs:
4556
- "3.10"
4657
- "3.11"
4758
- "3.12"
59+
- "3.13"
4860
steps:
4961
- uses: actions/checkout@v4
5062
- name: Setup python${{ matrix.python }}
5163
uses: actions/setup-python@v5
5264
with:
5365
python-version: "${{ matrix.python }}"
54-
- run: python -m pip install poetry
66+
- name: Install poetry
67+
uses: abatilo/actions-poetry@v3
68+
with:
69+
poetry-version: latest
5570
- run: poetry install
5671
- run: >-
5772
poetry run pytest \

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@ behavior. Here are some of the arguments that you can use:
3939
| Name | description | Default |
4040
|-------|-------------|---------|
4141
| `update_pyproject` | plugin will not only use version from provider for building, but save it in `pyproject.toml` | `false` |
42+
| `update_pyproject_place` | place to update version in `pyproject.toml`. Use `project` with [PEP 621](https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#version) compatability | `tool.poetry` |
4243
| `write_version_file` | plugin will create a file `version.py` inside a module, with version information | `false` |
4344
| `version_file_quotes` | plugin will replace default quotes in `version.py` file with provided by: `'` or `"` | `unset` |
4445

46+
4547
You can specify provider-specific settings in your configuration.
4648
To specify provider-specific settings, you can use the `tool.poem-plugins.version.{provider}` section.
4749
Here are some of the arguments that you can use for `git` provider:

poem_plugins/config/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,19 @@ class QuotesEnum(StrEnum):
1919
single = "'"
2020

2121

22+
@unique
23+
class VersionPlaceEnum(StrEnum):
24+
TOOL_POETRY = "tool.poetry"
25+
PROJECT = "project"
26+
27+
2228
@dataclass
2329
class VersionConfig(BaseConfig):
2430
MAPPERS = MappingProxyType(
2531
{
2632
"provider": VersionProviderEnum,
2733
"update_pyproject": bool,
34+
"update_pyproject_place": VersionPlaceEnum,
2835
"write_version_file": bool,
2936
"git": GitProviderSettings.fabric,
3037
"quote": QuotesEnum,
@@ -34,6 +41,7 @@ class VersionConfig(BaseConfig):
3441
provider: Optional[VersionProviderEnum] = None
3542

3643
update_pyproject: bool = False
44+
update_pyproject_place: VersionPlaceEnum = VersionPlaceEnum.TOOL_POETRY
3745
write_version_file: bool = False
3846
version_file_quotes: Optional[QuotesEnum] = None
3947

poem_plugins/handlers/version.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
from dataclasses import dataclass
2-
from typing import Optional
2+
from typing import Container, Optional
33

44
from cleo.io.io import IO
55
from poetry.core.utils.helpers import module_name
66
from poetry.poetry import Poetry
7-
from tomlkit import TOMLDocument
7+
from tomlkit import TOMLDocument, item
88

9-
from poem_plugins.config import QuotesEnum, VersionConfig, VersionProviderEnum
9+
from poem_plugins.config import (
10+
QuotesEnum,
11+
VersionConfig,
12+
VersionPlaceEnum,
13+
VersionProviderEnum,
14+
)
1015
from poem_plugins.general.version import Version
1116
from poem_plugins.general.version.drivers import IVersionDriver
1217
from poem_plugins.general.version.drivers.git import GitVersionDriver
1318
from poem_plugins.handlers import IHandler
19+
from poetry.core.constraints.version import Version as pcVersion
1420

1521

1622
@dataclass(frozen=True)
@@ -41,7 +47,7 @@ def handle(self, poetry: Poetry, io: IO) -> None:
4147
io.write_line(
4248
f"<b>poem-plugins</b>: Setting version to: {version}",
4349
)
44-
poetry.package.version = str(version) # type: ignore
50+
poetry.package.version = pcVersion.parse(str(version))
4551

4652
if self.config.update_pyproject:
4753
self._write_pyproject(poetry, version)
@@ -59,8 +65,23 @@ def _write_pyproject(
5965
version: Version,
6066
) -> None:
6167
content: TOMLDocument = poetry.file.read()
62-
poetry_content = content["tool"]["poetry"] # type: ignore
63-
poetry_content["version"] = str(version) # type: ignore
68+
69+
if self.config.update_pyproject_place == VersionPlaceEnum.PROJECT:
70+
if "project" not in content:
71+
content["project"] = {}
72+
if isinstance(content["project"], Container):
73+
content["project"]["version"] = item(str(version))
74+
75+
elif self.config.update_pyproject_place == VersionPlaceEnum.TOOL_POETRY:
76+
if "tool" not in content:
77+
content["tool"] = {}
78+
if "poetry" not in content["tool"]: # type: ignore
79+
content["tool"]["poetry"] = {} # type: ignore
80+
content["tool"]["poetry"]["version"] = str(version) # type: ignore
81+
else:
82+
upp = self.config.update_pyproject_place
83+
raise ValueError(f"Unknown place: {upp}")
84+
6485
poetry.file.write(content)
6586

6687
def _write_module(

0 commit comments

Comments
 (0)