From 3ab5a475ae66808cd4b019608d5f979d05ba05d6 Mon Sep 17 00:00:00 2001 From: paugier Date: Sun, 27 Oct 2024 16:00:34 +0100 Subject: [PATCH] Add noxfile.py --- noxfile.py | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 noxfile.py diff --git a/noxfile.py b/noxfile.py new file mode 100644 index 0000000..86e8bc4 --- /dev/null +++ b/noxfile.py @@ -0,0 +1,65 @@ +import os +from pathlib import Path +from shutil import rmtree + +import nox + +os.environ.update({"PDM_IGNORE_SAVED_PYTHON": "1"}) +nox.options.reuse_existing_virtualenvs = 1 + + +def _get_version_from_pyproject(path=Path.cwd()): + if isinstance(path, str): + path = Path(path) + + if path.name != "pyproject.toml": + path /= "pyproject.toml" + + in_project = False + version = None + with open(path, encoding="utf-8") as file: + for line in file: + if line.startswith("[project]"): + in_project = True + if line.startswith("version =") and in_project: + version = line.split("=")[1].strip() + version = version[1:-1] + break + + assert version is not None + return version + + +@nox.session(name="add-tag-for-release", venv_backend="none") +def add_tag_for_release(session): + """Add a tag to the repo for a new version""" + session.run("hg", "pull", external=True) + + result = session.run( + *"hg log -r default -G".split(), external=True, silent=True + ) + if result[0] != "@": + session.run("hg", "update", "default", external=True) + + version = _get_version_from_pyproject() + + print(f"{version = }") + + result = session.run("hg", "tags", "-T", "{tag},", external=True, silent=True) + last_tag = result.split(",", 2)[1] + print(f"{last_tag = }") + + if last_tag == version: + session.error("last_tag == version") + + answer = input( + f'Do you really want to add and push the new tag "{version}"? (yes/[no]) ' + ) + + if answer != "yes": + print("Maybe next time then. Bye!") + return + + print("Let's go!") + session.run("hg", "tag", version, external=True) + session.run("hg", "push", external=True)