payshare icon indicating copy to clipboard operation
payshare copied to clipboard

Black formatting

Open Zarathustra2 opened this issue 6 years ago • 2 comments

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.

Zarathustra2 avatar Aug 17 '19 15:08 Zarathustra2

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 avatar Sep 23 '19 20:09 cb109

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

cb109 avatar Sep 23 '19 20:09 cb109