]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-108455: peg_generator: install two stubs packages before running mypy (#108637)
authorAlex Waygood <Alex.Waygood@Gmail.com>
Tue, 29 Aug 2023 19:14:08 +0000 (20:14 +0100)
committerGitHub <noreply@github.com>
Tue, 29 Aug 2023 19:14:08 +0000 (20:14 +0100)
Tools/peg_generator/mypy.ini
Tools/peg_generator/pegen/build.py
Tools/peg_generator/pegen/testutil.py
Tools/requirements-dev.txt

index 3f3db2ea1266c68b70d6248ca5ff84a85a806007..55429dd76eba686f38a6a0b2ee2d0c109969babb 100644 (file)
@@ -14,5 +14,7 @@ enable_error_code = truthy-bool,ignore-without-code
 warn_return_any = False
 warn_unreachable = False
 
-[mypy-setuptools.*]
-ignore_missing_imports = True
+[mypy-pegen.build]
+# we need this for now due to some missing annotations
+# in typeshed's stubs for setuptools
+disallow_untyped_calls = False
index 81efcadc001ec5826cd5f66a369e6d36f2a9eb11..998cd41428db190cc6f9628ba00d9018c78dc6fd 100644 (file)
@@ -1,4 +1,5 @@
 import itertools
+import logging
 import os
 import pathlib
 import sys
@@ -90,6 +91,7 @@ def compile_c_extension(
     static library of the common parser sources (this is useful in case you are
     creating multiple extensions).
     """
+    import setuptools.command.build_ext
     import setuptools.logging
 
     from setuptools import Extension, Distribution
@@ -98,7 +100,7 @@ def compile_c_extension(
     from setuptools._distutils.sysconfig import customize_compiler
 
     if verbose:
-        setuptools.logging.set_threshold(setuptools.logging.logging.DEBUG)
+        setuptools.logging.set_threshold(logging.DEBUG)
 
     source_file_path = pathlib.Path(generated_source_path)
     extension_name = source_file_path.stem
@@ -140,12 +142,14 @@ def compile_c_extension(
     )
     dist = Distribution({"name": extension_name, "ext_modules": [extension]})
     cmd = dist.get_command_obj("build_ext")
+    assert isinstance(cmd, setuptools.command.build_ext.build_ext)
     fixup_build_ext(cmd)
     cmd.build_lib = str(source_file_path.parent)
     cmd.include_dirs = include_dirs
     if build_dir:
         cmd.build_temp = build_dir
-    cmd.ensure_finalized()
+    # A deficiency in typeshed's stubs means we have to type: ignore:
+    cmd.ensure_finalized()  # type: ignore[attr-defined]
 
     compiler = new_compiler()
     customize_compiler(compiler)
@@ -156,7 +160,8 @@ def compile_c_extension(
         library_filename = compiler.library_filename(extension_name, output_dir=library_dir)
         if newer_group(common_sources, library_filename, "newer"):
             if sys.platform == "win32":
-                pdb = compiler.static_lib_format % (extension_name, ".pdb")
+                # A deficiency in typeshed's stubs means we have to type: ignore:
+                pdb = compiler.static_lib_format % (extension_name, ".pdb")  # type: ignore[attr-defined]
                 compile_opts = [f"/Fd{library_dir}\\{pdb}"]
                 compile_opts.extend(extra_compile_args)
             else:
index 50cc8520f2ce3fa65a7d7d180e11b518478016dc..0e85b844ef152b7c89f5a65a659cc2a59e3ba920 100644 (file)
@@ -116,7 +116,7 @@ def generate_parser_c_extension(
 def print_memstats() -> bool:
     MiB: Final = 2**20
     try:
-        import psutil  # type: ignore[import]
+        import psutil
     except ImportError:
         return False
     print("Memory stats:")
index b814169974bd08f4db556452af9e6e07bea564f9..49f783c096f2d2b627bf859ecaee02423d1c66cc 100644 (file)
@@ -1,3 +1,7 @@
 # Requirements file for external linters and checks we run on
 # Tools/clinic, Tools/cases_generator/, and Tools/peg_generator/ in CI
 mypy==1.5.1
+
+# needed for peg_generator:
+types-psutil==5.9.5.16
+types-setuptools==68.1.0.0