Add python configs for consistency between IDE and CI

Also adds settings to .vscode/settings.json to use the correct
formatter and type checking settings out of the box.

VSCode uses pyright and health-check uses mypy. They do not always
agree unfortunately, mypy  is a little more lenient.
Unfortunately pyright is hard to get working with our scripts that
have no file extension.

BUG=b:242605601
TEST=./tools/health-check

Change-Id: Iaef4ac6f61613e7dda409d5e717102ea9adefe82
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3833699
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Tested-by: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
This commit is contained in:
Dennis Kempin 2022-08-16 17:24:40 +00:00 committed by crosvm LUCI
parent c89cf4b332
commit abcfc67d8b
5 changed files with 23 additions and 3 deletions

3
.gitignore vendored
View file

@ -6,5 +6,6 @@ target/
**/*.pyc
lcov.info
.idea
.vscode
.envrc
.vscode/*
!.vscode/settings.json

5
.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,5 @@
{
// Python
"python.formatting.provider": "black",
"python.analysis.typeCheckingMode": "strict"
}

3
mypy.ini Normal file
View file

@ -0,0 +1,3 @@
[mypy]
python_version = 3.9
mypy_path = tools

11
pyproject.toml Normal file
View file

@ -0,0 +1,11 @@
[tool.black]
line-length = 100
[tool.pyright]
include = ["tools"]
exclude = ["target"]
ignore = ["infra", "tools/windows", "tools/contrib"]
pythonVersion = "3.9"
pythonPlatform = "Linux"
typeCheckingMode = "strict"

View file

@ -18,12 +18,12 @@ def check_python_tests(context: CheckContext):
def check_python_types(context: CheckContext):
"Run mypy on all python files to type-check."
mypy = cmd("mypy --pretty --color-output").env("MYPY_FORCE_COLOR", "1").env("MYPYPATH", "tools")
mypy = cmd("mypy --pretty --color-output").env("MYPY_FORCE_COLOR", "1")
parallel(*mypy.foreach(context.all_files)).fg()
def check_python_format(context: CheckContext):
black = cmd("black", "--line-length 100", "--check" if not context.fix else "")
black = cmd("black", "--check" if not context.fix else "")
parallel(*black.foreach(context.modified_files)).fg()