Skip to content

Commit c898b90

Browse files
KotlinIslandilevkivskyi
authored andcommitted
add black/isort configuration
1 parent 5718dff commit c898b90

10 files changed

+49
-8
lines changed

.git-blame-ignore-revs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<insert format ref here>

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ jobs:
8686
arch: x64
8787
os: windows-latest
8888
toxenv: type
89-
- name: Code style with flake8
89+
- name: Formatting with Black + isort and code style with flake8
9090
python: '3.7'
9191
arch: x64
9292
os: ubuntu-latest

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ docs/source/_build
99
mypyc/doc/_build
1010
*.iml
1111
/out/
12-
.venv
12+
.venv*
1313
venv/
1414
.mypy_cache/
1515
.incremental_checker_cache.json

.pre-commit-config.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
repos:
2+
- repo: https://github.com/psf/black
3+
rev: 22.6.0 # must match test-requirements.txt
4+
hooks:
5+
- id: black
6+
- repo: https://github.com/pycqa/isort
7+
rev: 5.10.1 # must match test-requirements.txt
8+
hooks:
9+
- id: isort

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ Mypy: Static Typing for Python
99
[![Documentation Status](https://readthedocs.org/projects/mypy/badge/?version=latest)](https://mypy.readthedocs.io/en/latest/?badge=latest)
1010
[![Chat at https://gitter.im/python/typing](https://badges.gitter.im/python/typing.svg)](https://gitter.im/python/typing?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
1111
[![Checked with mypy](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/)
12-
12+
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg")](https://github.com/psf/black)
13+
[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/)
1314

1415
Got a question?
1516
---------------

pyproject.toml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,24 @@ requires = [
44
"wheel >= 0.30.0",
55
]
66
build-backend = "setuptools.build_meta"
7+
8+
[tool.black]
9+
line-length = 99
10+
target-version = ['py37']
11+
skip-magic-trailing-comma = true
12+
extend-exclude = '''
13+
^/mypy/typeshed|
14+
^/mypyc/test-data|
15+
^/test-data
16+
'''
17+
18+
[tool.isort]
19+
profile = "black"
20+
line_length = 99
21+
combine_as_imports = true
22+
skip_gitignore = true
23+
skip = [
24+
"mypy/typeshed",
25+
"mypyc/test-data",
26+
"test-data",
27+
]

runtests.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@
5252
'self': [executable, '-m', 'mypy', '--config-file', 'mypy_self_check.ini', '-p', 'mypy'],
5353
# Lint
5454
'lint': ['flake8', '-j0'],
55+
"format-black": ["black", "."],
56+
"format-isort": ["isort", "."],
5557
# Fast test cases only (this is the bulk of the test suite)
56-
'pytest-fast': ['pytest', '-q', '-k', 'not (%s)' % ' or '.join(ALL_NON_FAST)],
58+
'pytest-fast': ['pytest', '-q', '-k', f"not ({' or '.join(ALL_NON_FAST)})"],
5759
# Test cases that invoke mypy (with small inputs)
5860
'pytest-cmdline': ['pytest', '-q', '-k', ' or '.join([CMDLINE,
5961
EVALUATION,
@@ -118,7 +120,7 @@ def wait_background_cmd(name: str, proc: Popen) -> int:
118120
print(f'run {name}: {cmds[name]}')
119121
if status:
120122
print(output.decode().rstrip())
121-
print('\nFAILED: %s' % name)
123+
print("\nFAILED:", name)
122124
if name in FAST_FAIL:
123125
exit(status)
124126
return status
@@ -128,7 +130,7 @@ def main() -> None:
128130
prog, *args = argv
129131

130132
if not set(args).issubset(cmds):
131-
print("usage:", prog, " ".join('[%s]' % k for k in cmds))
133+
print("usage:", prog, " ".join(f"[{k}]" for k in cmds))
132134
print()
133135
print('Run the given tests. If given no arguments, run everything except'
134136
+ ' pytest-extra and mypyc-extra.')

setup.cfg

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ exclude =
3434

3535
# Things to ignore:
3636
# E128: continuation line under-indented (too noisy)
37+
# E203: conflicts with black
38+
# E501: conflicts with black
3739
# W601: has_key() deprecated (false positives)
3840
# E701: multiple statements on one line (colon) (we use this for classes with empty body)
3941
# E704: multiple statements on one line (def)
@@ -44,7 +46,7 @@ exclude =
4446
# B011: Don't use assert False
4547
# F821: Name not defined (generates false positives with error codes)
4648
# E741: Ambiguous variable name
47-
extend-ignore = E128,W601,E701,E704,E402,B3,B006,B007,B011,F821,E741
49+
extend-ignore = E128,E203,E501,W601,E701,E704,E402,B3,B006,B007,B011,F821,E741
4850

4951
[coverage:run]
5052
branch = true

test-requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
-r mypy-requirements.txt
22
-r build-requirements.txt
33
attrs>=18.0
4+
black==22.6.0 # must match version in .pre-commit-config.yaml
45
filelock>=3.3.0,<3.4.2; python_version<'3.7'
56
filelock>=3.3.0; python_version>='3.7'
67
flake8==3.9.2
78
flake8-bugbear==22.3.20
89
flake8-pyi>=20.5
10+
isort[colors]==5.10.1 # must match version in .pre-commit-config.yaml
911
lxml>=4.4.0; python_version<'3.11'
1012
psutil>=4.0
1113
# pytest 6.2.3 does not support Python 3.10

tox.ini

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ parallel_show_output = True
4747

4848
[testenv:lint]
4949
description = check the code style
50-
commands = flake8 {posargs}
50+
commands =
51+
flake8 {posargs}
52+
black --check --diff --color .
53+
isort --check --diff --color .
5154

5255
[testenv:type]
5356
description = type check ourselves

0 commit comments

Comments
 (0)