Skip to content

Commit

Permalink
Depend on cmake only if there is no system package
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mgorny committed Jan 16, 2025
1 parent 2c7187e commit 1aa5c6a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[build-system]
requires = ["setuptools>=61", "wheel", "cmake"]
requires = ["setuptools>=61", "wheel"]
build-backend = "setuptools.build_meta"
6 changes: 6 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import re
import shutil
import subprocess
import sys
import warnings
Expand Down Expand Up @@ -161,6 +162,10 @@ def initialize_options(self):
version_info = get_version_info()
author_info = get_author_info()

setup_requires = []
if not shutil.which('cmake'):
setup_requires.append('cmake')

setuptools.setup(
name='OpenCC',
version=version_info,
Expand All @@ -178,6 +183,7 @@ def initialize_options(self):
'build_ext': BuildExtCommand,
'bdist_wheel': BDistWheelCommand
},
setup_requires=setup_requires,

classifiers=[
'Development Status :: 5 - Production/Stable',
Expand Down

0 comments on commit 1aa5c6a

Please sign in to comment.