From d789a17898a1ed071beab1fdb4b4282cdd62c7f2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 26 Jun 2025 23:42:02 +0000 Subject: [PATCH] Fix ModuleNotFoundError by removing dynamic version loading from pyproject.toml Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com> --- src/api/python/pyproject.toml | 5 ++--- src/api/python/setup.py | 38 +++++++++++++++------------------ src/api/python/z3_version.py | 40 ----------------------------------- 3 files changed, 19 insertions(+), 64 deletions(-) delete mode 100644 src/api/python/z3_version.py diff --git a/src/api/python/pyproject.toml b/src/api/python/pyproject.toml index 1e23ff82b..09f6337e9 100644 --- a/src/api/python/pyproject.toml +++ b/src/api/python/pyproject.toml @@ -4,6 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "z3-solver" +version = "4.15.3.0" description = "an efficient SMT solver library" readme = "README.txt" requires-python = ">=3.8" @@ -33,7 +34,6 @@ classifiers = [ dependencies = [ "importlib-resources; python_version < '3.9'" ] -dynamic = ["version"] [project.urls] Homepage = "https://github.com/Z3Prover/z3" @@ -51,5 +51,4 @@ z3 = ["lib/*", "include/*.h", "include/c++/*.h"] [tool.setuptools.data-files] bin = ["bin/*"] -[tool.setuptools.dynamic] -version = {attr = "z3_version.__version__"} + diff --git a/src/api/python/setup.py b/src/api/python/setup.py index a8f5419ce..c6fdf7205 100644 --- a/src/api/python/setup.py +++ b/src/api/python/setup.py @@ -116,27 +116,22 @@ def _clean_native_build(): rmtree(BUILD_DIR) def _z3_version(): - # Import version from z3_version module for consistency - try: - from z3_version import get_version - return get_version() - except ImportError: - # Fallback to original implementation - post = os.getenv('Z3_VERSION_SUFFIX', '') - if RELEASE_DIR is None: - fn = os.path.join(SRC_DIR, 'scripts', 'mk_project.py') - if os.path.exists(fn): - with open(fn) as f: - for line in f: - n = re.match(r".*set_version\((.*), (.*), (.*), (.*)\).*", line) - if not n is None: - return n.group(1) + '.' + n.group(2) + '.' + n.group(3) + '.' + n.group(4) + post - return "?.?.?.?" - else: - version = RELEASE_METADATA[0] - if version.count('.') == 2: - version += '.0' - return version + post + # Get version from project metadata + post = os.getenv('Z3_VERSION_SUFFIX', '') + if RELEASE_DIR is None: + fn = os.path.join(SRC_DIR, 'scripts', 'mk_project.py') + if os.path.exists(fn): + with open(fn) as f: + for line in f: + n = re.match(r".*set_version\((.*), (.*), (.*), (.*)\).*", line) + if not n is None: + return n.group(1) + '.' + n.group(2) + '.' + n.group(3) + '.' + n.group(4) + post + return "?.?.?.?" + else: + version = RELEASE_METADATA[0] + if version.count('.') == 2: + version += '.0' + return version + post def _configure_z3(): global IS_SINGLE_THREADED @@ -335,6 +330,7 @@ class bdist_wheel(_bdist_wheel): setup( # Most configuration is now in pyproject.toml # Keep only setup.py-specific configuration + version=_z3_version(), setup_requires = SETUP_REQUIRES, include_package_data=True, package_data={ diff --git a/src/api/python/z3_version.py b/src/api/python/z3_version.py deleted file mode 100644 index debb328e4..000000000 --- a/src/api/python/z3_version.py +++ /dev/null @@ -1,40 +0,0 @@ -""" -Version detection for z3-solver package. -""" -import os -import re - -def get_version(): - """Get the z3 version from the source tree.""" - post = os.getenv('Z3_VERSION_SUFFIX', '') - - # Determine where the source directory is located - ROOT_DIR = os.path.abspath(os.path.dirname(__file__)) - SRC_DIR_LOCAL = os.path.join(ROOT_DIR, 'core') - SRC_DIR_REPO = os.path.join(ROOT_DIR, '..', '..', '..') - SRC_DIR = SRC_DIR_LOCAL if os.path.exists(SRC_DIR_LOCAL) else SRC_DIR_REPO - - # Check if we're using a release directory - RELEASE_DIR = os.environ.get('PACKAGE_FROM_RELEASE', None) - - if RELEASE_DIR is None: - fn = os.path.join(SRC_DIR, 'scripts', 'mk_project.py') - if os.path.exists(fn): - with open(fn) as f: - for line in f: - n = re.match(r".*set_version\((.*), (.*), (.*), (.*)\).*", line) - if not n is None: - return n.group(1) + '.' + n.group(2) + '.' + n.group(3) + '.' + n.group(4) + post - return "4.15.3.0" + post # fallback version - else: - RELEASE_METADATA = os.path.basename(RELEASE_DIR).split('-') - if RELEASE_METADATA[0] == 'z3' and len(RELEASE_METADATA) >= 4: - RELEASE_METADATA.pop(0) - version = RELEASE_METADATA[0] - if version.count('.') == 2: - version += '.0' - return version + post - return "4.15.3.0" + post # fallback version - -# Make version available at module level -__version__ = get_version() \ No newline at end of file