From 722d99863bfc2636f8fd5bdead8c014a84bf10aa Mon Sep 17 00:00:00 2001 From: kdmukai <934746+kdmukai@users.noreply.github.com> Date: Sat, 20 Dec 2025 09:23:38 -0600 Subject: [PATCH] dir handling improvements --- src/seedsigner/helpers/version.py | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/seedsigner/helpers/version.py b/src/seedsigner/helpers/version.py index b5f70683..f56f45ea 100644 --- a/src/seedsigner/helpers/version.py +++ b/src/seedsigner/helpers/version.py @@ -67,25 +67,29 @@ class Version: # Filename is the tag name return tag_filename return None - + + + @classmethod + def _get_version_file_path(cls) -> str: + # Have to back out of "helpers" dir to the main "seedsigner" dir + return os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", cls.VERSION_FILENAME) + @classmethod def _get_version_file(cls) -> dict | None: """ Attempts to read the VERSION_FILENAME and return its contents as a dict. """ - version_file_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", cls.VERSION_FILENAME) - if os.path.exists(version_file_path): - try: - with open(version_file_path, "r") as f: - return json.load(f) - except Exception as e: - # In local dev we don't expect/want this file to exist - pass + version_file_path = cls._get_version_file_path() + try: + with open(version_file_path, "r") as f: + return json.load(f) + except Exception as e: + # In local dev we don't expect/want this file to exist + pass return None - @classmethod def get_version(cls) -> str: """ @@ -162,15 +166,15 @@ class Version: if __name__ == "__main__": """ - CLI to extract the current version and last edit time and write to `src/version.json`. + CLI to extract the current version and last edit time and write to `src/seedsigner/version.json`. """ version_info = dict(version=Version.get_version()) last_edit_dt = Version.get_last_src_edit() if last_edit_dt: version_info["last_src_edit"] = last_edit_dt.isoformat() - with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", Version.VERSION_FILENAME), "w") as f: + with open(Version._get_version_file_path(), "w") as f: json.dump(version_info, f, indent=4) - print("Wrote version info to src/version.json:") + print("Wrote version info to src/seedsigner/version.json:") print(json.dumps(version_info, indent=4)) \ No newline at end of file