Skip to content

Commit

Permalink
#137: Remove unnecessary version check
Browse files Browse the repository at this point in the history
  • Loading branch information
mtkennerly committed Aug 17, 2023
1 parent 1a02171 commit 3b5f1c7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## Unreleased

* Fixed:
* Running `poetry dynamic-versioning` followed by `poetry build`
would leave the plugin enabled in the sdist's pyproject.toml.

## v0.25.0 (2023-07-11)

* Added:
Expand Down
26 changes: 12 additions & 14 deletions poetry_dynamic_versioning/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,16 +414,15 @@ def _apply_version(
) -> None:
pyproject = tomlkit.parse(pyproject_path.read_text(encoding="utf-8"))

if pyproject["tool"]["poetry"]["version"] != version: # type: ignore
pyproject["tool"]["poetry"]["version"] = version # type: ignore
pyproject["tool"]["poetry"]["version"] = 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.
# We revert this later when we deactivate.
if not retain and not _state.cli_mode:
pyproject["tool"]["poetry-dynamic-versioning"]["enable"] = False # 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.
# We revert this later when we deactivate.
if not retain and not _state.cli_mode:
pyproject["tool"]["poetry-dynamic-versioning"]["enable"] = False # type: ignore

pyproject_path.write_bytes(tomlkit.dumps(pyproject).encode("utf-8"))
pyproject_path.write_bytes(tomlkit.dumps(pyproject).encode("utf-8"))

name = pyproject["tool"]["poetry"]["name"] # type: ignore

Expand Down Expand Up @@ -485,14 +484,13 @@ def _get_and_apply_version(

def _revert_version(retain: bool = False) -> None:
for project, state in _state.projects.items():
if state.original_version != state.version:
pyproject = tomlkit.parse(state.path.read_text(encoding="utf-8"))
pyproject["tool"]["poetry"]["version"] = state.original_version # type: ignore
pyproject = tomlkit.parse(state.path.read_text(encoding="utf-8"))
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
if not retain and not _state.cli_mode:
pyproject["tool"]["poetry-dynamic-versioning"]["enable"] = True # type: ignore

state.path.write_bytes(tomlkit.dumps(pyproject).encode("utf-8"))
state.path.write_bytes(tomlkit.dumps(pyproject).encode("utf-8"))

if state.substitutions:
for file, content in state.substitutions.items():
Expand Down
13 changes: 13 additions & 0 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import shlex
import shutil
import subprocess
import tarfile
from pathlib import Path
from typing import Optional, Sequence, Tuple

import pytest
import tomlkit

ROOT = Path(__file__).parent.parent
DIST = ROOT / "dist"
Expand Down Expand Up @@ -183,6 +185,17 @@ def test_cli_mode_and_substitution_without_enable():
assert "<0.0.0>" not in (DUMMY / "project" / "__init__.py").read_text("utf8")


def test_cli_mode_plus_build_will_disable_plugin():
run("poetry dynamic-versioning", where=DUMMY)
run("poetry build", where=DUMMY)
artifact = next(DUMMY_DIST.glob("*.tar.gz"))
with tarfile.open(artifact, "r:gz") as f:
item = "{}/pyproject.toml".format(artifact.name.replace(".tar.gz", ""))
content = f.extractfile(item).read()
parsed = tomlkit.parse(content)
assert parsed["tool"]["poetry-dynamic-versioning"]["enable"] is False


def test_dependency_versions():
run("poetry install", where=DUMMY)
_, out = run("poetry run pip list --format freeze", where=DUMMY)
Expand Down

0 comments on commit 3b5f1c7

Please sign in to comment.