From 8701ccc6d87527660d82fbddaefe2a24a6b2cfbf Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 29 Nov 2024 14:59:20 +1100 Subject: [PATCH] mypy: update checker to support specific files overlapping directories This allows single files to use different settings to other files in the same directory. Add check_unused_defines.py. --- tools/check_source/check_mypy.py | 6 ++++++ tools/check_source/check_mypy_config.py | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/tools/check_source/check_mypy.py b/tools/check_source/check_mypy.py index 190a4b19f85..98d8e942dd6 100755 --- a/tools/check_source/check_mypy.py +++ b/tools/check_source/check_mypy.py @@ -68,6 +68,10 @@ def main() -> None: # Fixed location, so change the current working directory doesn't create cache everywhere. cache_dir = os.path.join(os.getcwd(), ".mypy_cache") + # Allow files which are listed explicitly to override files that are included as part of a directory. + # Needed when files need their own arguments and/or environment. + files_explicitly_listed: set[str] = {f for f, _extra_args, _extra_env in PATHS} + if os.path.samefile(sys.argv[-1], __file__): paths = path_expand_with_args(PATHS, is_source) else: @@ -79,6 +83,8 @@ def main() -> None: for f, extra_args, extra_env in paths: if f in PATHS_EXCLUDE: continue + if f in files_explicitly_listed: + continue if not extra_args: extra_args = () diff --git a/tools/check_source/check_mypy_config.py b/tools/check_source/check_mypy_config.py index ac985b78a8a..c61977d15e3 100644 --- a/tools/check_source/check_mypy_config.py +++ b/tools/check_source/check_mypy_config.py @@ -9,6 +9,8 @@ from typing import ( # Notes: # - Most tests in `tests/python` use `bpy` enough that it's simpler to list the scripts that *are* type checked. +# - References individual files which are also included in a directory are supported +# without checking those files twice. This is needed to allow those files to use their own settings. PATHS: tuple[tuple[str, tuple[Any, ...], dict[str, str]], ...] = ( ("build_files/cmake/", (), {'MYPYPATH': "modules"}), ("build_files/utils/", (), {'MYPYPATH': "modules"}), @@ -23,6 +25,7 @@ PATHS: tuple[tuple[str, tuple[Any, ...], dict[str, str]], ...] = ( ("tools/check_blender_release/", (), {}), ("tools/check_docs/", (), {}), ("tools/check_source/", (), {'MYPYPATH': "modules"}), + ("tools/check_source/check_unused_defines.py", (), {'MYPYPATH': "../utils_maintenance/modules"}), ("tools/config/", (), {}), ("tools/triage/", (), {}), ("tools/utils/", (), {}), @@ -56,7 +59,6 @@ PATHS_EXCLUDE = set( "tools/check_blender_release/scripts/requests_basic_access.py", "tools/check_blender_release/scripts/requests_import.py", "tools/check_source/check_descriptions.py", - "tools/check_source/check_unused_defines.py", "tools/utils/blend2json.py", "tools/utils/blender_keyconfig_export_permutations.py", "tools/utils/blender_merge_format_changes.py",