Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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