Skip to content

Commit

Permalink
add black/isort configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
KotlinIsland authored and ilevkivskyi committed Jul 27, 2022
1 parent 5718dff commit c898b90
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 8 deletions.
1 change: 1 addition & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<insert format ref here>
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ jobs:
arch: x64
os: windows-latest
toxenv: type
- name: Code style with flake8
- name: Formatting with Black + isort and code style with flake8
python: '3.7'
arch: x64
os: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ docs/source/_build
mypyc/doc/_build
*.iml
/out/
.venv
.venv*
venv/
.mypy_cache/
.incremental_checker_cache.json
Expand Down
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
repos:
- repo: https://github.com/psf/black
rev: 22.6.0 # must match test-requirements.txt
hooks:
- id: black
- repo: https://github.com/pycqa/isort
rev: 5.10.1 # must match test-requirements.txt
hooks:
- id: isort
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ Mypy: Static Typing for Python
[![Documentation Status](https://readthedocs.org/projects/mypy/badge/?version=latest)](https://mypy.readthedocs.io/en/latest/?badge=latest)
[![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)
[![Checked with mypy](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/)

[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg")](https://github.com/psf/black)
[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/)

Got a question?
---------------
Expand Down
21 changes: 21 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,24 @@ requires = [
"wheel >= 0.30.0",
]
build-backend = "setuptools.build_meta"

[tool.black]
line-length = 99
target-version = ['py37']
skip-magic-trailing-comma = true
extend-exclude = '''
^/mypy/typeshed|
^/mypyc/test-data|
^/test-data
'''

[tool.isort]
profile = "black"
line_length = 99
combine_as_imports = true
skip_gitignore = true
skip = [
"mypy/typeshed",
"mypyc/test-data",
"test-data",
]
8 changes: 5 additions & 3 deletions runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@
'self': [executable, '-m', 'mypy', '--config-file', 'mypy_self_check.ini', '-p', 'mypy'],
# Lint
'lint': ['flake8', '-j0'],
"format-black": ["black", "."],
"format-isort": ["isort", "."],
# Fast test cases only (this is the bulk of the test suite)
'pytest-fast': ['pytest', '-q', '-k', 'not (%s)' % ' or '.join(ALL_NON_FAST)],
'pytest-fast': ['pytest', '-q', '-k', f"not ({' or '.join(ALL_NON_FAST)})"],
# Test cases that invoke mypy (with small inputs)
'pytest-cmdline': ['pytest', '-q', '-k', ' or '.join([CMDLINE,
EVALUATION,
Expand Down Expand Up @@ -118,7 +120,7 @@ def wait_background_cmd(name: str, proc: Popen) -> int:
print(f'run {name}: {cmds[name]}')
if status:
print(output.decode().rstrip())
print('\nFAILED: %s' % name)
print("\nFAILED:", name)
if name in FAST_FAIL:
exit(status)
return status
Expand All @@ -128,7 +130,7 @@ def main() -> None:
prog, *args = argv

if not set(args).issubset(cmds):
print("usage:", prog, " ".join('[%s]' % k for k in cmds))
print("usage:", prog, " ".join(f"[{k}]" for k in cmds))
print()
print('Run the given tests. If given no arguments, run everything except'
+ ' pytest-extra and mypyc-extra.')
Expand Down
4 changes: 3 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ exclude =

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

[coverage:run]
branch = true
Expand Down
2 changes: 2 additions & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
-r mypy-requirements.txt
-r build-requirements.txt
attrs>=18.0
black==22.6.0 # must match version in .pre-commit-config.yaml
filelock>=3.3.0,<3.4.2; python_version<'3.7'
filelock>=3.3.0; python_version>='3.7'
flake8==3.9.2
flake8-bugbear==22.3.20
flake8-pyi>=20.5
isort[colors]==5.10.1 # must match version in .pre-commit-config.yaml
lxml>=4.4.0; python_version<'3.11'
psutil>=4.0
# pytest 6.2.3 does not support Python 3.10
Expand Down
5 changes: 4 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ parallel_show_output = True

[testenv:lint]
description = check the code style
commands = flake8 {posargs}
commands =
flake8 {posargs}
black --check --diff --color .
isort --check --diff --color .

[testenv:type]
description = type check ourselves
Expand Down

0 comments on commit c898b90

Please sign in to comment.