Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
mtkennerly committed Jan 5, 2025
1 parent 56ed2ea commit 6c40686
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ __pycache__/
.env/
.idea/
.mypy_cache/
.poetry/
.pytest_cache/
.ruff_cache/
.tox/
Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
## Unreleased

* Added:
* CLI: When pyproject.toml contains the `project` section,
the `enable` command will add the required fields for Poetry 2.0.0+.
* Fixed:
* For compatibility with Poetry 2.0.0,
adjusted Poetry constraint from `^1.2.0` to `>=1.2.0`.
* For compatibility with Poetry 2.0.0,
when inserting the dynamic version into pyproject.toml with PEP 621 mode activated,
the plugin ensures not to set `project.version` and `tool.poetry.version` at the same time.
* An `UnboundLocalError` could happen when pyproject.toml was misconfigured.

## v1.4.1 (2024-09-10)

* Fixed:
Expand Down
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,28 @@ be sure to uninstall it before proceeding.

* Install the plugin using one of the options below:

* In most cases: `poetry self add "poetry-dynamic-versioning[plugin]"`
* If you installed Poetry with Pipx: `pipx inject poetry "poetry-dynamic-versioning[plugin]"`
* For Poetry 2.0.0+, add this to your pyproject.toml and then run `poetry install`:
```toml
[tool.poetry.requires-plugins]
poetry-dynamic-versioning = { version = ">=1.0.0,<2.0.0", extras = ["plugin"] }
```
* For older Poetry versions, depending on how you installed Poetry:
* In most cases: `poetry self add "poetry-dynamic-versioning[plugin]"`
* If you installed Poetry with Pipx: `pipx inject poetry "poetry-dynamic-versioning[plugin]"`

See the [Poetry plugin documentation](https://python-poetry.org/docs/plugins/#using-plugins)
for more information about these options.
* Run in your project: `poetry dynamic-versioning enable`
* Run this in your project: `poetry dynamic-versioning enable`

Or you can update your pyproject.toml manually:
Or you can update your pyproject.toml manually to include these fields:

```toml
[project]
dynamic = ["version"]

[tool.poetry]
version = "0.0.0"

[tool.poetry-dynamic-versioning]
enable = true
```
Expand Down
10 changes: 8 additions & 2 deletions poetry_dynamic_versioning/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,7 @@ def _apply_version(
elif mode == _Mode.Pep621:
pyproject["project"]["dynamic"].remove("version") # type: ignore
pyproject["project"]["version"] = version # type: ignore
pyproject["tool"]["poetry"].pop("version") # type: ignore

# Disable the plugin in case we're building a source distribution,
# which won't have access to the VCS info at install time.
Expand Down Expand Up @@ -654,6 +655,9 @@ def _get_and_apply_version(
and "dynamic" in pyproject["project"]
and "version" in pyproject["project"]["dynamic"]
and "version" not in pyproject["project"]
and "tool" in pyproject
and "poetry" in pyproject["tool"]
and "version" in pyproject["tool"]["poetry"]
)

if classic:
Expand All @@ -662,10 +666,10 @@ def _get_and_apply_version(
dynamic_index = None
elif pep621:
name = pyproject["project"]["name"]
original = pyproject["project"].get("version")
original = pyproject["tool"]["poetry"]["version"]
dynamic_index = pyproject["project"]["dynamic"].index("version")
else:
return name if name in _state.projects else None
return None

if name in _state.projects:
return name
Expand Down Expand Up @@ -726,6 +730,8 @@ def _revert_version(retain: bool = False) -> None:
pyproject["project"]["dynamic"].insert(index, "version") # type: ignore
if "version" in pyproject["project"]: # type: ignore
pyproject["project"].pop("version") # type: ignore
if state.original_version is not None:
pyproject["tool"]["poetry"]["version"] = state.original_version # type: ignore

if not retain and not _state.cli_mode:
pyproject["tool"]["poetry-dynamic-versioning"]["enable"] = True # type: ignore
Expand Down
19 changes: 19 additions & 0 deletions poetry_dynamic_versioning/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ class Key:
build_system = "build-system"
requires = "requires"
build_backend = "build-backend"
project = "project"
poetry = "poetry"
dynamic = "dynamic"
version = "version"


class Command:
Expand Down Expand Up @@ -120,4 +124,19 @@ def _enable_in_doc(doc: tomlkit.TOMLDocument) -> tomlkit.TOMLDocument:
else:
doc[Key.build_system].update(build_system_table) # type: ignore

# Poetry 2.0.0+
if doc.get(Key.project) is not None:
if doc[Key.project].get(Key.version) is not None:
del doc[Key.project][Key.version]

if doc[Key.project].get(Key.dynamic) is None:
doc[Key.project][Key.dynamic] = [Key.version]
else:
doc[Key.project][Key.dynamic].append(Key.version)

if doc[Key.tool].get(Key.poetry) is None:
doc[Key.tool][Key.poetry] = tomlkit.table().add(Key.version, "0.0.0")
else:
doc[Key.tool][Key.poetry][Key.version] = "0.0.0"

return doc

0 comments on commit 6c40686

Please sign in to comment.