Repository: scikit-learn/scikit-learn
Pull request: [MRG] Add extra requirements in setup.py
<!--
Thanks for contributing a pull request! Please ensure you have taken a look at
the contribution guidelines: https://github.com/scikit-learn/scikit-learn/blob/master/CONTRIBUTING.md#pull-request-checklist
-->

#### Reference Issues/PRs
<!--
Example: Fixes #1234. See also #3456.
Please use keywords (e.g., Fixes) to create link to the issues or pull requests
you resolved, so that they will automatically be closed when your pull request
is merged. See https://github.com/blog/1506-closing-issues-via-pull-requests
-->
Fixes #17320

#### What does this implement/fix? Explain your changes.

Add extra requirements of the projects.

This list is based on requirements given in:

 - contributing.rst
 - build_doc.sh
 - README.rst


#### Any other comments?

I've used the list format of `extras_require` but this could be turned into the `dict` version; see [setuptools doc](https://setuptools.readthedocs.io/en/latest/setuptools.html#declaring-extras-optional-features-with-their-own-dependencies). 

<!--
Please be aware that we are a loose team of volunteers so patience is
necessary; assistance handling other issues is very welcome. We value
all user contributions, no matter how minor they are. If we are slow to
review, either the pull request needs some benchmarking, tinkering,
convincing, etc. or more likely the reviewers are simply busy. In either
case, we ask for your understanding during the review process.
For more information, see our FAQ on this topic:
http://scikit-learn.org/dev/faq.html#why-is-my-pull-request-not-getting-any-attention.

Thanks for contributing!
-->


Problem statement:
extras_require for doc building
Now that we are using more dependent packages in our documentation builds, we should have an `extras_require` configuration in setup.py to install appropriate dependencies for building our docs. These dependencies are currently briefly listed in README.rst and doc/developers/contributing.rst and build_tools/circle/build_doc.sh.

Hints from issue discussion:

Commit message: Remove variables for packages versions

Patch to review:
diff --git a/setup.py b/setup.py
index 90162b65644e5..3aa5f614ef125 100755
--- a/setup.py
+++ b/setup.py
@@ -75,9 +75,26 @@
         zip_safe=False,  # the package can run out of an .egg file
         include_package_data=True,
         extras_require={
-            'alldeps': (
-                'numpy >= {}'.format(NUMPY_MIN_VERSION),
-                'scipy >= {}'.format(SCIPY_MIN_VERSION),
+            'examples': (
+                'matplotlib>=2.1.1',
+                'scikit-image>=0.13',
+                'pandas>=0.18.0',
+                'seaborn>=0.9.0',
+            ),
+            'benchmark': (
+                'memory_profiler>=0.57.0'
+            ),
+            'tests': (
+                'pytest>=3.3.0',
+                'pytest-cov>=2.9.0',
+                'flake8>=3.8.2',
+                'mypy>=0.770',
+            ),
+            'docs': (
+                'sphinx>=2.1.2',
+                'sphinx-gallery>=0.7.0',
+                'numpydoc>=0.9.2'
+                'Pillow>=7.1.2',
             ),
         },
     )
@@ -256,10 +273,10 @@ def setup_package():
                     cmdclass=cmdclass,
                     python_requires=">=3.6",
                     install_requires=[
-                        'numpy>={}'.format(NUMPY_MIN_VERSION),
-                        'scipy>={}'.format(SCIPY_MIN_VERSION),
-                        'joblib>={}'.format(JOBLIB_MIN_VERSION),
-                        'threadpoolctl>={}'.format(THREADPOOLCTL_MIN_VERSION)
+                        f'numpy>={NUMPY_MIN_VERSION}',
+                        f'scipy>={SCIPY_MIN_VERSION}',
+                        f'joblib>={JOBLIB_MIN_VERSION}',
+                        f'threadpoolctl>={THREADPOOLCTL_MIN_VERSION}'
                     ],
                     package_data={'': ['*.pxd']},
                     **extra_setuptools_args)


Code review comments:
diff_hunk: @@ -256,10 +273,10 @@ def setup_package():
                     cmdclass=cmdclass,
                     python_requires=">=3.6",
                     install_requires=[
-                        'numpy>={}'.format(NUMPY_MIN_VERSION),
-                        'scipy>={}'.format(SCIPY_MIN_VERSION),
-                        'joblib>={}'.format(JOBLIB_MIN_VERSION),
-                        'threadpoolctl>={}'.format(THREADPOOLCTL_MIN_VERSION)
+                        f'numpy>={NUMPY_MIN_VERSION}',
+                        f'scipy>={SCIPY_MIN_VERSION}',
+                        f'joblib>={JOBLIB_MIN_VERSION}',
+                        f'threadpoolctl>={THREADPOOLCTL_MIN_VERSION}'
path: setup.py
text: @user1:
When building from source, this would result in a `SyntaxError`:

```
    f'numpy>={NUMPY_MIN_VERSION}',
                                ^
SyntaxError: invalid syntax
```

rather than the nicer:

```
ERROR: Package 'scikit-learn' requires a different Python: 3.5.5
```

@author:
I've reinstalled the source in a new virtual environment with the editable mode [as indicated in the documentation](https://scikit-learn.org/stable/developers/advanced_installation.html#building-from-source) using:
```bash
python -m venv /tmp/venv
source /tmp/venv/bin/activate
pip install wheel
pip install cython
pip install --verbose --no-build-isolation --editable .
```
but I haven't meet this problem.

How can I reproduce this problem?

@user2:
Thomas is right that f-stings are not supported in Python <=3.5: we should revert to using `.format` so that people who mistakenly use Py3.5 get a nice error message.

@author:
As far as I've seen, scikit-learn requires python 3.6 and newer, isn't it?

@user2:
Yes, but if you mistakenly try install it for Python 3.5- previously one would get an error saying that you need python 3.6+ now it will just produce a syntax error which is not very nice.

@author:
OK, makes sense. I followed @user3 's suggestions (see above) but I can revert back to the `format` syntax.