Skip to content

MAINT Remove setup.py mentions from documentation and comments #29352

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

Merged
merged 6 commits into from
Jun 28, 2024
Merged
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
6 changes: 1 addition & 5 deletions asv_benchmarks/asv.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@
//
// "install_command": ["python -mpip install {wheel_file}"],
// "uninstall_command": ["return-code=any python -mpip uninstall -y {project}"],
// "build_command": [
// "python setup.py build",
// "PIP_NO_BUILD_ISOLATION=false python -mpip wheel --no-deps --no-index -w {build_cache_dir} {build_dir}"
// ],

// "build_command": ["python -m build --wheel -o {build_cache_dir} {build_dir}"],
// List of branches to benchmark. If not provided, defaults to "master
// (for git) or "default" (for mercurial).
"branches": ["main"],
Expand Down
41 changes: 0 additions & 41 deletions doc/developers/advanced_installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -481,44 +481,3 @@ the base system and these steps will not be necessary.
.. _virtualenv: https://docs.python.org/3/tutorial/venv.html
.. _conda environment: https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html
.. _Miniforge3: https://github.com/conda-forge/miniforge#miniforge3

Alternative compilers
=====================

The following command will build scikit-learn using your default C/C++ compiler.

.. prompt:: bash $

pip install --editable . \
--verbose --no-build-isolation \
--config-settings editable-verbose=true

If you want to build scikit-learn with another compiler handled by ``setuptools``,
use the following command:

.. prompt:: bash $

python setup.py build_ext --compiler=<compiler> -i build_clib --compiler=<compiler>

To see the list of available compilers run:

.. prompt:: bash $

python setup.py build_ext --help-compiler

If your compiler is not listed here, you can specify it through some environment
variables (does not work on windows). This `section
<https://setuptools.pypa.io/en/stable/userguide/ext_modules.html#compiler-and-linker-options>`_
of the setuptools documentation explains in details which environment variables
are used by ``setuptools``, and at which stage of the compilation, to set the
compiler and linker options.

When setting these environment variables, it is advised to first check their
``sysconfig`` counterparts variables and adapt them to your compiler. For instance::

import sysconfig
print(sysconfig.get_config_var('CC'))
print(sysconfig.get_config_var('LDFLAGS'))

In addition, since Scikit-learn uses OpenMP, you need to include the appropriate OpenMP
flag of your compiler into the ``CFLAGS`` and ``CPPFLAGS`` environment variables.
2 changes: 0 additions & 2 deletions doc/developers/cython.rst
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ Tips for performance

* Inline methods and function when it makes sense

* Make sure your Cython compilation units `use NumPy recent C API <https://github.com/scikit-learn/scikit-learn/blob/62a017efa047e9581ae7df8bbaa62cf4c0544ee4/setup.py#L64-L70>`_.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be interested to have more details about what we need/don't need to do about that before deciding to completely remove it and forget about it. ping @jjerphan, you seem familiar with this stuff :)

Copy link
Member

@jjerphan jjerphan Jun 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now taken care of natively by setup.py (note that this might need to be ported to meson):

scikit-learn/setup.py

Lines 121 to 128 in 87fa654

# Always use NumPy 1.7 C API for all compiled extensions.
# See: https://numpy.org/doc/stable/reference/c-api/deprecations.html
DEFINE_MACRO_NUMPY_C_API = (
"NPY_NO_DEPRECATED_API",
"NPY_1_7_API_VERSION",
)
for ext in self.extensions:
ext.define_macros.append(DEFINE_MACRO_NUMPY_C_API)

so this comment can be removed. 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think NPY_NO_DEPRECATED_API must be defined everywhere especially if NumPy 2 is used as old C APIs might be deprecated.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I think this part has not been ported to Meson, which is likely an oversight ... fixing this is probably doable.

Not 100% sure, but my understanding is that using NPY_NO_DEPRECATED_API + NPY_1_7_API_VERSION makes sure that we don't use any Numpy C API that is deprecated in Numpy version 1.7.

@jjerphan but do you have a suggestion about which version we should pick? Is NPY_1_7_API_VERSION OK? Would using NPY_1_9_API_VERSION be better, which is what scipy is doing see https://github.com/scipy/scipy/blob/fffcaa8c58b6909d22063c29e4f9593059a40230/scipy/meson.build#L76-L77?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the meantime I have opened #29357 to do the same thing as what setup.py was doing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also pick NPY_1_9_API_VERSION to be consistent with SciPy's choice. 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#29357 has been merged, so I guess this PR can be merged too?


* In doubt, read the generated C or C++ code if you can: "The fewer C instructions and indirections
for a line of Cython code, the better" is a good rule of thumb.

Expand Down
14 changes: 0 additions & 14 deletions doc/developers/performance.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,6 @@ following:
parallelism** that is amenable to **multi-processing** by using the
``joblib.Parallel`` class.

When using Cython, use either

.. prompt:: bash $

python setup.py build_ext -i
python setup.py install

to generate C files. You are responsible for adding .c/.cpp extensions along
with build parameters in each submodule ``setup.py``.

C/C++ generated files are embedded in distributed stable packages. The goal is
to make it possible to install scikit-learn stable version
on any machine with Python, Numpy, Scipy and C/C++ compiler.

.. _profiling-python-code:

Profiling Python code
Expand Down
4 changes: 2 additions & 2 deletions sklearn/__check_build/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ def raise_build_error(e):
It seems that scikit-learn has not been built correctly.

If you have installed scikit-learn from source, please do not forget
to build the package before using it: run `python setup.py install` or
`make` in the source directory.
to build the package before using it. For detailed instructions, see:
https://scikit-learn.org/dev/developers/advanced_installation.html#building-from-source
%s"""
% (e, local_dir, "".join(dir_content).strip(), msg)
)
Expand Down
2 changes: 1 addition & 1 deletion sklearn/_loss/_loss.pyx.tp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Template file to easily generate loops over samples using Tempita
Generated file: _loss.pyx

Each loss class is generated by a cdef functions on single samples.
The keywords between double braces are substituted in setup.py.
The keywords between double braces are substituted during the build.
"""

doc_HalfSquaredError = (
Expand Down
2 changes: 1 addition & 1 deletion sklearn/ensemble/_gradient_boosting.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ from scipy.sparse import issparse

from ..utils._typedefs cimport float32_t, float64_t, intp_t, int32_t, uint8_t
# Note: _tree uses cimport numpy, cnp.import_array, so we need to include
# numpy headers, see setup.py.
# numpy headers in the build configuration of this extension
from ..tree._tree cimport Node
from ..tree._tree cimport Tree
from ..tree._utils cimport safe_realloc
Expand Down
2 changes: 1 addition & 1 deletion sklearn/linear_model/_sag_fast.pyx.tp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Template file for easily generate fused types consistent code using Tempita
Generated file: sag_fast.pyx

Each class is duplicated for all dtypes (float and double). The keywords
between double braces are substituted in setup.py.
between double braces are substituted during the build.

Authors: Danny Sullivan <dbsullivan23@gmail.com>
Tom Dupre la Tour <tom.dupre-la-tour@m4x.org>
Expand Down
2 changes: 1 addition & 1 deletion sklearn/linear_model/_sgd_fast.pyx.tp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Template file to easily generate fused types consistent code using Tempita
Generated file: _sgd_fast.pyx

Each relevant function is duplicated for the dtypes float and double.
The keywords between double braces are substituted in setup.py.
The keywords between double braces are substituted during the build.

Authors: Peter Prettenhofer <peter.prettenhofer@gmail.com>
Mathieu Blondel (partial_fit support)
Expand Down
2 changes: 1 addition & 1 deletion sklearn/utils/_seq_dataset.pxd.tp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Template file for easily generate fused types consistent code using Tempita
Generated file: _seq_dataset.pxd

Each class is duplicated for all dtypes (float and double). The keywords
between double braces are substituted in setup.py.
between double braces are substituted during the build.
"""

# name_suffix, c_type
Expand Down
2 changes: 1 addition & 1 deletion sklearn/utils/_seq_dataset.pyx.tp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Template file for easily generate fused types consistent code using Tempita
Generated file: _seq_dataset.pyx

Each class is duplicated for all dtypes (float and double). The keywords
between double braces are substituted in setup.py.
between double braces are substituted during the build.

Author: Peter Prettenhofer <peter.prettenhofer@gmail.com>
Arthur Imbert <arthurimbert05@gmail.com>
Expand Down
2 changes: 1 addition & 1 deletion sklearn/utils/_weight_vector.pxd.tp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Template file for easily generate fused types consistent code using Tempita
Generated file: weight_vector.pxd

Each class is duplicated for all dtypes (float and double). The keywords
between double braces are substituted in setup.py.
between double braces are substituted during the build.
"""

# name_suffix, c_type
Expand Down
2 changes: 1 addition & 1 deletion sklearn/utils/_weight_vector.pyx.tp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Template file for easily generate fused types consistent code using Tempita
Generated file: weight_vector.pxd

Each class is duplicated for all dtypes (float and double). The keywords
between double braces are substituted in setup.py.
between double braces are substituted during the build.
"""

# name_suffix, c_type, reset_wscale_threshold
Expand Down