diff --git a/noxfile.py b/noxfile.py index 043c8d4..77bb04b 100644 --- a/noxfile.py +++ b/noxfile.py @@ -125,17 +125,6 @@ def typing(session: nox.Session): ) -def _repl_version(session: nox.Session, new_version: str): - with open("pyproject.toml", "r+") as fp: - lines = tuple(fp) - fp.seek(0) - for line in lines: - if line.startswith("version = "): - line = f'version = "{new_version}"\n' - fp.write(line) - fp.truncate() - - def check_no_modifications(session: nox.Session) -> None: modified = session.run( "git", @@ -192,7 +181,7 @@ def bump(session: nox.Session): "or two positional arguments must be provided." ) install(session, "antsibull-changelog[toml]", "hatch") - _repl_version(session, version) + session.run("hatch", "version", version) if len(session.posargs) > 1: fragment = session.run( "python", @@ -203,18 +192,24 @@ def bump(session: nox.Session): ) with open(fragment_file, "w") as fp: print(fragment, file=fp) - session.run("git", "add", "pyproject.toml", str(fragment_file), external=True) + session.run( + "git", + "add", + "src/antsibull_core/__init__.py", + str(fragment_file), + external=True, + ) session.run("git", "commit", "-m", f"Prepare {version}.", external=True) - session.run("antsibull-changelog", "release") + session.run("antsibull-changelog", "release", "--version", version) session.run( "git", "add", "CHANGELOG.rst", "changelogs/changelog.yaml", "changelogs/fragments/", - # pyproject.toml is not committed in the last step + # src/antsibull_core/__init__.py is not committed in the last step # when the release_summary fragment is created manually - "pyproject.toml", + "src/antsibull_core/__init__.py", external=True, ) install(session, ".") # Smoke test @@ -240,6 +235,6 @@ def publish(session: nox.Session): install(session, "hatch") session.run("hatch", "publish", *session.posargs) version = session.run("hatch", "version", silent=True).strip() - _repl_version(session, f"{version}.post0") + session.run("hatch", "version", "post") session.run("git", "add", "pyproject.toml", external=True) session.run("git", "commit", "-m", "Post-release version bump.", external=True) diff --git a/pyproject.toml b/pyproject.toml index 7874359..415a676 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,7 +8,9 @@ build-backend = "hatchling.build" [project] name = "antsibull-core" -version = "2.1.0.post0" +dynamic = [ + "version", +] description = "Tools for building the Ansible Distribution" license = "GPL-3.0-or-later AND BSD-2-Clause AND MIT AND PSF-2.0" license-files = {globs=["LICENSES/*.txt"]} @@ -107,6 +109,9 @@ dev = [ ] +[tool.hatch.version] +path = "src/antsibull_core/__init__.py" + [tool.isort] profile = "black" diff --git a/src/antsibull_core/__init__.py b/src/antsibull_core/__init__.py index 7547f6e..adf9522 100644 --- a/src/antsibull_core/__init__.py +++ b/src/antsibull_core/__init__.py @@ -2,3 +2,13 @@ # https://www.gnu.org/licenses/gpl-3.0.txt) # SPDX-License-Identifier: GPL-3.0-or-later # SPDX-FileCopyrightText: 2020, Ansible Project + +""" +Shared code used by tools for building the Ansible distribution +""" + +from __future__ import annotations + +__version__ = "2.1.0.post0" + +__all__ = ("__version__",)