From de225faf262b521be360b4dedc700a30978922fb Mon Sep 17 00:00:00 2001 From: Mike Casale <46603283+mikewcasale@users.noreply.github.com> Date: Sat, 14 Dec 2024 13:19:40 -0800 Subject: [PATCH] fix: update version detection to work in build environment --- setup.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/setup.py b/setup.py index 66fde3d..a2f270e 100644 --- a/setup.py +++ b/setup.py @@ -3,13 +3,23 @@ import re def get_version(): - init_path = os.path.join("repominify", "__init__.py") - with open(init_path, "r") as f: - content = f.read() - version_match = re.search(r'^__version__ = ["\']([^"\']*)["\']', content, re.M) - if version_match: - return version_match.group(1) - raise RuntimeError("Cannot find version string.") + # Try both the source directory and the package directory + possible_paths = [ + os.path.join("repominify", "__init__.py"), + os.path.join("repominify", "repominify", "__init__.py"), + ] + + for init_path in possible_paths: + try: + with open(init_path, "r") as f: + content = f.read() + version_match = re.search(r'^__version__ = ["\']([^"\']*)["\']', content, re.M) + if version_match: + return version_match.group(1) + except FileNotFoundError: + continue + + raise RuntimeError("Cannot find version string in __init__.py") setup( name="repominify",