Skip to content

Commit 2a1e968

Browse files
rthjnothman
authored andcommitted
MAINT Add python_requires>=3.5 to setup.py (scikit-learn#13861)
* Add python_requires to setup.py * FIX make it possible to run egg_info from Python 2 without numpy * Informative error message for python2.7 setup.py install (without breaking python2.7 setup.py egg_info)
1 parent f325c8f commit 2a1e968

File tree

1 file changed

+35
-25
lines changed

1 file changed

+35
-25
lines changed

setup.py

+35-25
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,18 @@
1313
import traceback
1414
try:
1515
import builtins
16-
# This is a bit (!) hackish: we are setting a global variable so that the
17-
# main sklearn __init__ can detect if it is being loaded by the setup
18-
# routine, to avoid attempting to load components that aren't built yet:
19-
# the numpy distutils extensions that are used by scikit-learn to
20-
# recursively build the compiled extensions in sub-packages is based on the
21-
# Python import machinery.
22-
builtins.__SKLEARN_SETUP__ = True
2316
except ImportError:
24-
# Python 2 is not support but we will raise an explicit error message next.
25-
pass
17+
# Python 2 compat: just to be able to declare that Python >=3.5 is needed.
18+
import __builtin__ as builtins
19+
20+
# This is a bit (!) hackish: we are setting a global variable so that the
21+
# main sklearn __init__ can detect if it is being loaded by the setup
22+
# routine, to avoid attempting to load components that aren't built yet:
23+
# the numpy distutils extensions that are used by scikit-learn to
24+
# recursively build the compiled extensions in sub-packages is based on the
25+
# Python import machinery.
26+
builtins.__SKLEARN_SETUP__ = True
2627

27-
if sys.version_info < (3, 5):
28-
raise RuntimeError("Scikit-learn requires Python 3.5 or later. The current"
29-
" Python version is %s installed in %s."
30-
% (platform.python_version(), sys.executable))
3128

3229
DISTNAME = 'scikit-learn'
3330
DESCRIPTION = 'A set of python modules for machine learning and data mining'
@@ -116,27 +113,33 @@ def run(self):
116113
shutil.rmtree(os.path.join(dirpath, dirname))
117114

118115

116+
cmdclass = {'clean': CleanCommand}
117+
119118
# custom build_ext command to set OpenMP compile flags depending on os and
120119
# compiler
121120
# build_ext has to be imported after setuptools
122-
from numpy.distutils.command.build_ext import build_ext # noqa
123-
121+
try:
122+
from numpy.distutils.command.build_ext import build_ext # noqa
124123

125-
class build_ext_subclass(build_ext):
126-
def build_extensions(self):
127-
from sklearn._build_utils.openmp_helpers import get_openmp_flag
124+
class build_ext_subclass(build_ext):
125+
def build_extensions(self):
126+
from sklearn._build_utils.openmp_helpers import get_openmp_flag
128127

129-
if not os.getenv('SKLEARN_NO_OPENMP'):
130-
openmp_flag = get_openmp_flag(self.compiler)
128+
if not os.getenv('SKLEARN_NO_OPENMP'):
129+
openmp_flag = get_openmp_flag(self.compiler)
131130

132-
for e in self.extensions:
133-
e.extra_compile_args += openmp_flag
134-
e.extra_link_args += openmp_flag
131+
for e in self.extensions:
132+
e.extra_compile_args += openmp_flag
133+
e.extra_link_args += openmp_flag
135134

136-
build_ext.build_extensions(self)
135+
build_ext.build_extensions(self)
137136

137+
cmdclass['build_ext'] = build_ext_subclass
138138

139-
cmdclass = {'clean': CleanCommand, 'build_ext': build_ext_subclass}
139+
except ImportError:
140+
# Numpy should not be a dependency just to be able to introspect
141+
# that python 3.5 is required.
142+
pass
140143

141144

142145
# Optional wheelhouse-uploader features
@@ -225,6 +228,7 @@ def setup_package():
225228
'Implementation :: PyPy')
226229
],
227230
cmdclass=cmdclass,
231+
python_requires=">=3.5",
228232
install_requires=[
229233
'numpy>={}'.format(NUMPY_MIN_VERSION),
230234
'scipy>={}'.format(SCIPY_MIN_VERSION),
@@ -250,6 +254,12 @@ def setup_package():
250254

251255
metadata['version'] = VERSION
252256
else:
257+
if sys.version_info < (3, 5):
258+
raise RuntimeError(
259+
"Scikit-learn requires Python 3.5 or later. The current"
260+
" Python version is %s installed in %s."
261+
% (platform.python_version(), sys.executable))
262+
253263
numpy_status = get_numpy_status()
254264
numpy_req_str = "scikit-learn requires NumPy >= {}.\n".format(
255265
NUMPY_MIN_VERSION)

0 commit comments

Comments
 (0)