pw_presubmit: Run Python presubmit steps in GN

- Remove the discrete Python check steps and run these checks through
  GN instead.
- Move auxiliary Python files from inputs to sources so they're covered
  by pylint and mypy.

Change-Id: I55ef3e5b696e85ee1aee800ed175c852397f5e86
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/22401
Commit-Queue: Wyatt Hepler <hepler@google.com>
Reviewed-by: Rob Mohr <mohrr@google.com>
diff --git a/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py b/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py
index c1228e2..9659bc4 100755
--- a/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py
+++ b/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py
@@ -33,7 +33,7 @@
     import pw_presubmit
 
 from pw_presubmit import build, cli, environment, format_code, git_repo
-from pw_presubmit import python_checks
+from pw_presubmit import python_checks as legacy_python_checks
 from pw_presubmit import call, filter_paths, plural, PresubmitContext
 from pw_presubmit import PresubmitFailure, Programs
 from pw_presubmit.install_hook import install_hook
@@ -53,7 +53,8 @@
 
 
 # Trigger builds if files with these extensions change.
-_BUILD_EXTENSIONS = ('.rst', '.gn', '.gni', *format_code.C_FORMAT.extensions)
+_BUILD_EXTENSIONS = ('.py', '.rst', '.gn', '.gni',
+                     *format_code.C_FORMAT.extensions)
 
 
 def _at_all_optimization_levels(target):
@@ -73,7 +74,7 @@
 def gn_quick_build_check(ctx: PresubmitContext):
     build.gn_gen(ctx.root, ctx.output_dir)
     build.ninja(ctx.output_dir, 'host_clang_size_optimized',
-                'stm32f429i_size_optimized')
+                'stm32f429i_size_optimized', 'python.tests', 'python.lint')
 
 
 @filter_paths(endswith=_BUILD_EXTENSIONS)
@@ -121,6 +122,18 @@
     build.ninja(ctx.output_dir, "host_clang")
 
 
+@filter_paths(endswith='.py')
+def python_checks(ctx: PresubmitContext):
+    build.gn_gen(ctx.root, ctx.output_dir)
+    build.ninja(
+        ctx.output_dir,
+        ':python.lint',
+        ':python.tests',
+        ':target_support_packages.lint',
+        ':target_support_packages.tests',
+    )
+
+
 @filter_paths(endswith=(*format_code.C_FORMAT.extensions, '.cmake',
                         'CMakeLists.txt'))
 def cmake_tests(ctx: PresubmitContext):
@@ -433,7 +446,8 @@
     # failing.
     oss_fuzz_build,
     bazel_test,
-)
+    # TODO(hepler): Remove these redundant checks.
+    *legacy_python_checks.all_checks())
 
 QUICK = (
     commit_message_format,
@@ -444,7 +458,6 @@
     pw_presubmit.pragma_once,
     gn_quick_build_check,
     source_is_in_build_files,
-    python_checks.all_checks(),
 )
 
 FULL = (
@@ -466,7 +479,7 @@
     # two extra flags: "-nostdc++" and "${clang_prefix}../lib/libc++.a".
     cmake_tests if sys.platform != 'darwin' else (),
     source_is_in_build_files,
-    python_checks.all_checks(),
+    python_checks,
     build_env_setup,
 )
 
diff --git a/pw_tokenizer/py/BUILD.gn b/pw_tokenizer/py/BUILD.gn
index 1c568fd..eca6abc 100644
--- a/pw_tokenizer/py/BUILD.gn
+++ b/pw_tokenizer/py/BUILD.gn
@@ -19,6 +19,9 @@
 pw_python_package("py") {
   setup = [ "setup.py" ]
   sources = [
+    "generate_argument_types_macro.py",
+    "generate_hash_macro.py",
+    "generate_hash_test_data.py",
     "pw_tokenizer/__init__.py",
     "pw_tokenizer/__main__.py",
     "pw_tokenizer/database.py",
@@ -28,6 +31,8 @@
     "pw_tokenizer/encode.py",
     "pw_tokenizer/serial_detokenizer.py",
     "pw_tokenizer/tokens.py",
+    "tokenized_string_decoding_test_data.py",
+    "varint_test_data.py",
   ]
   tests = [
     "database_test.py",
@@ -37,11 +42,4 @@
     "encode_test.py",
     "tokens_test.py",
   ]
-  inputs = [
-    "generate_argument_types_macro.py",
-    "generate_hash_macro.py",
-    "generate_hash_test_data.py",
-    "tokenized_string_decoding_test_data.py",
-    "varint_test_data.py",
-  ]
 }