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

Add py3.13 and poetry v2 #91

Merged
merged 6 commits into from
Jan 21, 2025
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
29 changes: 22 additions & 7 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,35 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup python3.10
- name: Setup python3.12
uses: actions/setup-python@v5
with:
python-version: "3.10"
- run: python -m pip install poetry
python-version: "3.12"
- name: Install poetry
uses: abatilo/actions-poetry@v3
with:
poetry-version: latest
- run: poetry install
- run: poetry run pylama poem_plugins
env:
FORCE_COLOR: 1
mypy:
runs-on: ubuntu-latest
strategy:
fail-fast: false

matrix:
poetry-version: ["latest", "2.0.1", "1.8.4"]
steps:
- uses: actions/checkout@v4
- name: Setup python3.10
- name: Setup python3.12
uses: actions/setup-python@v5
with:
python-version: "3.10"
- run: python -m pip install poetry
python-version: "3.12"
- name: Install poetry
uses: abatilo/actions-poetry@v3
with:
poetry-version: ${{ matrix.poetry-version }}
- run: poetry install
- run: poetry run mypy
env:
Expand All @@ -45,13 +56,17 @@ jobs:
- "3.10"
- "3.11"
- "3.12"
- "3.13"
steps:
- uses: actions/checkout@v4
- name: Setup python${{ matrix.python }}
uses: actions/setup-python@v5
with:
python-version: "${{ matrix.python }}"
- run: python -m pip install poetry
- name: Install poetry
uses: abatilo/actions-poetry@v3
with:
poetry-version: latest
- run: poetry install
- run: >-
poetry run pytest \
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ behavior. Here are some of the arguments that you can use:
| Name | description | Default |
|-------|-------------|---------|
| `update_pyproject` | plugin will not only use version from provider for building, but save it in `pyproject.toml` | `false` |
| `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` |
| `write_version_file` | plugin will create a file `version.py` inside a module, with version information | `false` |
| `version_file_quotes` | plugin will replace default quotes in `version.py` file with provided by: `'` or `"` | `unset` |


You can specify provider-specific settings in your configuration.
To specify provider-specific settings, you can use the `tool.poem-plugins.version.{provider}` section.
Here are some of the arguments that you can use for `git` provider:
Expand Down
8 changes: 8 additions & 0 deletions poem_plugins/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,19 @@ class QuotesEnum(StrEnum):
single = "'"


@unique
class VersionPlaceEnum(StrEnum):
TOOL_POETRY = "tool.poetry"
PROJECT = "project"


@dataclass
class VersionConfig(BaseConfig):
MAPPERS = MappingProxyType(
{
"provider": VersionProviderEnum,
"update_pyproject": bool,
"update_pyproject_place": VersionPlaceEnum,
"write_version_file": bool,
"git": GitProviderSettings.fabric,
"quote": QuotesEnum,
Expand All @@ -34,6 +41,7 @@ class VersionConfig(BaseConfig):
provider: Optional[VersionProviderEnum] = None

update_pyproject: bool = False
update_pyproject_place: VersionPlaceEnum = VersionPlaceEnum.TOOL_POETRY
write_version_file: bool = False
version_file_quotes: Optional[QuotesEnum] = None

Expand Down
33 changes: 27 additions & 6 deletions poem_plugins/handlers/version.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
from dataclasses import dataclass
from typing import Optional
from typing import Container, Optional

from cleo.io.io import IO
from poetry.core.utils.helpers import module_name
from poetry.poetry import Poetry
from tomlkit import TOMLDocument
from tomlkit import TOMLDocument, item

from poem_plugins.config import QuotesEnum, VersionConfig, VersionProviderEnum
from poem_plugins.config import (
QuotesEnum,
VersionConfig,
VersionPlaceEnum,
VersionProviderEnum,
)
from poem_plugins.general.version import Version
from poem_plugins.general.version.drivers import IVersionDriver
from poem_plugins.general.version.drivers.git import GitVersionDriver
from poem_plugins.handlers import IHandler
from poetry.core.constraints.version import Version as pcVersion


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

if self.config.update_pyproject:
self._write_pyproject(poetry, version)
Expand All @@ -59,8 +65,23 @@ def _write_pyproject(
version: Version,
) -> None:
content: TOMLDocument = poetry.file.read()
poetry_content = content["tool"]["poetry"] # type: ignore
poetry_content["version"] = str(version) # type: ignore

if self.config.update_pyproject_place == VersionPlaceEnum.PROJECT:
if "project" not in content:
content["project"] = {}
if isinstance(content["project"], Container):
content["project"]["version"] = item(str(version))

elif self.config.update_pyproject_place == VersionPlaceEnum.TOOL_POETRY:
if "tool" not in content:
content["tool"] = {}
if "poetry" not in content["tool"]: # type: ignore
content["tool"]["poetry"] = {} # type: ignore
content["tool"]["poetry"]["version"] = str(version) # type: ignore
else:
upp = self.config.update_pyproject_place
raise ValueError(f"Unknown place: {upp}")

poetry.file.write(content)

def _write_module(
Expand Down
Loading
Loading