Skip to content

Commit 97d49f2

Browse files
authored
BLD Specify build time dependencies via pyproject.toml (scikit-learn#16244)
* add pyproject.toml * do it in CI * cln * no build isolation in the doc * bump dependencies * no-build-isolation everywhere needed
1 parent c79a5b4 commit 97d49f2

File tree

6 files changed

+45
-20
lines changed

6 files changed

+45
-20
lines changed

MANIFEST.in

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ recursive-include sklearn *.c *.h *.pyx *.pxd *.pxi *.tp
55
recursive-include sklearn/datasets *.csv *.csv.gz *.rst *.jpg *.txt *.arff.gz *.json.gz
66
include COPYING
77
include README.rst
8+
include pyproject.toml

build_tools/azure/install.sh

+12-5
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ elif [[ "$DISTRIB" == "conda-pip-latest" ]]; then
9090
# conda is still used as a convenient way to install Python and pip.
9191
make_conda "python=$PYTHON_VERSION"
9292
python -m pip install -U pip
93-
python -m pip install numpy scipy cython joblib
9493
python -m pip install pytest==$PYTEST_VERSION pytest-cov pytest-xdist
9594
python -m pip install pandas matplotlib pyamg
9695
# do not install dependencies for lightgbm since it requires scikit-learn
@@ -121,7 +120,15 @@ except ImportError:
121120
"
122121
python -m pip list
123122

124-
# Use setup.py instead of `pip install -e .` to be able to pass the -j flag
125-
# to speed-up the building multicore CI machines.
126-
python setup.py build_ext --inplace -j 3
127-
python setup.py develop
123+
if [[ "$DISTRIB" == "conda-pip-latest" ]]; then
124+
# Check that pip can automatically install the build dependencies from
125+
# pyproject.toml using an isolated build environment:
126+
pip install --verbose --editable .
127+
else
128+
# Use the pre-installed build dependencies and build directly in the
129+
# current environment.
130+
# Use setup.py instead of `pip install -e .` to be able to pass the -j flag
131+
# to speed-up the building multicore CI machines.
132+
python setup.py build_ext --inplace -j 3
133+
python setup.py develop
134+
fi

build_tools/circle/build_test_pypy.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export LOKY_MAX_CPU_COUNT="2"
3434
export OMP_NUM_THREADS="1"
3535

3636
python setup.py build_ext --inplace -j 3
37-
pip install -e .
37+
pip install --no-build-isolation -e .
3838

3939
# Check that Python implementation is PyPy
4040
python - << EOL

doc/developers/advanced_installation.rst

+14-11
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ feature, code or documentation improvement).
5959
#. Install Cython_ and build the project with pip in :ref:`editable_mode`::
6060

6161
pip install cython
62-
pip install --verbose --editable .
62+
pip install --verbose --no-build-isolation --editable .
6363

6464
#. Check that the installed scikit-learn has a version number ending with
6565
`.dev0`::
@@ -71,8 +71,11 @@ feature, code or documentation improvement).
7171

7272
.. note::
7373

74-
You will have to re-run the ``pip install --editable .`` command every time
75-
the source code of a Cython file is updated (ending in `.pyx` or `.pxd`).
74+
You will have to run the ``pip install --no-build-isolation --editable .``
75+
command every time the source code of a Cython file is updated
76+
(ending in `.pyx` or `.pxd`). Use the ``--no-build-isolation`` flag to
77+
avoid compiling the whole project each time, only the files you have
78+
modified.
7679

7780
Dependencies
7881
------------
@@ -152,9 +155,9 @@ Editable mode
152155

153156
If you run the development version, it is cumbersome to reinstall the package
154157
each time you update the sources. Therefore it is recommended that you install
155-
in with the ``pip install --editable .`` command, which allows you to edit the
156-
code in-place. This builds the extension in place and creates a link to the
157-
development directory (see `the pip docs
158+
in with the ``pip install --no-build-isolation --editable .`` command, which
159+
allows you to edit the code in-place. This builds the extension in place and
160+
creates a link to the development directory (see `the pip docs
158161
<https://pip.pypa.io/en/stable/reference/pip_install/#editable-installs>`_).
159162

160163
This is fundamentally similar to using the command ``python setup.py develop``
@@ -207,7 +210,7 @@ environment variables in the current command prompt.
207210

208211
Finally, build scikit-learn from this command prompt::
209212

210-
pip install --verbose --editable .
213+
pip install --verbose --no-build-isolation --editable .
211214

212215
.. _compiler_macos:
213216

@@ -240,7 +243,7 @@ scikit-learn from source::
240243
"conda-forge::compilers>=1.0.4" conda-forge::llvm-openmp
241244
conda activate sklearn-dev
242245
make clean
243-
pip install --verbose --editable .
246+
pip install --verbose --no-build-isolation --editable .
244247

245248
.. note::
246249

@@ -302,7 +305,7 @@ Finally, build scikit-learn in verbose mode (to check for the presence of the
302305
``-fopenmp`` flag in the compiler commands)::
303306

304307
make clean
305-
pip install --verbose --editable .
308+
pip install --verbose --no-build-isolation --editable .
306309

307310
.. _compiler_linux:
308311

@@ -351,7 +354,7 @@ in the user folder using conda::
351354

352355
conda create -n sklearn-dev numpy scipy joblib cython conda-forge::compilers
353356
conda activate sklearn-dev
354-
pip install --verbose --editable .
357+
pip install --verbose --no-build-isolation --editable .
355358

356359
.. _compiler_freebsd:
357360

@@ -374,7 +377,7 @@ can set the environment variables to these locations::
374377

375378
Finally, build the package using the standard command::
376379

377-
pip install --verbose --editable .
380+
pip install --verbose --no-build-isolation --editable .
378381

379382
For the upcoming FreeBSD 12.1 and 11.3 versions, OpenMP will be included in
380383
the base system and these steps will not be necessary.

doc/developers/contributing.rst

+8-3
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ how to set up your git repository:
219219

220220
5. Install scikit-learn in editable mode::
221221

222-
$ pip install --editable .
222+
$ pip install --no-build-isolation --editable .
223223

224224
for more details about advanced installation, see the
225225
:ref:`install_bleeding_edge` section.
@@ -266,8 +266,13 @@ modifying code and submitting a PR:
266266

267267
.. note::
268268

269-
If you are modifying a Cython module, you have to re-run step 5 after modifications
270-
and before testing them.
269+
If you are modifying a Cython module, you have to re-compile after
270+
modifications and before testing them::
271+
272+
pip install --no-build-isolation -e .
273+
274+
Use the ``--no-build-isolation`` flag to avoid compiling the whole project
275+
each time, only the files you have modified.
271276

272277
It is often helpful to keep your local feature branch synchronized with the
273278
latest changes of the main scikit-learn repository::

pyproject.toml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[build-system]
2+
# Minimum requirements for the build system to execute.
3+
requires = [
4+
"setuptools",
5+
"wheel",
6+
"Cython>=0.28.5",
7+
"numpy>=1.13.3",
8+
"scipy>=0.19.1",
9+
]

0 commit comments

Comments
 (0)