8000 MAINT Black formatting prework (#20260) · scikit-learn/scikit-learn@0e7761c · GitHub
[go: up one dir, main page]

Skip to content

Commit 0e7761c

Browse files
authored
MAINT Black formatting prework (#20260)
1 parent e68886f commit 0e7761c

File tree

4 files changed

+54
-36
lines changed

4 files changed

+54
-36
lines changed

azure-pipelines.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,12 @@ jobs:
4545
versionSpec: '3.9'
4646
- bash: |
4747
# Include pytest compatibility with mypy
48-
pip install pytest flake8 mypy==0.782
48+
pip install pytest flake8 mypy==0.782 black==21.6b0
4949
displayName: Install linters
50+
- bash: |
51+
# Remove comment when code is formatted by black
52+
# black --check .
53+
displayName: Run black
5054
- bash: |
5155
./build_tools/circle/linting.sh
5256
displayName: Run linting

doc/developers/contributing.rst

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ how to set up your git repository:
261261

262262
.. prompt:: bash $
263263

264-
pip install cython pytest pytest-cov flake8 mypy
264+
pip install cython pytest pytest-cov flake8 mypy black==21.6b0
265265

266266
5. Install scikit-learn in editable mode:
267267

@@ -433,7 +433,17 @@ complies with the following rules before marking a PR as ``[MRG]``. The
433433
non-regression tests should fail for the code base in the ``main`` branch
434434
and pass for the PR code.
435435

436-
5. **Make sure that your PR does not add PEP8 violations**. To check the
436+
5. Run `black` to auto-format your code.
437+
438+
.. prompt:: bash $
439+
440+
black .
441+
442+
See black's
443+
`editor integration documentation <https://black.readthedocs.io/en/stable/integrations/editors.html>`_
444+
to configure your editor to run `black`.
445+
446+
6. **Make sure that your PR does not add PEP8 violations**. To check the
437447
code that you changed, you can run the following command (see
438448
:ref:`above <upstream>` to set up the ``upstream`` remote):
439449

@@ -443,14 +453,14 @@ complies with the following rules before marking a PR as ``[MRG]``. The
443453
444454
or `make flake8-diff` which should work on unix-like system.
445455

446-
6. Follow the :ref:`coding-guidelines`.
456+
7. Follow the :ref:`coding-guidelines`.
447457

448458

449-
7. When applicable, use the validation tools and scripts in the
459+
8. When applicable, use the validation tools and scripts in the
450460
``sklearn.utils`` submodule. A list of utility routines available
451461
for developers can be found in the :ref:`developers-utils` page.
452462

453-
8. Often pull requests resolve one or more other issues (or pull requests).
463+
9. Often pull requests resolve one or more other issues (or pull requests).
454464
If merging your pull request means that some other issues/PRs should
455465
be closed, you should `use keywords to create link to them
456466
<https://github.com/blog/1506-closing-issues-via-pull-requests/>`_
@@ -460,23 +470,23 @@ complies with the following rules before marking a PR as ``[MRG]``. The
460470
related to some other issues/PRs, create a link to them without using
461471
the keywords (e.g., ``See also #1234``).
462472

463-
9. PRs should often substantiate the change, through benchmarks of
464-
performance and efficiency (see :ref:`monitoring_performances`) or through
465-
examples of usage. Examples also illustrate the features and intricacies of
466-
the library to users. Have a look at other examples in the `examples/
467-
<https://github.com/scikit-learn/scikit-learn/tree/main/examples>`_
468-
directory for reference. Examples should demonstrate why the new
469-
functionality is useful in practice and, if possible, compare it to other
470-
methods available in scikit-learn.
473+
10. PRs should often substantiate the change, through benchmarks of
474+
performance and efficiency (see :ref:`monitoring_performances`) or through
475+
examples of usage. Examples also illustrate the features and intricacies of
476+
the library to users. Have a look E864 at other examples in the `examples/
477+
<https://github.com/scikit-learn/scikit-learn/tree/main/examples>`_
478+
directory for reference. Examples should demonstrate why the new
479+
functionality is useful in practice and, if possible, compare it to other
480+
methods available in scikit-learn.
471481

472-
10. New features have some maintenance overhead. We expect PR authors
482+
11. New features have some maintenance overhead. We expect PR authors
473483
to take part in the maintenance for the code they submit, at least
474484
initially. New features need to be illustrated with narrative
475485
documentation in the user guide, with small code snippets.
476486
If relevant, please also add references in the literature, with PDF links
477487
when possible.
478488

479-
11. The user guide should also include expected time and space complexity
489+
12. The user guide should also include expected time and space complexity
480490
of the algorithm and scalability, e.g. "this algorithm can scale to a
481491
large number of samples > 100000, but does not scale in dimensionality:
482492
n_features is expected to be lower than 100".
@@ -1357,3 +1367,13 @@ make this task easier and faster (in no particular order).
13571367
<https://git-scm.com/docs/git-grep#_examples>`_) is also extremely
13581368
useful to see every occurrence of a pattern (e.g. a function call or a
13591369
variable) in the code base.
1370+
1371+
- Configure `git blame` to ignore the commit that migrated the code style to
1372+
`black`.
1373+
1374+
.. prompt:: bash $
1375+
1376+
git config blame.ignoreRevsFile .git-blame-ignore-revs
1377+
1378+
Find out more information in black's
1379+
`documentation for avoiding ruining git blame <https://black.readthedocs.io/en/stable/guides/introducing_black_to_your_project.html#avoiding-ruining-git-blame>`_.

pyproject.toml

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,17 @@ requires = [
2020
[tool.black]
2121
line-length = 88
2222
exclude = '''
23-
24-
(
25-
/(
26-
\.eggs # exclude a few common directories in the
27-
| \.git # root of the project
28-
| \.mypy_cache
29-
| examples
30-
| build
31-
| dist
32-
| doc
33-
| sklearn/externals
34-
)/
35-
)
36-
'''
37-
include = '''
38-
(
39-
/(
40-
doc/conf.py
41-
)/
42-
)
23+
/(
24+
\.eggs # exclude a few common directories in the
25+
| \.git # root of the project
26+
| \.mypy_cache
27+
| examples
28+
| build
29+
| dist
30+
| doc/tutorial
31+
| doc/_build
32+
| doc/auto_examples
33+
| sklearn/externals
34+
| asv_benchmarks/env
35+
)/
4336
'''

sklearn/_min_dependencies.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
'pytest': (PYTEST_MIN_VERSION, 'tests'),
3434
'pytest-cov': ('2.9.0', 'tests'),
3535
'flake8': ('3.8.2', 'tests'),
36+
'black': ('21.6b0', 'tests'),
3637
'mypy': ('0.770', 'tests'),
3738
'pyamg': ('4.0.0', 'tests'),
3839
'sphinx': ('4.0.1', 'docs'),

0 commit comments

Comments
 (0)
0