From bc762428381fe2a02e3be997ad3291ea2cd331d7 Mon Sep 17 00:00:00 2001 From: Jon Meow <46229924+jonmeow@users.noreply.github.com> Date: Mon, 29 Jun 2020 11:34:15 -0700 Subject: [PATCH] Configure black for Python formatting (#97) --- .pre-commit-config.yaml | 7 ++++++- docs/project/contribution_tools.md | 9 +++++++++ pyproject.toml | 4 ++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 pyproject.toml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 782290432aae..c73ddb478170 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -31,7 +31,12 @@ repos: additional_dependencies: [markdown-toc] files: .*\.md$ exclude: ^src/jekyll/theme/ - # Prettier should be run late so that it can re-format any prior changes. + # Formatters should be run late so that they can re-format any prior changes. + - repo: https://github.com/psf/black + rev: stable + hooks: + - id: black + language_version: python3.6 - repo: https://github.com/prettier/prettier rev: 2.0.5 hooks: diff --git a/docs/project/contribution_tools.md b/docs/project/contribution_tools.md index e162ddaec602..2bd256eddf43 100644 --- a/docs/project/contribution_tools.md +++ b/docs/project/contribution_tools.md @@ -14,6 +14,7 @@ contributions. - [pre-commit](#pre-commit) +- [black](#black) - [codespell](#codespell) - [markdown-toc](#markdown-toc) - [Prettier](#prettier) @@ -42,6 +43,14 @@ To set up pre-commit: When modifying or adding pre-commit hooks, please run `pre-commit run --all-files` to see what changes. +## black + +> **pre-commit enabled**: If you're using pre-commit, it will run this. +> Installing and running manually is optional, but may be helpful. + +We use [Black](https://github.com/psf/black) to format Python code. Although +[Prettier](#prettier) is used for most languages, it doesn't support Python. + ## codespell > **pre-commit enabled**: If you're using pre-commit, it will run this. diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 000000000000..f30e22b74290 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,4 @@ +[tool.black] +line-length = 80 +target-version = ['py36', 'py37', 'py38'] +include = '\.pyi?$'