Skip to content

Commit c9346f3

Browse files
authored
Add stubs for PyInstaller (public API only) (#8702)
1 parent 8e718d4 commit c9346f3

21 files changed

+504
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# fake module, only exists once the app is frozen
2+
pyi_splash
3+
# Undocumented and clearly not meant to be exposed
4+
PyInstaller.__main__.generate_parser
5+
PyInstaller.__main__.run_build
6+
PyInstaller.__main__.run_makespec
7+
PyInstaller.utils.hooks.conda.lib_dir
8+
# A mix of modules meant to be private, and shallow incomplete type references for other modules
9+
PyInstaller.building.*
10+
PyInstaller.depend.analysis.*
11+
PyInstaller.isolated._parent.*
12+
# Most modules are not meant to be used, yet are not marked as private
13+
PyInstaller.archive.*
14+
PyInstaller.config
15+
PyInstaller.configure
16+
PyInstaller.depend.bindepend
17+
PyInstaller.depend.bytecode
18+
PyInstaller.depend.dylib
19+
PyInstaller.depend.imphook
20+
PyInstaller.depend.utils
21+
PyInstaller.exceptions
22+
PyInstaller.hooks.*
23+
PyInstaller.lib.*
24+
PyInstaller.loader.*
25+
PyInstaller.log
26+
PyInstaller.utils.cliutils.*
27+
PyInstaller.utils.conftest
28+
PyInstaller.utils.git
29+
PyInstaller.utils.hooks.django
30+
PyInstaller.utils.hooks.gi
31+
PyInstaller.utils.hooks.qt
32+
PyInstaller.utils.hooks.subproc.*
33+
PyInstaller.utils.hooks.tcl_tk
34+
PyInstaller.utils.misc
35+
PyInstaller.utils.osx
36+
PyInstaller.utils.run_tests
37+
PyInstaller.utils.tests
38+
PyInstaller.utils.win32.*
39+
# Explicitly private implementation details
40+
PyInstaller\._.*
41+
PyInstaller.isolated._child
42+
PyInstaller.utils._gitrevision

stubs/pyinstaller/METADATA.toml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
version = "5.4.*"
2+
requires = ["types-setuptools"]
3+
4+
[tool.stubtest]
5+
ignore_missing_stub = false
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from typing_extensions import LiteralString
2+
3+
from PyInstaller import compat as compat
4+
5+
__all__ = ("HOMEPATH", "PLATFORM", "__version__", "DEFAULT_DISTPATH", "DEFAULT_SPECPATH", "DEFAULT_WORKPATH")
6+
__version__: str
7+
HOMEPATH: str
8+
DEFAULT_SPECPATH: str
9+
DEFAULT_DISTPATH: str
10+
DEFAULT_WORKPATH: str
11+
PLATFORM: LiteralString
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# https://pyinstaller.org/en/stable/usage.html#running-pyinstaller-from-python-code
2+
from _typeshed import SupportsKeysAndGetItem
3+
from collections.abc import Iterable
4+
from typing_extensions import TypeAlias
5+
6+
# Used to update PyInstaller.config.CONF
7+
_PyIConfig: TypeAlias = (
8+
SupportsKeysAndGetItem[str, bool | str | list[str] | None] | Iterable[tuple[str, bool | str | list[str] | None]]
9+
)
10+
11+
def run(pyi_args: Iterable[str] | None = ..., pyi_config: _PyIConfig | None = ...) -> None: ...

stubs/pyinstaller/PyInstaller/building/__init__.pyi

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Referenced in: https://pyinstaller.org/en/stable/hooks.html?highlight=get_hook_config#PyInstaller.utils.hooks.get_hook_config
2+
# Not to be imported during runtime, but is the type reference for hooks and analysis configuration
3+
4+
from _typeshed import StrOrBytesPath
5+
from collections.abc import Iterable
6+
from typing import Any
7+
8+
from PyInstaller.building.datastruct import Target
9+
10+
class Analysis(Target):
11+
# https://pyinstaller.org/en/stable/hooks-config.html#hook-configuration-options
12+
hooksconfig: dict[str, dict[str, object]]
13+
def __init__(
14+
self,
15+
scripts: Iterable[StrOrBytesPath],
16+
pathex=...,
17+
binaries=...,
18+
datas=...,
19+
hiddenimports=...,
20+
hookspath=...,
21+
hooksconfig: dict[str, dict[str, Any]] | None = ...,
22+
excludes=...,
23+
runtime_hooks=...,
24+
cipher=...,
25+
win_no_prefer_redirects: bool = ...,
26+
win_private_assemblies: bool = ...,
27+
noarchive: bool = ...,
28+
module_collection_mode=...,
29+
) -> None: ...
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# https://pyinstaller.org/en/stable/advanced-topics.html#the-toc-and-tree-classes
2+
from collections.abc import Iterable, Sequence
3+
from typing import ClassVar
4+
from typing_extensions import Literal, LiteralString, SupportsIndex, TypeAlias
5+
6+
_TypeCode: TypeAlias = Literal["DATA", "BINARY", "EXTENSION", "OPTION"]
7+
_TOCTuple: TypeAlias = tuple[str, str | None, _TypeCode | None]
8+
9+
class TOC(list[_TOCTuple]):
10+
filenames: set[str]
11+
def __init__(self, initlist: Iterable[_TOCTuple] | None = ...) -> None: ...
12+
def append(self, entry: _TOCTuple) -> None: ...
13+
def insert(self, pos: SupportsIndex, entry: _TOCTuple) -> None: ...
14+
def extend(self, other: Iterable[_TOCTuple]) -> None: ...
15+
16+
class Target:
17+
invcnum: ClassVar[int]
18+
tocfilename: LiteralString
19+
tocbasename: LiteralString
20+
dependencies: TOC
21+
22+
class Tree(Target, TOC):
23+
root: str | None
24+
prefix: str | None
25+
excludes: Sequence[str]
26+
typecode: _TypeCode
27+
def __init__(
28+
self, root: str | None = ..., prefix: str | None = ..., excludes: Sequence[str] | None = ..., typecode: _TypeCode = ...
29+
) -> None: ...
30+
def assemble(self) -> None: ...
+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# https://pyinstaller.org/en/stable/hooks.html#module-PyInstaller.compat
2+
from _typeshed import FileDescriptor, GenericPath, StrOrBytesPath
3+
from collections.abc import Iterable
4+
from importlib.abc import _Path
5+
from types import ModuleType
6+
from typing import AnyStr, overload
7+
from typing_extensions import Literal, TypeAlias
8+
9+
_OpenFile: TypeAlias = StrOrBytesPath | FileDescriptor
10+
11+
is_64bits: bool
12+
is_py35: bool
13+
is_py36: bool
14+
is_py37: bool
15+
is_py38: bool
16+
is_py39: bool
17+
is_py310: bool
18+
is_win: bool
19+
is_win_10: bool
20+
is_win_wine: bool
21+
is_cygwin: bool
22+
is_darwin: bool
23+
is_linux: bool
24+
is_solar: bool
25+
is_aix: bool
26+
is_freebsd: bool
27+
is_openbsd: bool
28+
is_hpux: bool
29+
is_unix: bool
30+
is_musl: bool
31+
is_macos_11_compat: bool
32+
is_macos_11_native: bool
33+
is_macos_11: bool
34+
PYDYLIB_NAMES: set[str]
35+
base_prefix: str
36+
is_venv: bool
37+
is_virtualenv: bool
38+
is_conda: bool
39+
is_pure_conda: bool
40+
python_executable: str
41+
is_ms_app_store: bool
42+
BYTECODE_MAGIC: bytes
43+
EXTENSION_SUFFIXES: list[str]
44+
ALL_SUFFIXES: list[str]
45+
46+
architecture: Literal["64bit", "n32bit", "32bit"]
47+
system: Literal["Cygwin", "Linux", "Darwin", "Java", "Windows"]
48+
machine: Literal["sw_64", "loongarch64", "arm", "intel", "ppc", "mips", "riscv", "s390x", "unknown", None]
49+
50+
def is_wine_dll(filename: _OpenFile) -> bool: ...
51+
@overload
52+
def getenv(name: str, default: str) -> str: ...
53+
@overload
54+
def getenv(name: str, default: None = ...) -> str | None: ...
55+
def setenv(name: str, value: str) -> None: ...
56+
def unsetenv(name: str) -> None: ...
57+
def exec_command(
58+
*cmdargs: str, encoding: str | None = ..., raise_enoent: bool | None = ..., **kwargs: int | bool | Iterable[int] | None
59+
) -> str: ...
60+
def exec_command_rc(*cmdargs: str, **kwargs: float | bool | Iterable[int] | None) -> int: ...
61+
def exec_command_stdout(
62+
*command_args: str, encoding: str | None = ..., **kwargs: float | str | bytes | bool | Iterable[int] | None
63+
) -> str: ...
64+
def exec_command_all(
65+
*cmdargs: str, encoding: str | None = ..., **kwargs: int | bool | Iterable[int] | None
66+
) -> tuple[int, str, str]: ...
67+
def exec_python(*args: str, **kwargs: str | None) -> str: ...
68+
def exec_python_rc(*args: str, **kwargs: str | None) -> int: ...
69+
def expand_path(path: GenericPath[AnyStr]) -> AnyStr: ...
70+
def getsitepackages(prefixes: Iterable[str] | None = ...) -> list[str]: ...
71+
def importlib_load_source(name: str, pathname: _Path) -> ModuleType: ...
72+
73+
PY3_BASE_MODULES: set[str]
74+
PURE_PYTHON_MODULE_TYPES: set[str]
75+
SPECIAL_MODULE_TYPES: set[str]
76+
BINARY_MODULE_TYPES: set[str]
77+
VALID_MODULE_TYPES: set[str]
78+
BAD_MODULE_TYPES: set[str]
79+
ALL_MODULE_TYPES: set[str]
80+
MODULE_TYPES_TO_TOC_DICT: dict[str, str]
81+
82+
def check_requirements() -> None: ...

stubs/pyinstaller/PyInstaller/depend/__init__.pyi

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# https://pyinstaller.org/en/stable/hooks.html#the-pre-safe-import-module-psim-api-method
2+
3+
# The documentation explicitely mentions that "Normally you do not need to know about the module-graph."
4+
# However, some PyiModuleGraph typed class attributes are still documented as existing in imphookapi.
5+
from _typeshed import Incomplete
6+
7+
class PyiModuleGraph: # incomplete
8+
def __init__(
9+
self,
10+
pyi_homepath: str,
11+
user_hook_dirs=...,
12+
excludes=...,
13+
path: Incomplete | None = ...,
14+
replace_paths=...,
15+
implies=...,
16+
graph: Incomplete | None = ...,
17+
debug: int = ...,
18+
) -> None: ...
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# https://pyinstaller.org/en/stable/hooks-config.html#adding-an-option-to-the-hook `hook_api` is a PostGraphAPI
2+
# Nothing in this module is meant to be initialized externally.
3+
# Instances are exposed through hooks during build.
4+
5+
from _typeshed import StrOrBytesPath
6+
from collections.abc import Generator, Iterable
7+
from typing import Any
8+
from typing_extensions import Literal
9+
10+
from PyInstaller.building.build_main import Analysis
11+
from PyInstaller.building.datastruct import TOC
12+
from PyInstaller.depend.analysis import PyiModuleGraph
13+
from PyInstaller.lib.modulegraph.modulegraph import Package
14+
15+
# https://pyinstaller.org/en/stable/hooks.html#the-pre-safe-import-module-psim-api-method
16+
class PreSafeImportModuleAPI:
17+
module_basename: str
18+
module_name: str
19+
def __init__(
20+
self, module_graph: PyiModuleGraph, module_basename: str, module_name: str, parent_package: Package | None
21+
) -> None: ...
22+
@property
23+
def module_graph(self) -> PyiModuleGraph: ...
24+
@property
25+
def parent_package(self) -> Package | None: ...
26+
def add_runtime_module(self, module_name: str) -> None: ...
27+
def add_runtime_package(self, package_name: str) -> None: ...
28+
def add_alias_module(self, real_module_name: str, alias_module_name: str) -> None: ...
29+
def append_package_path(self, directory: str) -> None: ...
30+
31+
# https://pyinstaller.org/en/stable/hooks.html#the-pre-find-module-path-pfmp-api-method
32+
class PreFindModulePathAPI:
33+
search_dirs: Iterable[StrOrBytesPath]
34+
def __init__(self, module_graph: PyiModuleGraph, module_name: str, search_dirs: Iterable[StrOrBytesPath]) -> None: ...
35+
@property
36+
def module_graph(self) -> PyiModuleGraph: ...
37+
@property
38+
def module_name(self) -> str: ...
39+
40+
# https://pyinstaller.org/en/stable/hooks.html#the-hook-hook-api-function
41+
class PostGraphAPI:
42+
module_graph: PyiModuleGraph
43+
module: Package
44+
def __init__(self, module_name: str, module_graph: PyiModuleGraph, analysis: Analysis) -> None: ...
45+
@property
46+
def __file__(self) -> str: ...
47+
@property
48+
def __path__(self) -> tuple[str, ...] | None: ...
49+
@property
50+
def __name__(self) -> str: ...
51+
# Compiled code. See stdlib.builtins.compile
52+
@property
53+
def co(self) -> Any: ...
54+
@property
55+
def analysis(self) -> Analysis: ...
56+
@property
57+
def name(self) -> str: ...
58+
@property
59+
def graph(self) -> PyiModuleGraph: ...
60+
@property
61+
def node(self) -> Package: ...
62+
@property
63+
def imports(self) -> Generator[Package, None, None]: ...
64+
def add_imports(self, *module_names: str) -> None: ...
65+
def del_imports(self, *module_names: str) -> None: ...
66+
def add_binaries(self, list_of_tuples: TOC | Iterable[tuple[StrOrBytesPath, StrOrBytesPath]]) -> None: ...
67+
def add_datas(self, list_of_tuples: TOC | Iterable[tuple[StrOrBytesPath, StrOrBytesPath]]) -> None: ...
68+
def set_module_collection_mode(
69+
self, name: str | None, mode: Literal["pyz", "pyc", "py", "pyz+py", "py+pyz", None]
70+
) -> None: ...
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# https://pyinstaller.org/en/stable/hooks.html#module-PyInstaller.isolated
2+
from PyInstaller.isolated._parent import Python as Python, call as call, decorate as decorate
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from _typeshed import Self
2+
from collections.abc import Callable
3+
from types import TracebackType
4+
from typing import TypeVar
5+
from typing_extensions import ParamSpec
6+
7+
_AC = TypeVar("_AC", bound=Callable[..., object])
8+
_R = TypeVar("_R")
9+
_P = ParamSpec("_P")
10+
11+
class Python:
12+
def __enter__(self: Self) -> Self: ...
13+
def __exit__(
14+
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
15+
) -> None: ...
16+
def call(self, function: Callable[_P, _R], *args: _P.args, **kwargs: _P.kwargs) -> _R: ...
17+
18+
def call(function: Callable[_P, _R], *args: _P.args, **kwargs: _P.kwargs) -> _R: ...
19+
def decorate(function: _AC) -> _AC: ...

stubs/pyinstaller/PyInstaller/lib/__init__.pyi

Whitespace-only changes.

stubs/pyinstaller/PyInstaller/lib/modulegraph/__init__.pyi

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from typing import Any, Protocol
2+
3+
class _SupportsGraphident(Protocol):
4+
graphident: str
5+
6+
# TODO: For typing purposes, once #5768 is complete, it'll be easier to use the modulegraph package directly.
7+
8+
# code, filename and packagepath are always initialized to None. But they can be given a value later.
9+
class Node:
10+
# Compiled code. See stdlib.builtins.compile
11+
code: Any | None
12+
filename: str | None
13+
graphident: str
14+
identifier: str
15+
packagepath: str | None
16+
def __init__(self, identifier: str) -> None: ...
17+
def is_global_attr(self, attr_name: str) -> bool: ...
18+
def is_submodule(self, submodule_basename: str) -> bool: ...
19+
def add_global_attr(self, attr_name: str) -> None: ...
20+
def add_global_attrs_from_module(self, target_module: Node) -> None: ...
21+
def add_submodule(self, submodule_basename: str, submodule_node: Node) -> None: ...
22+
def get_submodule(self, submodule_basename: str) -> Node: ...
23+
def get_submodule_or_none(self, submodule_basename: str) -> Node | None: ...
24+
def remove_global_attr_if_found(self, attr_name: str) -> None: ...
25+
def __eq__(self, other: object) -> bool: ...
26+
def __ne__(self, other: object) -> bool: ...
27+
def __lt__(self, other: _SupportsGraphident) -> bool: ...
28+
def __le__(self, other: _SupportsGraphident) -> bool: ...
29+
def __gt__(self, other: _SupportsGraphident) -> bool: ...
30+
def __ge__(self, other: _SupportsGraphident) -> bool: ...
31+
def infoTuple(self) -> tuple[str]: ...
32+
33+
class BaseModule(Node):
34+
filename: str
35+
packagepath: str
36+
def __init__(self, name: str, filename: str | None = ..., path: str | None = ...) -> None: ...
37+
# Returns a tuple of length 0, 1, 2, or 3
38+
def infoTuple(self) -> tuple[str, ...]: ... # type: ignore[override]
39+
40+
class Package(BaseModule): ...

stubs/pyinstaller/PyInstaller/utils/__init__.pyi

Whitespace-only changes.

0 commit comments

Comments
 (0)