Skip to content

Commit 3d8db98

Browse files
DOC add sphinx-prompt to ease select/copy/paste of prompt command scikit-learn#18512 (scikit-learn#18516)
Co-authored-by: Guillaume Lemaitre <[email protected]>
1 parent d640b7f commit 3d8db98

File tree

11 files changed

+386
-182
lines changed

11 files changed

+386
-182
lines changed

build_tools/circle/build_doc.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ conda create -n $CONDA_ENV_NAME --yes --quiet \
182182
source activate testenv
183183
pip install sphinx-gallery
184184
pip install numpydoc
185+
pip install sphinx-prompt
185186

186187
# Set parallelism to 3 to overlap IO bound tasks with CPU bound tasks on CI
187188
# workers with 2 cores when building the compiled extensions of scikit-learn.

doc/computing/parallelism.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ avoid oversubscription), the implementation will use as many threads as
7979
possible.
8080

8181
You can control the exact number of threads that are used via the
82-
``OMP_NUM_THREADS`` environment variable::
82+
``OMP_NUM_THREADS`` environment variable:
83+
84+
.. prompt:: bash $
8385

8486
OMP_NUM_THREADS=4 python my_script.py
8587

doc/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
'sphinx_gallery.gen_gallery',
4343
'sphinx_issues',
4444
'add_toctree_functions',
45+
'sphinx-prompt',
4546
]
4647

4748
# this is needed for some reason...

doc/developers/advanced_installation.rst

Lines changed: 95 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Installing a nightly build is the quickest way to:
2626

2727
- check whether a bug you encountered has been fixed since the last release.
2828

29-
::
29+
.. prompt:: bash $
3030

3131
pip install --pre --extra-index https://pypi.anaconda.org/scipy-wheels-nightly/simple scikit-learn
3232

@@ -43,7 +43,9 @@ feature, code or documentation improvement).
4343

4444
#. Use `Git <https://git-scm.com/>`_ to check out the latest source from the
4545
`scikit-learn repository <https://github.com/scikit-learn/scikit-learn>`_ on
46-
Github.::
46+
Github.:
47+
48+
.. prompt:: bash $
4749

4850
git clone git://github.com/scikit-learn/scikit-learn.git # add --depth 1 if your connection is slow
4951
cd scikit-learn
@@ -58,13 +60,17 @@ feature, code or documentation improvement).
5860
#. Optional (but recommended): create and activate a dedicated virtualenv_
5961
or `conda environment`_.
6062

61-
#. Install Cython_ and build the project with pip in :ref:`editable_mode`::
63+
#. Install Cython_ and build the project with pip in :ref:`editable_mode`:
64+
65+
.. prompt:: bash $
6266

6367
pip install cython
6468
pip install --verbose --no-build-isolation --editable .
6569

6670
#. Check that the installed scikit-learn has a version number ending with
67-
`.dev0`::
71+
`.dev0`:
72+
73+
.. prompt:: bash $
6874

6975
python -c "import sklearn; sklearn.show_versions()"
7076

@@ -194,11 +200,15 @@ First, install `Build Tools for Visual Studio 2019
194200
Secondly, find out if you are running 64-bit or 32-bit Python. The building
195201
command depends on the architecture of the Python interpreter. You can check
196202
the architecture by running the following in ``cmd`` or ``powershell``
197-
console::
203+
console:
204+
205+
.. prompt:: bash $
198206

199207
python -c "import struct; print(struct.calcsize('P') * 8)"
200208

201-
For 64-bit Python, configure the build environment with::
209+
For 64-bit Python, configure the build environment with:
210+
211+
.. prompt:: bash $
202212

203213
SET DISTUTILS_USE_SDK=1
204214
"C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" x64
@@ -209,7 +219,9 @@ Please be aware that the path above might be different from user to user. The
209219
aim is to point to the "vcvarsall.bat" file that will set the necessary
210220
environment variables in the current command prompt.
211221

212-
Finally, build scikit-learn from this command prompt::
222+
Finally, build scikit-learn from this command prompt:
223+
224+
.. prompt:: bash $
213225

214226
pip install --verbose --no-build-isolation --editable .
215227

@@ -233,12 +245,16 @@ If you use the conda package manager (version >= 4.7), you can install the
233245
``compilers`` meta-package from the conda-forge channel, which provides
234246
OpenMP-enabled C/C++ compilers based on the llvm toolchain.
235247

236-
First install the macOS command line tools::
248+
First install the macOS command line tools:
249+
250+
.. prompt:: bash $
237251

238252
xcode-select --install
239253

240254
It is recommended to use a dedicated `conda environment`_ to build
241-
scikit-learn from source::
255+
scikit-learn from source:
256+
257+
.. prompt:: bash $
242258

243259
conda create -n sklearn-dev -c conda-forge python numpy scipy cython \
244260
joblib threadpoolctl pytest "compilers>=1.0.4,!=1.1.0" llvm-openmp
@@ -254,14 +270,18 @@ scikit-learn from source::
254270
problems for this setup.
255271

256272
You can check that the custom compilers are properly installed from conda
257-
forge using the following command::
273+
forge using the following command:
258274

259-
conda list
275+
.. prompt:: bash $
276+
277+
conda list
260278

261279
which should include ``compilers`` and ``llvm-openmp``.
262280

263281
The compilers meta-package will automatically set custom environment
264-
variables::
282+
variables:
283+
284+
.. prompt:: bash $
265285

266286
echo $CC
267287
echo $CXX
@@ -283,17 +303,23 @@ macOS compilers from Homebrew
283303
Another solution is to enable OpenMP support for the clang compiler shipped
284304
by default on macOS.
285305

286-
First install the macOS command line tools::
306+
First install the macOS command line tools:
307+
308+
.. prompt:: bash $
287309

288310
xcode-select --install
289311

290312
Install the Homebrew_ package manager for macOS.
291313

292-
Install the LLVM OpenMP library::
314+
Install the LLVM OpenMP library:
315+
316+
.. prompt:: bash $
293317

294318
brew install libomp
295319

296-
Set the following environment variables::
320+
Set the following environment variables:
321+
322+
.. prompt:: bash $
297323

298324
export CC=/usr/bin/clang
299325
export CXX=/usr/bin/clang++
@@ -303,7 +329,9 @@ Set the following environment variables::
303329
export LDFLAGS="$LDFLAGS -Wl,-rpath,/usr/local/opt/libomp/lib -L/usr/local/opt/libomp/lib -lomp"
304330

305331
Finally, build scikit-learn in verbose mode (to check for the presence of the
306-
``-fopenmp`` flag in the compiler commands)::
332+
``-fopenmp`` flag in the compiler commands):
333+
334+
.. prompt:: bash $
307335

308336
make clean
309337
pip install --verbose --no-build-isolation --editable .
@@ -321,11 +349,15 @@ installed the scikit-learn Python development headers and a working C/C++
321349
compiler with OpenMP support (typically the GCC toolchain).
322350

323351
Install build dependencies for Debian-based operating systems, e.g.
324-
Ubuntu::
352+
Ubuntu:
353+
354+
.. prompt:: bash $
325355

326356
sudo apt-get install build-essential python3-dev python3-pip
327357

328-
then proceed as usual::
358+
then proceed as usual:
359+
360+
.. prompt:: bash $
329361

330362
pip3 install cython
331363
pip3 install --verbose --editable .
@@ -339,19 +371,25 @@ using an isolated environment, ``pip3`` should be replaced by ``pip`` in the
339371
above commands.
340372

341373
When precompiled wheels of the runtime dependencies are not avalaible for your
342-
architecture (e.g. ARM), you can install the system versions::
374+
architecture (e.g. ARM), you can install the system versions:
375+
376+
.. prompt:: bash $
343377

344378
sudo apt-get install cython3 python3-numpy python3-scipy
345379

346-
On Red Hat and clones (e.g. CentOS), install the dependencies using::
380+
On Red Hat and clones (e.g. CentOS), install the dependencies using:
381+
382+
.. prompt:: bash $
347383

348384
sudo yum -y install gcc gcc-c++ python3-devel numpy scipy
349385

350386
Linux compilers from conda-forge
351387
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
352388

353389
Alternatively, install a recent version of the GNU C Compiler toolchain (GCC)
354-
in the user folder using conda::
390+
in the user folder using conda:
391+
392+
.. prompt:: bash $
355393

356394
conda create -n sklearn-dev -c conda-forge python numpy scipy cython \
357395
joblib threadpoolctl pytest compilers
@@ -365,19 +403,25 @@ FreeBSD
365403

366404
The clang compiler included in FreeBSD 12.0 and 11.2 base systems does not
367405
include OpenMP support. You need to install the `openmp` library from packages
368-
(or ports)::
406+
(or ports):
407+
408+
.. prompt:: bash $
369409

370410
sudo pkg install openmp
371411

372412
This will install header files in ``/usr/local/include`` and libs in
373413
``/usr/local/lib``. Since these directories are not searched by default, you
374-
can set the environment variables to these locations::
414+
can set the environment variables to these locations:
415+
416+
.. prompt:: bash $
375417

376418
export CFLAGS="$CFLAGS -I/usr/local/include"
377419
export CXXFLAGS="$CXXFLAGS -I/usr/local/include"
378420
export LDFLAGS="$LDFLAGS -Wl,-rpath,/usr/local/lib -L/usr/local/lib -lomp"
379421

380-
Finally, build the package using the standard command::
422+
Finally, build the package using the standard command:
423+
424+
.. prompt:: bash $
381425

382426
pip install --verbose --no-build-isolation --editable .
383427

@@ -393,22 +437,30 @@ the base system and these steps will not be necessary.
393437
Alternative compilers
394438
=====================
395439

396-
The command::
440+
The command:
441+
442+
.. prompt:: bash $
397443

398444
pip install --verbose --editable .
399445

400446
will build scikit-learn using your default C/C++ compiler. If you want to build
401447
scikit-learn with another compiler handled by ``distutils`` or by
402-
``numpy.distutils``, use the following command::
448+
``numpy.distutils``, use the following command:
449+
450+
.. prompt:: bash $
403451

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

406-
To see the list of available compilers run::
454+
To see the list of available compilers run:
455+
456+
.. prompt:: bash $
407457

408458
python setup.py build_ext --help-compiler
409459

410460
If your compiler is not listed here, you can specify it via the ``CC`` and
411-
``LDSHARED`` environment variables (does not work on windows)::
461+
``LDSHARED`` environment variables (does not work on windows):
462+
463+
.. prompt:: bash $
412464

413465
CC=<compiler> LDSHARED="<compiler> -shared" python setup.py build_ext -i
414466

@@ -417,26 +469,36 @@ Building with Intel C Compiler (ICC) using oneAPI on Linux
417469

418470
Intel provides access to all of its oneAPI toolkits and packages through a
419471
public APT repository. First you need to get and install the public key of this
420-
repository::
472+
repository:
473+
474+
.. prompt:: bash $
421475

422476
wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB
423477
sudo apt-key add GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB
424478
rm GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB
425479

426-
Then, add the oneAPI repository to your APT repositories::
480+
Then, add the oneAPI repository to your APT repositories:
481+
482+
.. prompt:: bash $
427483

428484
sudo add-apt-repository "deb https://apt.repos.intel.com/oneapi all main"
429485
sudo apt-get update
430486

431-
Install ICC, packaged under the name ``intel-oneapi-icc``::
487+
Install ICC, packaged under the name ``intel-oneapi-icc``:
488+
489+
.. prompt:: bash $
432490

433491
sudo apt-get install intel-oneapi-icc
434492

435-
Before using ICC, you need to set up environment variables::
493+
Before using ICC, you need to set up environment variables:
494+
495+
.. prompt:: bash $
436496

437497
source /opt/intel/oneapi/setvars.sh
438498

439-
Finally, you can build scikit-learn. For example on Linux x86_64::
499+
Finally, you can build scikit-learn. For example on Linux x86_64:
500+
501+
.. prompt:: bash $
440502

441503
python setup.py build_ext --compiler=intelem -i build_clib --compiler=intelem
442504

0 commit comments

Comments
 (0)