8000 MAINT Black formatting prework by thomasjpfan · Pull Request #20260 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content
8000

MAINT Black formatting prework #20260

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 11 commits into from
Jun 17, 2021
6 changes: 5 additions & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,12 @@ jobs:
versionSpec: '3.9'
- bash: |
# Include pytest compatibility with mypy
pip install pytest flake8 mypy==0.782
pip install pytest flake8 mypy==0.782 black==21.6b0
displayName: Install linters
- bash: |
# Remove comment when code is formatted by black
# black --check .
displayName: Run black
- bash: |
./build_tools/circle/linting.sh
displayName: Run linting
Expand Down
50 changes: 35 additions & 15 deletions doc/developers/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ how to set up your git repository:

.. prompt:: bash $

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

5. Install scikit-learn in editable mode:

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

5. **Make sure that your PR does not add PEP8 violations**. To check the
5. Run `black` to auto-format your code.

.. prompt:: bash $

black .

See black's
`editor integration documentation <https://black.readthedocs.io/en/stable/integrations/editors.html>`_
to configure your editor to run `black`.

6. **Make sure that your PR does not add PEP8 violations**. To check the
code that you changed, you can run the following command (see
:ref:`above <upstream>` to set up the ``upstream`` remote):

Expand All @@ -443,14 +453,14 @@ complies with the following rules before marking a PR as ``[MRG]``. The

or `make flake8-diff` which should work on unix-like system.

6. Follow the :ref:`coding-guidelines`.
7. Follow the :ref:`coding-guidelines`.


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

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

9. PRs should often substantiate the change, through benchmarks of
performance and efficiency (see :ref:`monitoring_performances`) or through
examples of usage. Examples also illustrate the features and intricacies of
the library to users. Have a look at other examples in the `examples/
<https://github.com/scikit-learn/scikit-learn/tree/main/examples>`_
directory for reference. Examples should demonstrate why the new
functionality is useful in practice and, if possible, compare it to other
methods available in scikit-learn.
10. PRs should often substantiate the change, through benchmarks of
performance and efficiency (see :ref:`monitoring_performances`) or through
examples of usage. Examples also illustrate the features and intricacies of
the library to users. Have a look at other examples in the `examples/
<https://github.com/scikit-learn/scikit-learn/tree/main/examples>`_
directory for reference. Examples should demonstrate why the new
functionality is useful in practice and, if possible, compare it to other
methods available in scikit-learn.

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

11. The user guide should also include expected time and space complexity
12. The user guide should also include expected time and space complexity
of the algorithm and scalability, e.g. "this algorithm can scale to a
large number of samples > 100000, but does not scale in dimensionality:
n_features is expected to be lower than 100".
Expand Down Expand Up @@ -1357,3 +1367,13 @@ make this task easier and faster (in no particular order).
<https://git-scm.com/docs/git-grep#_examples>`_) is also extremely
useful to see every occurrence of a pattern (e.g. a function call or a
variable) in the code base.

- Configure `git blame` to ignore the commit that migrated the code style to
`black`.

.. prompt:: bash $

git config blame.ignoreRevsFile .git-blame-ignore-revs
Copy link
Member

Choose a reason for hiding this comment

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

Neat!

Copy link
Member

Choose a reason for hiding this comment

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

Is there a way to make it enabled by default? In particular for the online git blame UI of github.com?

Copy link
Member

Choose a reason for hiding this comment

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

I read the link. Unfortunately it's not possible at this time:

The one caveat is that GitHub and GitLab do not yet support ignoring revisions using their native UI of blame. So blame information will be cluttered with a reformatting commit on those platforms. (If you’d like this feature, there’s an open issue for GitLab and please let GitHub know!)

Copy link
Member Author

Choose a reason for hiding this comment

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

The request for github to support blame ignore files is: https://github.community/t/support-ignore-revs-file-in-githubs-blame-view/3256 So using git blame with the github UI will require one more click to get pass the black commit. On the other hand, editors support blame.ignoreRevsFile pretty well.

Copy link
Member

Choose a reason for hiding this comment

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

I "hearted" the feature request on github.community.


Find out more information in black's
`documentation for avoiding ruining git blame <https://black.readthedocs.io/en/stable/guides/introducing_black_to_your_project.html#avoiding-ruining-git-blame>`_.
33 changes: 13 additions & 20 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,17 @@ requires = [
[tool.black]
line-length = 88
exclude = '''

(
/(
\.eggs # exclude a few common directories in the
| \.git # root of the project
| \.mypy_cache
| examples
| build
| dist
| doc
| sklearn/externals
)/
)
'''
include = '''
(
/(
doc/conf.py
)/
)
/(
\.eggs # exclude a few common directories in the
| \.git # root of the project
| \.mypy_cache
| examples
| build
| dist
| doc/tutorial
| doc/_build
| doc/auto_examples
| sklearn/externals
| asv_benchmarks/env
)/
'''
1 change: 1 addition & 0 deletions sklearn/_min_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
'pytest': (PYTEST_MIN_VERSION, 'tests'),
'pytest-cov': ('2.9.0', 'tests'),
'flake8': ('3.8.2', 'tests'),
'black': ('21.6b0', 'tests'),
'mypy': ('0.770', 'tests'),
'pyamg': ('4.0.0', 'tests'),
'sphinx': ('4.0.1', 'docs'),
Expand Down
0