Skip to content

Commit 549bab5

Browse files
In setup.py, don't limit CMake version test to only Windows (#995)
The `CMakeBuild` class' `run()` method tests the version of CMake; however, it did the test only when on Windows. It seems like this is a test worth doing everywhere, so I removed test for Windows. In addition, while at it, I slightly updated the way the process output is captured, and expanded the range of exceptions tested in order to provide more specific feedback to users. --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent 9b8cea6 commit 549bab5

1 file changed

Lines changed: 21 additions & 10 deletions

File tree

setup.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,32 @@ def __init__(self, name, sourcedir=""):
3434
class CMakeBuild(build_ext):
3535
def run(self):
3636
try:
37-
out = subprocess.check_output(["cmake", "--version"])
38-
except OSError:
37+
out = subprocess.check_output(["cmake", "--version"], text=True, timeout=15)
38+
39+
from packaging.version import parse
40+
41+
cmake_version = parse(re.search(r"version\s*([\d.]+)", out).group(1))
42+
if cmake_version < parse("3.28.0"):
43+
raise RuntimeError(
44+
f"CMake reports its version is {cmake_version}, but qsim needs "
45+
"version >= 3.28.0."
46+
)
47+
except FileNotFoundError:
3948
raise RuntimeError(
4049
"CMake must be installed to build the following extensions: "
4150
+ ", ".join(e.name for e in self.extensions)
4251
)
43-
44-
if platform.system() == "Windows":
45-
from packaging.version import parse
46-
47-
cmake_version = parse(
48-
re.search(r"version\s*([\d.]+)", out.decode()).group(1)
52+
except subprocess.CalledProcessError as e:
53+
raise RuntimeError(
54+
f"Command '{e.cmd}' returned status {e.returncode}. "
55+
f"Output: {e.output}"
56+
)
57+
except subprocess.TimeoutExpired as e:
58+
raise RuntimeError(f"Command timed out: {e}")
59+
except OSError as e:
60+
raise RuntimeError(
61+
f"An OS error occurred when trying to run 'cmake --version': {e}"
4962
)
50-
if cmake_version < parse("3.28.0"):
51-
raise RuntimeError("CMake >= 3.28.0 is required on Windows")
5263

5364
for ext in self.extensions:
5465
self.build_extension(ext)

0 commit comments

Comments
 (0)