From abcfc67d8bb326c3082007f06a4fd933f0d11426 Mon Sep 17 00:00:00 2001 From: Dennis Kempin Date: Tue, 16 Aug 2022 17:24:40 +0000 Subject: [PATCH] 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 Tested-by: Dennis Kempin Reviewed-by: Daniel Verkamp --- .gitignore | 3 ++- .vscode/settings.json | 5 +++++ mypy.ini | 3 +++ pyproject.toml | 11 +++++++++++ tools/health-check | 4 ++-- 5 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 mypy.ini create mode 100644 pyproject.toml diff --git a/.gitignore b/.gitignore index 6e197e75c6..59d7832f99 100644 --- a/.gitignore +++ b/.gitignore @@ -6,5 +6,6 @@ target/ **/*.pyc lcov.info .idea -.vscode .envrc +.vscode/* +!.vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000000..540d2904ec --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + // Python + "python.formatting.provider": "black", + "python.analysis.typeCheckingMode": "strict" +} diff --git a/mypy.ini b/mypy.ini new file mode 100644 index 0000000000..ba52c21726 --- /dev/null +++ b/mypy.ini @@ -0,0 +1,3 @@ +[mypy] +python_version = 3.9 +mypy_path = tools diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000000..2d341f3d8c --- /dev/null +++ b/pyproject.toml @@ -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" + diff --git a/tools/health-check b/tools/health-check index 9c30ec745b..1fe0d1826c 100755 --- a/tools/health-check +++ b/tools/health-check @@ -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()