1# IMPORTANT: Should stay in sync with setup_helpers.py (mostly checked by CI /
2# pre-commit).
3
4from typing import Any, Callable, Dict, Iterator, List, Optional, Type, TypeVar, Union
5from types import TracebackType
6
7from distutils.command.build_ext import build_ext as _build_ext  # type: ignore
8from distutils.extension import Extension as _Extension
9import distutils.ccompiler
10import contextlib
11
12WIN: bool
13PY2: bool
14MACOS: bool
15STD_TMPL: str
16
17class Pybind11Extension(_Extension):
18    def _add_cflags(self, *flags: str) -> None: ...
19    def _add_lflags(self, *flags: str) -> None: ...
20    def __init__(
21        self, *args: Any, cxx_std: int = 0, language: str = "c++", **kwargs: Any
22    ) -> None: ...
23    @property
24    def cxx_std(self) -> int: ...
25    @cxx_std.setter
26    def cxx_std(self, level: int) -> None: ...
27
28@contextlib.contextmanager
29def tmp_chdir() -> Iterator[str]: ...
30def has_flag(compiler: distutils.ccompiler.CCompiler, flag: str) -> bool: ...
31def auto_cpp_level(compiler: distutils.ccompiler.CCompiler) -> Union[int, str]: ...
32
33class build_ext(_build_ext):  # type: ignore
34    def build_extensions(self) -> None: ...
35
36def intree_extensions(
37    paths: Iterator[str], package_dir: Optional[Dict[str, str]] = None
38) -> List[Pybind11Extension]: ...
39def no_recompile(obj: str, src: str) -> bool: ...
40def naive_recompile(obj: str, src: str) -> bool: ...
41
42T = TypeVar("T", bound="ParallelCompile")
43
44class ParallelCompile:
45    envvar: Optional[str]
46    default: int
47    max: int
48    needs_recompile: Callable[[str, str], bool]
49    def __init__(
50        self,
51        envvar: Optional[str] = None,
52        default: int = 0,
53        max: int = 0,
54        needs_recompile: Callable[[str, str], bool] = no_recompile,
55    ) -> None: ...
56    def function(self) -> Any: ...
57    def install(self: T) -> T: ...
58    def __enter__(self: T) -> T: ...
59    def __exit__(
60        self,
61        exc_type: Optional[Type[BaseException]],
62        exc_value: Optional[BaseException],
63        traceback: Optional[TracebackType],
64    ) -> None: ...
65