Skip to content

BLD do not cythonize sdist #15335

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 (
Expand Down
57 changes: 26 additions & 31 deletions sklearn/_build_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})
4 changes: 3 additions & 1 deletion sklearn/setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
import os

from sklearn._build_utils import maybe_cythonize_extensions
Expand Down Expand Up @@ -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

Expand Down