Skip to content

Commit 8075f68

Browse files
SvenSerneelsclaude
andcommitted
fix setup.py to read version without importing module
Avoids import errors during pip install -e . when dependencies are not yet installed. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 8a9b724 commit 8075f68

1 file changed

Lines changed: 33 additions & 5 deletions

File tree

setup.py

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,41 @@
88

99
from setuptools import setup, find_packages
1010
import re
11-
import sys
1211
import os
1312

14-
SRC_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)),"./src")
15-
if SRC_DIR not in sys.path:
16-
sys.path.insert(0,SRC_DIR)
17-
from direpack import __version__, __author__, __license__
13+
14+
def get_version():
15+
"""Read version from __init__.py without importing the module."""
16+
init_file = os.path.join(
17+
os.path.dirname(os.path.abspath(__file__)),
18+
"src", "direpack", "__init__.py"
19+
)
20+
with open(init_file, "r") as f:
21+
content = f.read()
22+
version_match = re.search(r'^__version__\s*=\s*["\']([^"\']+)["\']', content, re.MULTILINE)
23+
if version_match:
24+
return version_match.group(1)
25+
raise RuntimeError("Unable to find version string.")
26+
27+
28+
def get_metadata():
29+
"""Read author and license from __init__.py without importing."""
30+
init_file = os.path.join(
31+
os.path.dirname(os.path.abspath(__file__)),
32+
"src", "direpack", "__init__.py"
33+
)
34+
with open(init_file, "r") as f:
35+
content = f.read()
36+
author_match = re.search(r'^__author__\s*=\s*["\']([^"\']+)["\']', content, re.MULTILINE)
37+
license_match = re.search(r'^__license__\s*=\s*["\']([^"\']+)["\']', content, re.MULTILINE)
38+
return (
39+
author_match.group(1) if author_match else "Unknown",
40+
license_match.group(1) if license_match else "MIT"
41+
)
42+
43+
44+
__version__ = get_version()
45+
__author__, __license__ = get_metadata()
1846

1947
readme_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'README.md')
2048
try:

0 commit comments

Comments
 (0)