From 08b1c474b32d3f32bc64a59a7e77d87c43527e1f Mon Sep 17 00:00:00 2001 From: Wan Liuyang Date: Thu, 13 Feb 2020 18:49:35 +0800 Subject: [PATCH] Add pre-commit plugin for black/isort/flake8 (#1398) * Add pre-commit plugin for black/isort/flake8 * Update .pre-commit-config.yaml * Add a few more useful hooks --- .isort.cfg | 2 +- .pre-commit-config.yaml | 23 +++++++++++++++++++++++ CONTRIBUTING.md | 12 +++++++++++- 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.isort.cfg b/.isort.cfg index 1417b118..64e39a4e 100644 --- a/.isort.cfg +++ b/.isort.cfg @@ -4,5 +4,5 @@ include_trailing_comma=True force_grid_wrap=0 use_parentheses=True line_length=88 -known_third_party=deprecated,httpretty,jwt,parameterized,requests,setuptools,six,urllib3 +known_third_party=deprecated,httpretty,jwt,parameterized,requests,setuptools,urllib3 known_first_party=github diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..84d3cbae --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,23 @@ +repos: + - repo: https://github.com/psf/black + rev: stable + hooks: + - id: black + language_version: python3.6 + - repo: https://github.com/asottile/seed-isort-config + rev: v1.9.4 + hooks: + - id: seed-isort-config + - repo: https://github.com/pre-commit/mirrors-isort + rev: v4.3.21 + hooks: + - id: isort + - repo: https://gitlab.com/pycqa/flake8 + rev: 3.7.9 + hooks: + - id: flake8 + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v2.3.0 + hooks: + - id: end-of-file-fixer + - id: trailing-whitespace diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 55608520..fbc6a7c8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -23,7 +23,7 @@ Pull Requests should clearly describe two things: Ideally, changes should be made in logical commits and tests added to improve the project's coverage of the GitHub API. -## Coding conventions +## Coding style PyGithub adopts the black coding style and uses isort to sort imports. @@ -32,6 +32,16 @@ To manually format the code: tox -e format ``` +## Pre-commit plugin + +To forget about coding style and let [pre-commit](https://pre-commit.com/#installation) fix your flake8/isort/black issue. + +``` +pre-commit install +``` + +That's it! + ## Adding missing attributes for a GithubObject ```bash