diff --git a/setup.py b/setup.py index d3b2494432f81..c30f5011173c0 100755 --- a/setup.py +++ b/setup.py @@ -55,6 +55,7 @@ NUMPY_MIN_VERSION = '1.11.0' JOBLIB_MIN_VERSION = '0.11' +CYTHON_MIN_VERSION = '0.28.5' # Optional setuptools features # We need to import setuptools early, if we want setuptools features, @@ -234,6 +235,12 @@ def setup_package(): 'scipy>={}'.format(SCIPY_MIN_VERSION), 'joblib>={}'.format(JOBLIB_MIN_VERSION) ], + setup_requires=[ + 'numpy>={}'.format(NUMPY_MIN_VERSION), + 'scipy>={}'.format(SCIPY_MIN_VERSION), + 'joblib>={}'.format(JOBLIB_MIN_VERSION), + 'cython>={}'.format(CYTHON_MIN_VERSION) + ], **extra_setuptools_args) if len(sys.argv) == 1 or ( diff --git a/sklearn/_build_utils/__init__.py b/sklearn/_build_utils/__init__.py index a2e69c6978efe..a2d034d9f377b 100644 --- a/sklearn/_build_utils/__init__.py +++ b/sklearn/_build_utils/__init__.py @@ -42,36 +42,31 @@ def maybe_cythonize_extensions(top_path, config): """Tweaks for building extensions between release and development mode.""" with_openmp = check_openmp_support() - is_release = os.path.exists(os.path.join(top_path, 'PKG-INFO')) + message = ('Please install cython with a version >= {0} in order ' + 'to build a scikit-learn development version.').format( + CYTHON_MIN_VERSION) + try: + import Cython + if LooseVersion(Cython.__version__) < CYTHON_MIN_VERSION: + message += ' Your version of Cython was {0}.'.format( + Cython.__version__) + raise ValueError(message) + from Cython.Build import cythonize + except ImportError as exc: + exc.args += (message,) + raise - if is_release: - build_from_c_and_cpp_files(config.ext_modules) - else: - message = ('Please install cython with a version >= {0} in order ' - 'to build a scikit-learn development version.').format( - CYTHON_MIN_VERSION) - try: - import Cython - if LooseVersion(Cython.__version__) < CYTHON_MIN_VERSION: - message += ' Your version of Cython was {0}.'.format( - Cython.__version__) - raise ValueError(message) - from Cython.Build import cythonize - except ImportError as exc: - exc.args += (message,) - raise + n_jobs = 1 + with contextlib.suppress(ImportError): + import joblib + if LooseVersion(joblib.__version__) > LooseVersion("0.13.0"): + # earlier joblib versions don't account for CPU affinity + # constraints, and may over-estimate the number of available + # CPU particularly in CI (cf loky#114) + n_jobs = joblib.effective_n_jobs() - n_jobs = 1 - with contextlib.suppress(ImportError): - import joblib - if LooseVersion(joblib.__version__) > LooseVersion("0.13.0"): - # earlier joblib versions don't account for CPU affinity - # constraints, and may over-estimate the number of available - # CPU particularly in CI (cf loky#114) - n_jobs = joblib.effective_n_jobs() - - config.ext_modules = cythonize( - config.ext_modules, - nthreads=n_jobs, - compile_time_env={'SKLEARN_OPENMP_SUPPORTED': with_openmp}, - compiler_directives={'language_level': 3}) + config.ext_modules = cythonize( + config.ext_modules, + nthreads=n_jobs, + compile_time_env={'SKLEARN_OPENMP_SUPPORTED': with_openmp}, + compiler_directives={'language_level': 3}) diff --git a/sklearn/setup.py b/sklearn/setup.py index 0c7f19f23d39c..e6dded00d4237 100644 --- a/sklearn/setup.py +++ b/sklearn/setup.py @@ -1,3 +1,4 @@ +import sys import os from sklearn._build_utils import maybe_cythonize_extensions @@ -78,7 +79,8 @@ def configuration(parent_package='', top_path=None): # add the test directory config.add_subpackage('tests') - maybe_cythonize_extensions(top_path, config) + if 'sdist' not in sys.argv: + generate_cythonize_extensions(top_path, config) return config