Skip to content

Commit 629fd0d

Browse files
committed
Fixed compilation on MacOS platforms where Python default target is <10.9.
Modified setup.py to set env MACOSX_DEPLOYMENT_TARGET=10.9 when the build MacOS is that or newer, but the default MACOSX_DEPLOYMENT_TARGET (when absent) is <10.9, which happens when the running Python targets <10.9 min. This happens for example when running a current Anaconda Python, which has target 10.7. This fix taken verbatim from similar in Pandas, pandas-dev/pandas#24274 . Fixed wmayner#39.
1 parent a3910f2 commit 629fd0d

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

setup.py

+16
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,35 @@
33

44
import io
55
import os
6+
import platform
67
import sys
78
from warnings import warn
89

910
from setuptools import Extension, setup
1011
from setuptools.command.build_ext import build_ext as _build_ext
1112
from setuptools.command.sdist import sdist as _sdist
13+
from distutils.sysconfig import get_config_var
14+
from distutils.version import LooseVersion
1215

16+
def is_platform_mac():
17+
return sys.platform == 'darwin'
1318

1419
# Alias ModuleNotFound for Python <= 3.5
1520
if (sys.version_info[0] < 3 or
1621
(sys.version_info[0] == 3 and sys.version_info[1] < 6)):
1722
ModuleNotFoundError = ImportError
1823

24+
# For mac, ensure extensions are built for macos 10.9 when compiling on a
25+
# 10.9 system or above, overriding distuitls behaviour which is to target
26+
# the version that python was built for. This may be overridden by setting
27+
# MACOSX_DEPLOYMENT_TARGET before calling setup.py
28+
if is_platform_mac():
29+
if 'MACOSX_DEPLOYMENT_TARGET' not in os.environ:
30+
current_system = LooseVersion(platform.mac_ver()[0])
31+
python_target = LooseVersion(
32+
get_config_var('MACOSX_DEPLOYMENT_TARGET'))
33+
if python_target < '10.9' and current_system >= '10.9':
34+
os.environ['MACOSX_DEPLOYMENT_TARGET'] = '10.9'
1935

2036
try:
2137
from Cython.Build import cythonize as _cythonize

0 commit comments

Comments
 (0)