From e107c5f2365283fd0ec5bb1946428d051d08c065 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Thu, 4 Jul 2019 14:03:00 -0400 Subject: [PATCH 1/4] DOC: update contributing guidelines for black --- .github/PULL_REQUEST_TEMPLATE.md | 1 + doc/source/development/contributing.rst | 39 +++++++++++++++++-------- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 4e1e9ce017408..7c3870470f074 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,4 +1,5 @@ - [ ] closes #xxxx - [ ] tests added / passed +- [ ] passes `black pandas` - [ ] passes `git diff upstream/master -u -- "*.py" | flake8 --diff` - [ ] whatsnew entry diff --git a/doc/source/development/contributing.rst b/doc/source/development/contributing.rst index dde1db7e693de..92d7cf1a79d8c 100644 --- a/doc/source/development/contributing.rst +++ b/doc/source/development/contributing.rst @@ -562,23 +562,38 @@ many errors as possible, but it may not correct *all* of them. Thus, it is recommended that you run ``cpplint`` to double check and make any other style fixes manually. -Python (PEP8) -~~~~~~~~~~~~~ - -*pandas* uses the `PEP8 `_ standard. -There are several tools to ensure you abide by this standard. Here are *some* of -the more common ``PEP8`` issues: +Python (PEP8 / black) +~~~~~~~~~~~~~~~~~~~~~ -* we restrict line-length to 79 characters to promote readability -* passing arguments should have spaces after commas, e.g. ``foo(arg1, arg2, kw1='bar')`` +*pandas* follows the `PEP8 `_ standard +and uses `Black `_ and +`Flake8 `_ to ensure a consistent code +format throughout the project. -:ref:`Continuous Integration ` will run -the `flake8 `_ tool -and report any stylistic errors in your code. Therefore, it is helpful before -submitting code to run the check yourself on the diff:: +:ref:`Continuous Integration ` will run those tools and +report any stylistic errors in your code. Therefore, it is helpful before +submitting code to run the check yourself:: + black pandas git diff upstream/master -u -- "*.py" | flake8 --diff +to auto-format your code. Additionally, many editors have plugins that will +apply ``black`` as you edit files. + +Optionally, you may wish to setup `pre-commit hooks `_ +to automatically run ``black`` and ``flake8`` when you make a git commit. This +can be done by installing ``pre-commit``:: + + pip install pre-commit + +and then running:: + + pre-commit install + +from the root of the pandas repository. Now ``black`` and ``flake8`` will be run +each time you commit changes. You can skip these checks with +``git commit --no-verify``. + This command will catch any stylistic errors in your changes specifically, but be beware it may not catch all of them. For example, if you delete the only usage of an imported function, it is stylistically incorrect to import an From a8ebd8e556d069e4b1074a60848815d24493bf08 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Thu, 4 Jul 2019 14:09:19 -0400 Subject: [PATCH 2/4] add pre-commit-config file --- pre-commit-config.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 pre-commit-config.yaml diff --git a/pre-commit-config.yaml b/pre-commit-config.yaml new file mode 100644 index 0000000000000..94e13cae38c5d --- /dev/null +++ b/pre-commit-config.yaml @@ -0,0 +1,10 @@ +repos: +- repo: https://github.com/python/black + rev: stable + hooks: + - id: black + language_version: python3.7 +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v2.2.3 + hooks: + - id: flake8 From fe25edbde2ca1c8e21449a034f4836bdb5bc9dba Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Thu, 4 Jul 2019 14:18:37 -0400 Subject: [PATCH 3/4] update pre-commit hook for pandas --- pre-commit-config.yaml | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/pre-commit-config.yaml b/pre-commit-config.yaml index 94e13cae38c5d..5f7143ef518bb 100644 --- a/pre-commit-config.yaml +++ b/pre-commit-config.yaml @@ -1,10 +1,16 @@ repos: -- repo: https://github.com/python/black - rev: stable - hooks: - - id: black - language_version: python3.7 -- repo: https://github.com/pre-commit/pre-commit-hooks - rev: v2.2.3 - hooks: - - id: flake8 + - repo: https://github.com/python/black + rev: stable + hooks: + - id: black + language_version: python3.7 + - repo: https://gitlab.com/pycqa/flake8 + rev: 3.7.7 + hooks: + - id: flake8 + language: python_venv + - repo: https://github.com/pre-commit/mirrors-isort + rev: v4.3.20 + hooks: + - id: isort + language: python_venv From 1e054482975fa840c119eedbea206de3ad23d3de Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Thu, 4 Jul 2019 14:21:59 -0400 Subject: [PATCH 4/4] correct name for config file --- pre-commit-config.yaml => .pre-commit-config.yaml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename pre-commit-config.yaml => .pre-commit-config.yaml (100%) diff --git a/pre-commit-config.yaml b/.pre-commit-config.yaml similarity index 100% rename from pre-commit-config.yaml rename to .pre-commit-config.yaml