Skip to content

Black formatting#17

Draft
Zarathustra2 wants to merge 3 commits intocb109:developfrom
Zarathustra2:black-formatting
Draft

Black formatting#17
Zarathustra2 wants to merge 3 commits intocb109:developfrom
Zarathustra2:black-formatting

Conversation

@Zarathustra2
Copy link
Contributor

WIP. Fixes #15

Added black formatting, pre-commit & black config file and updated travis file.
I would need some information about the coding format for this project before I apply the formatting via black.

@cb109
Copy link
Owner

cb109 commented Sep 23, 2019

I am going to add support for auto-formatting with black and isort based on this once I've figured out how likely my VPS is going to handle installing Python 3.6+ (black requirement) as I just noticed it still runs on 3.5.

@cb109
Copy link
Owner

cb109 commented Sep 23, 2019

I recently setup that combination on another project with pre-commit and ran into some caveats, namely isort having issues figuring out which libraries are third- or first-party and thus confusing their ordering. I could fix those by introducing another pre-step that will populate a list of third party libraries before running isort. This is the pre-commit configuration, isort configuration and black configuration that I used:

.pre-commit-config.yaml

repos:

# Note: black config can be found in the pyproject.toml
- repo: https://github.com/psf/black
  rev: stable
  hooks:
  - id: black
    language_version: python3.7

# This little thingie helps isort to figure out what libraries are
# third party, see https://github.com/asottile/seed-isort-config
- repo: https://github.com/asottile/seed-isort-config
  rev: v1.9.2
  hooks:
  - id: seed-isort-config

# Note: isort config can be found in the .isort.cfg
- repo: https://github.com/pre-commit/mirrors-isort
  rev: v4.3.21
  hooks:
  - id: isort
    name: isort
    entry: isort
    require_serial: true
    language: python
    types: [python]
    exclude: migrations/*.py

pyproject.toml

[tool.black]
line-length = 88
target_version = ['py37']
include = '\.pyi?$'
exclude = '''

(
  /(
      \.eggs
    | \.git
    | \.hg
    | \.mypy_cache
    | \.tox
    | \.venv
    | _build
    | buck-out
    | build
    | dist
  )/
)

.isort.cfg

[settings]
force_grid_wrap=False
force_single_line=True
include_trailing_comma=True
line_length=88
multi_line_output=3
use_parentheses=True
known_third_party=
known_first_party=msrcms
sections=FUTURE,STDLIB,THIRDPARTY,FIRSTPARTY,LOCALFOLDER

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Black - Code Formatting

2 participants