Skip to content

Commit

Permalink
gh-108455: peg_generator: install two stubs packages before running m…
Browse files Browse the repository at this point in the history
…ypy (#108637)
  • Loading branch information
AlexWaygood committed Aug 29, 2023
1 parent 8178a88 commit 77e8f23
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
6 changes: 4 additions & 2 deletions Tools/peg_generator/mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 8 additions & 3 deletions Tools/peg_generator/pegen/build.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import itertools
import logging
import os
import pathlib
import sys
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion Tools/peg_generator/pegen/testutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:")
Expand Down
4 changes: 4 additions & 0 deletions Tools/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 77e8f23

Please sign in to comment.