Skip to content

Commit 7d4cc40

Browse files
committed
refactor: move get_current_version into bump-version script to avoid unneeded tomli install in other scripts
1 parent 4345fa5 commit 7d4cc40

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

scripts/bump-version.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,22 @@
99
"""Script responsible for bumping the version of cookiecutter-robust-python using CalVer."""
1010

1111
import sys
12+
from pathlib import Path
1213
from typing import Annotated
14+
from typing import Any
1315
from typing import Optional
1416

1517
import typer
1618

1719
from util import bump_version
1820
from util import calculate_calver
19-
from util import get_current_version
21+
from util import REPO_FOLDER
22+
23+
24+
try:
25+
import tomllib
26+
except ModuleNotFoundError:
27+
import tomli as tomllib
2028

2129

2230
cli: typer.Typer = typer.Typer()
@@ -45,5 +53,14 @@ def main(
4553
sys.exit(1)
4654

4755

56+
def get_current_version() -> str:
57+
"""Read current version from pyproject.toml."""
58+
59+
pyproject_path: Path = REPO_FOLDER / "pyproject.toml"
60+
with pyproject_path.open("rb") as f:
61+
data: dict[str, Any] = tomllib.load(f)
62+
return data["project"]["version"]
63+
64+
4865
if __name__ == "__main__":
4966
cli()

scripts/util.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
# "cookiecutter",
55
# "cruft",
66
# "python-dotenv",
7-
# "tomli>=2.0.0;python_version<'3.11'",
87
# "typer",
98
# ]
109
# ///
@@ -257,19 +256,6 @@ def get_package_version() -> str:
257256
return result.stdout.strip()
258257

259258

260-
def get_current_version() -> str:
261-
"""Read current version from pyproject.toml."""
262-
try:
263-
import tomllib
264-
except ModuleNotFoundError:
265-
import tomli as tomllib
266-
267-
pyproject_path: Path = REPO_FOLDER / "pyproject.toml"
268-
with pyproject_path.open("rb") as f:
269-
data: dict[str, Any] = tomllib.load(f)
270-
return data["project"]["version"]
271-
272-
273259
def calculate_calver(current_version: str, micro_override: Optional[int] = None) -> str:
274260
"""Calculate the next CalVer version.
275261

0 commit comments

Comments
 (0)