Skip to content

Commit 1aa5c6a

Browse files
committed
Depend on cmake only if there is no system package
Rather than requiring using `cmake` from PyPI unconditionally, check if `cmake` is available on the system, and add the dependency only if it is not. This is the same approach as used e.g. by `scikit-build-core` build system. Besides avoiding unnecessarily installing (or building) a second copy of CMake, it improves portability, as system CMake is often patched downstream whereas the CMake version found on PyPI is not.
1 parent 2c7187e commit 1aa5c6a

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[build-system]
2-
requires = ["setuptools>=61", "wheel", "cmake"]
2+
requires = ["setuptools>=61", "wheel"]
33
build-backend = "setuptools.build_meta"

setup.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import re
3+
import shutil
34
import subprocess
45
import sys
56
import warnings
@@ -161,6 +162,10 @@ def initialize_options(self):
161162
version_info = get_version_info()
162163
author_info = get_author_info()
163164

165+
setup_requires = []
166+
if not shutil.which('cmake'):
167+
setup_requires.append('cmake')
168+
164169
setuptools.setup(
165170
name='OpenCC',
166171
version=version_info,
@@ -178,6 +183,7 @@ def initialize_options(self):
178183
'build_ext': BuildExtCommand,
179184
'bdist_wheel': BDistWheelCommand
180185
},
186+
setup_requires=setup_requires,
181187

182188
classifiers=[
183189
'Development Status :: 5 - Production/Stable',

0 commit comments

Comments
 (0)