gh-108455: peg_generator: install two stubs packages before running mypy (#108637)

This commit is contained in:
Alex Waygood 2023-08-29 20:14:08 +01:00 committed by GitHub
parent 8178a88bd8
commit 77e8f233ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 6 deletions

View 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

View 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:

View 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:")

View 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