Skip to content

Commit

Permalink
Use 'hatch version' instead of manually updating the version (#36)
Browse files Browse the repository at this point in the history
* Use 'hatch version' instead of manually updating the version.

* Cleanup; commit the file which now contains the version.

* Provide version to antsibull-changelog.
  • Loading branch information
felixfontein authored Feb 8, 2024
1 parent af816b9 commit 7b01818
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 20 deletions.
34 changes: 15 additions & 19 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,6 @@ def create_vectors(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 test_no_modifications(session: nox.Session) -> bool:
modified = session.run(
"git",
Expand Down Expand Up @@ -177,7 +166,9 @@ def bump(session: nox.Session):
f"Either {fragment_file} must already exist, or two positional arguments must be provided."
)
install(session, "antsibull-changelog[toml]", "hatch")
_repl_version(session, version)
current_version = session.run("hatch", "version", silent=True).strip()
if version != current_version:
session.run("hatch", "version", version)
if len(session.posargs) > 1:
fragment = session.run(
"python",
Expand All @@ -187,18 +178,24 @@ def bump(session: nox.Session):
)
with open(fragment_file, "w") as fp:
print(fragment, file=fp)
session.run("git", "add", "pyproject.toml", fragment_file, external=True)
session.run(
"git",
"add",
"src/antsibull_docs_parser/__init__.py",
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
# __init__.py is not committed in the last step
# when the release_summary fragment is created manually
"pyproject.toml",
"src/antsibull_docs_parser/__init__.py",
external=True,
)
install(session, ".") # Smoke test
Expand All @@ -223,7 +220,6 @@ def publish(session: nox.Session):
check_no_modifications(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("git", "add", "pyproject.toml", external=True)
session.run("hatch", "version", "post")
session.run("git", "add", "src/antsibull_docs_parser/__init__.py", external=True)
session.run("git", "commit", "-m", "Post-release version bump.", external=True)
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ build-backend = "hatchling.build"

[project]
name = "antsibull-docs-parser"
version = "1.0.0.post0"
dynamic = ["version"]
description = "Python library for processing Ansible documentation markup"
readme = "README.md"
requires-python = ">=3.6.1"
Expand Down Expand Up @@ -74,6 +74,9 @@ dev = [
"nox",
]

[tool.hatch.version]
path = "src/antsibull_docs_parser/__init__.py"

[tool.isort]
profile = "black"

Expand Down
8 changes: 8 additions & 0 deletions src/antsibull_docs_parser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,11 @@
# https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
# SPDX-FileCopyrightText: 2020, Ansible Project

"""
Library for processing Ansible documentation markup.
"""

__version__ = "1.0.0.post0"

__all__ = ("__version__",)

0 comments on commit 7b01818

Please sign in to comment.