From 2479cbd41b42f25832d6385dbd181916e3582f5a Mon Sep 17 00:00:00 2001 From: aclist <92275929+aclist@users.noreply.github.com> Date: Mon, 9 Nov 2026 11:03:50 +0900 Subject: [PATCH] change: parse repository root --- scripts/concat_licenses.py | 4 +++- scripts/copy_changelog.py | 9 +++++---- scripts/parse_toml.py | 5 ++--- scripts/prebuild.py | 4 +++- scripts/release.py | 3 ++- scripts/scrot.py | 10 +--------- scripts/shared/__init__.py | 11 +++++++++++ 7 files changed, 27 insertions(+), 19 deletions(-) create mode 100644 scripts/shared/__init__.py diff --git a/scripts/concat_licenses.py b/scripts/concat_licenses.py index 56f80a6..5008b5e 100644 --- a/scripts/concat_licenses.py +++ b/scripts/concat_licenses.py @@ -1,5 +1,7 @@ from pathlib import Path +from shared import get_git_root + BOILERPLATE = """ This file includes the combined licenses to the following components: @@ -40,7 +42,7 @@ class CombinedLicense: def concat_license() -> str: combined = CombinedLicense() - root = Path(__file__).resolve().parents[1] + root = get_git_root() licenses = root.joinpath("docs/licenses") main_license = root.joinpath(LICENSE_FILE) diff --git a/scripts/copy_changelog.py b/scripts/copy_changelog.py index c32a4cb..e900469 100644 --- a/scripts/copy_changelog.py +++ b/scripts/copy_changelog.py @@ -1,10 +1,11 @@ import shutil import subprocess -from pathlib import Path -par = Path(__file__).parent.parent -clog = par / "CHANGELOG.md" -target = par / "dzgui/data/CHANGELOG.md" +from shared import get_git_root + +root = get_git_root() +clog = root.joinpath("CHANGELOG.md") +target = root.joinpath("dzgui/data/CHANGELOG.md") shutil.copy(clog, target) diff --git a/scripts/parse_toml.py b/scripts/parse_toml.py index dc0afe0..e4b5210 100644 --- a/scripts/parse_toml.py +++ b/scripts/parse_toml.py @@ -1,10 +1,9 @@ import tomllib -from pathlib import Path - -root = Path(__file__).resolve().parents[1] +from shared import get_git_root def get_entrypoint() -> None: + root = get_git_root() p = root.joinpath("pyproject.toml") with open(p, "rb") as f: t = tomllib.load(f) diff --git a/scripts/prebuild.py b/scripts/prebuild.py index 8700b62..162f500 100644 --- a/scripts/prebuild.py +++ b/scripts/prebuild.py @@ -6,11 +6,13 @@ import tarfile from pathlib import Path from urllib.parse import unquote +from shared import get_git_root + BUILD = "3.13.9" DATE = "20251014" CPYTHON_BUILD = f"cpython-{BUILD}" -root = Path(__file__).resolve().parents[1] +root = get_git_root() build_dir = root.joinpath("build") cpython_dir = build_dir.joinpath(CPYTHON_BUILD) diff --git a/scripts/release.py b/scripts/release.py index 2eb8f02..2afaf47 100644 --- a/scripts/release.py +++ b/scripts/release.py @@ -9,6 +9,7 @@ from pathlib import Path from concat_licenses import concat_license from parse_toml import get_entrypoint from prebuild import get_pyapp, rebuild_cpython +from shared import get_git_root def update_uname(info: tarfile.TarInfo) -> tarfile.TarInfo: @@ -17,7 +18,7 @@ def update_uname(info: tarfile.TarInfo) -> tarfile.TarInfo: return info -root = Path(__file__).resolve().parents[1] +root = get_git_root() dist_dir = root.joinpath("dist") build_dir = root.joinpath("build") diff --git a/scripts/scrot.py b/scripts/scrot.py index 9dbf04e..2209b9a 100644 --- a/scripts/scrot.py +++ b/scripts/scrot.py @@ -2,15 +2,7 @@ import subprocess from pathlib import Path from dzgui.app_init import build_gui - - -def get_git_root() -> Path: - proc = subprocess.run( - ["git", "rev-parse", "--show-toplevel"], capture_output=True, text=True - ) - if proc.returncode != 0: - raise OSError("Failed to parse git root") - return Path(proc.stdout.rstrip()) +from shared import get_git_root def get_image_path() -> Path: diff --git a/scripts/shared/__init__.py b/scripts/shared/__init__.py new file mode 100644 index 0000000..f638b7b --- /dev/null +++ b/scripts/shared/__init__.py @@ -0,0 +1,11 @@ +import subprocess +from pathlib import Path + + +def get_git_root() -> Path: + proc = subprocess.run( + ["git", "rev-parse", "--show-toplevel"], capture_output=True, text=True + ) + if proc.returncode != 0: + raise OSError("Failed to parse git root") + return Path(proc.stdout.rstrip())