Skip to content
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

Black formatting #17

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft

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