Skip to contentSkip to conversation

tuna: Fix circular import in setup.py during isolated builds

PATCH New John Kacur 1 participant 1 message Aug 5

lore
Share & tools
lore

John Kacur

author
#0 lore raw

PATCH 1/1 tuna: Fix circular import in setup.py during isolated builds

The setup.py file was importing TUNA_VERSION from tuna.version module, which caused a ModuleNotFoundError during isolated builds with python-build because the tuna package isn't installed yet in the build environment.

This commit replaces the import with a get_version() function that reads tuna/version.py as a text file and parses the version string directly. This approach:
- Works in both traditional setup.py builds (CentOS/RHEL RPM style)
- Works with modern isolated builds using python -m build
- Works when setup.py is removed and only pyproject.toml is used (c10s)
- Maintains backward compatibility with all build systems

The version is still sourced from tuna/version.py as the single source of truth, but without requiring the package to be importable during the build process.

Assisted-by Claude:claude-sonnet-4-5
---
 setup.py | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
setup.py +10 -1
index 8036a647f698..99253600b20e 100755
@@ -6,7 +6,16 @@ from os.path import isfile, relpath
 from setuptools import setup
 
 # Get the tuna version from a single source
-from tuna.version import TUNA_VERSION
+# Read version without importing to avoid circular dependency during build
+def get_version():
+    version_file = os.path.join(os.path.dirname(__file__), 'tuna', 'version.py')
+    with open(version_file, 'r') as f:
+        for line in f:
+            if line.startswith('TUNA_VERSION'):
+                return line.split('=')[1].strip().strip("'\"")
+    raise RuntimeError("Unable to find version string")
+
+TUNA_VERSION = get_version()
 
 if isfile("MANIFEST"):
     os.unlink("MANIFEST")
Signature · 1 line
2.55.0