mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-03 19:42:55 +00:00
test_runner: replace yapf with black and isort
This commit is contained in:
committed by
Alexander Bayandin
parent
277f2d6d3d
commit
6b2e1d9065
7
.github/workflows/codestyle.yml
vendored
7
.github/workflows/codestyle.yml
vendored
@@ -128,8 +128,11 @@ jobs:
|
||||
- name: Install Python deps
|
||||
run: ./scripts/pysync
|
||||
|
||||
- name: Run yapf to ensure code format
|
||||
run: poetry run yapf --recursive --diff .
|
||||
- name: Run isort to ensure code format
|
||||
run: poetry run isort --diff --check .
|
||||
|
||||
- name: Run black to ensure code format
|
||||
run: poetry run black --diff --check .
|
||||
|
||||
- name: Run mypy to check types
|
||||
run: poetry run mypy .
|
||||
|
||||
10
.yapfignore
10
.yapfignore
@@ -1,10 +0,0 @@
|
||||
# This file is only read when `yapf` is run from this directory.
|
||||
# Hence we only top-level directories here to avoid confusion.
|
||||
# See source code for the exact file format: https://github.com/google/yapf/blob/c6077954245bc3add82dafd853a1c7305a6ebd20/yapf/yapflib/file_resources.py#L40-L43
|
||||
vendor/
|
||||
target/
|
||||
tmp_install/
|
||||
__pycache__/
|
||||
test_output/
|
||||
.neon/
|
||||
.git/
|
||||
@@ -112,11 +112,12 @@ Run `poetry shell` to activate the virtual environment.
|
||||
Alternatively, use `poetry run` to run a single command in the venv, e.g. `poetry run pytest`.
|
||||
|
||||
### Obligatory checks
|
||||
We force code formatting via `yapf` and type hints via `mypy`.
|
||||
Run the following commands in the repository's root (next to `setup.cfg`):
|
||||
We force code formatting via `black`, `isort` and type hints via `mypy`.
|
||||
Run the following commands in the repository's root (next to `pyproject.toml`):
|
||||
|
||||
```bash
|
||||
poetry run yapf -ri . # All code is reformatted
|
||||
poetry run isort . # Imports are reformatted
|
||||
poetry run black . # All code is reformatted
|
||||
poetry run mypy . # Ensure there are no typing errors
|
||||
```
|
||||
|
||||
|
||||
743
poetry.lock
generated
743
poetry.lock
generated
File diff suppressed because one or more lines are too long
@@ -1,11 +1,10 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from typing import List
|
||||
import argparse
|
||||
import enum
|
||||
import subprocess
|
||||
import sys
|
||||
import enum
|
||||
import argparse
|
||||
import os
|
||||
from typing import List
|
||||
|
||||
|
||||
@enum.unique
|
||||
@@ -37,12 +36,17 @@ def rustfmt(fix_inplace: bool = False, no_color: bool = False) -> str:
|
||||
return cmd
|
||||
|
||||
|
||||
def yapf(fix_inplace: bool) -> str:
|
||||
cmd = "poetry run yapf --recursive"
|
||||
if fix_inplace:
|
||||
cmd += " --in-place"
|
||||
else:
|
||||
cmd += " --diff"
|
||||
def black(fix_inplace: bool) -> str:
|
||||
cmd = "poetry run black"
|
||||
if not fix_inplace:
|
||||
cmd += " --diff --check"
|
||||
return cmd
|
||||
|
||||
|
||||
def isort(fix_inplace: bool) -> str:
|
||||
cmd = "poetry run isort"
|
||||
if not fix_inplace:
|
||||
cmd += " --diff --check"
|
||||
return cmd
|
||||
|
||||
|
||||
@@ -71,11 +75,13 @@ def check(name: str, suffix: str, cmd: str, changed_files: List[str], no_color:
|
||||
else:
|
||||
print("Please inspect the output below and run make fmt to fix automatically.")
|
||||
if suffix == ".py":
|
||||
print("If the output is empty, ensure that you've installed Python tooling by\n"
|
||||
"running './scripts/pysync' in the current directory (no root needed)")
|
||||
print(
|
||||
"If the output is empty, ensure that you've installed Python tooling by\n"
|
||||
"running './scripts/pysync' in the current directory (no root needed)"
|
||||
)
|
||||
print()
|
||||
print(res.stdout.decode())
|
||||
exit(1)
|
||||
sys.exit(1)
|
||||
|
||||
print(colorify("[OK]", Color.GREEN, no_color))
|
||||
|
||||
@@ -83,10 +89,12 @@ def check(name: str, suffix: str, cmd: str, changed_files: List[str], no_color:
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--fix-inplace", action="store_true", help="apply fixes inplace")
|
||||
parser.add_argument("--no-color",
|
||||
action="store_true",
|
||||
help="disable colored output",
|
||||
default=not sys.stdout.isatty())
|
||||
parser.add_argument(
|
||||
"--no-color",
|
||||
action="store_true",
|
||||
help="disable colored output",
|
||||
default=not sys.stdout.isatty(),
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
files = get_commit_files()
|
||||
@@ -101,9 +109,16 @@ if __name__ == "__main__":
|
||||
no_color=args.no_color,
|
||||
)
|
||||
check(
|
||||
name="yapf",
|
||||
name="isort",
|
||||
suffix=".py",
|
||||
cmd=yapf(fix_inplace=args.fix_inplace),
|
||||
cmd=isort(fix_inplace=args.fix_inplace),
|
||||
changed_files=files,
|
||||
no_color=args.no_color,
|
||||
)
|
||||
check(
|
||||
name="black",
|
||||
suffix=".py",
|
||||
cmd=black(fix_inplace=args.fix_inplace),
|
||||
changed_files=files,
|
||||
no_color=args.no_color,
|
||||
)
|
||||
|
||||
@@ -30,10 +30,50 @@ pytest-order = "^1.0.1"
|
||||
allure-pytest = "^2.9.45"
|
||||
|
||||
[tool.poetry.dev-dependencies]
|
||||
yapf = "==0.31.0"
|
||||
flake8 = "^3.9.2"
|
||||
mypy = "==0.971"
|
||||
black = "^22.6.0"
|
||||
isort = "^5.10.1"
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core>=1.0.0"]
|
||||
build-backend = "poetry.core.masonry.api"
|
||||
|
||||
[tool.black]
|
||||
line-length = 100
|
||||
extend-exclude = '''
|
||||
/(
|
||||
vendor
|
||||
)/
|
||||
'''
|
||||
|
||||
[tool.isort]
|
||||
profile = "black"
|
||||
line_length = 100
|
||||
skip_gitignore = true
|
||||
skip = [
|
||||
"vendor",
|
||||
]
|
||||
|
||||
[tool.mypy]
|
||||
# mypy uses regex
|
||||
exclude = "^vendor/"
|
||||
# some tests don't typecheck when this flag is set
|
||||
check_untyped_defs = false
|
||||
# Help mypy find imports when running against list of individual files.
|
||||
# Without this line it would behave differently when executed on the entire project.
|
||||
mypy_path = "$MYPY_CONFIG_FILE_DIR:$MYPY_CONFIG_FILE_DIR/test_runner"
|
||||
|
||||
disallow_incomplete_defs = false
|
||||
disallow_untyped_calls = false
|
||||
disallow_untyped_decorators = false
|
||||
disallow_untyped_defs = false
|
||||
strict = true
|
||||
|
||||
[[tool.mypy.overrides]]
|
||||
module = [
|
||||
"asyncpg.*",
|
||||
"cached_property.*",
|
||||
"pg8000.*",
|
||||
]
|
||||
ignore_missing_imports = true
|
||||
|
||||
43
setup.cfg
43
setup.cfg
@@ -1,43 +0,0 @@
|
||||
# Just trying to gather linter settings in one file.
|
||||
# I wonder if there's a way to de-duplicate them...
|
||||
|
||||
[flake8]
|
||||
max-line-length = 100
|
||||
|
||||
[pycodestyle]
|
||||
max-line-length = 100
|
||||
|
||||
[yapf]
|
||||
based_on_style = pep8
|
||||
column_limit = 100
|
||||
split_all_top_level_comma_separated_values = true
|
||||
|
||||
[mypy]
|
||||
# mypy uses regex
|
||||
exclude = ^vendor/
|
||||
# some tests don't typecheck when this flag is set
|
||||
check_untyped_defs = false
|
||||
|
||||
# Help mypy find imports when running against list of individual files.
|
||||
# Without this line it would behave differently when executed on the entire project.
|
||||
mypy_path = $MYPY_CONFIG_FILE_DIR:$MYPY_CONFIG_FILE_DIR/test_runner
|
||||
|
||||
disallow_incomplete_defs = false
|
||||
disallow_untyped_calls = false
|
||||
disallow_untyped_decorators = false
|
||||
disallow_untyped_defs = false
|
||||
strict = true
|
||||
|
||||
[mypy-asyncpg.*]
|
||||
# There is some work in progress, though: https://github.com/MagicStack/asyncpg/pull/577
|
||||
ignore_missing_imports = true
|
||||
|
||||
[mypy-pg8000.*]
|
||||
# Used only in testing clients
|
||||
ignore_missing_imports = true
|
||||
|
||||
[mypy-cached_property.*]
|
||||
ignore_missing_imports = true
|
||||
|
||||
[mypy-pytest.*]
|
||||
ignore_missing_imports = true
|
||||
Reference in New Issue
Block a user