Skip to content

Commit 4930eba

Browse files
AvasamAlexWaygood
andauthored
Type PyInstaller.building.api and related modules (#9730)
Co-authored-by: Alex Waygood <[email protected]>
1 parent 01972e0 commit 4930eba

File tree

12 files changed

+423
-16
lines changed

12 files changed

+423
-16
lines changed

stubs/pyinstaller/@tests/stubtest_allowlist.txt

+7-3
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@
22
pyi_splash
33

44
# Undocumented and clearly not meant to be exposed
5+
PyInstaller\..+?\.logger
56
PyInstaller.__main__.generate_parser
67
PyInstaller.__main__.run_build
78
PyInstaller.__main__.run_makespec
89
PyInstaller.utils.hooks.conda.lib_dir
910

1011
# A mix of modules meant to be private, and shallow incomplete type references for other modules
11-
PyInstaller.building.*
12+
PyInstaller\.building\.\w+?
13+
PyInstaller.building.build_main.*
14+
PyInstaller.building.datastruct.unique_name
1215
PyInstaller.depend.analysis.*
1316
PyInstaller.isolated._parent.*
17+
PyInstaller\.lib\.modulegraph\.modulegraph\.\w+?
1418

1519
# Most modules are not meant to be used, yet are not marked as private
1620
PyInstaller.archive.*
@@ -23,7 +27,7 @@ PyInstaller.depend.imphook
2327
PyInstaller.depend.utils
2428
PyInstaller.exceptions
2529
PyInstaller.hooks.*
26-
PyInstaller.lib.*
30+
PyInstaller\.lib\.modulegraph\.\w+?
2731
PyInstaller.loader.*
2832
PyInstaller.log
2933
PyInstaller.utils.cliutils.*
@@ -37,4 +41,4 @@ PyInstaller.utils.misc
3741
PyInstaller.utils.osx
3842
PyInstaller.utils.run_tests
3943
PyInstaller.utils.tests
40-
PyInstaller.utils.win32.*
44+
PyInstaller\.utils\.win32\.\w+?
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
PyInstaller\.utils\.win32\.versioninfo\.\w+?
2+
PyInstaller\.utils\.win32\.winmanifest\.\w+?
+1-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# https://pyinstaller.org/en/stable/usage.html#running-pyinstaller-from-python-code
2-
import logging
31
from _typeshed import SupportsKeysAndGetItem
42
from collections.abc import Iterable
53
from typing_extensions import TypeAlias
@@ -9,6 +7,5 @@ _PyIConfig: TypeAlias = (
97
SupportsKeysAndGetItem[str, bool | str | list[str] | None] | Iterable[tuple[str, bool | str | list[str] | None]]
108
)
119

12-
logger: logging.Logger
13-
10+
# https://pyinstaller.org/en/stable/usage.html#running-pyinstaller-from-python-code
1411
def run(pyi_args: Iterable[str] | None = None, pyi_config: _PyIConfig | None = None) -> None: ...
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from typing_extensions import TypeAlias
2+
3+
# PyiBlockCipher is deprecated and misleads users into thinking it adds any security. Runtime deprecation warning:
4+
# DEPRECATION: Bytecode encryption will be removed in PyInstaller v6.
5+
# Please remove cipher and block_cipher parameters from your spec file to avoid breakages on upgrade.
6+
# For the rationale/alternatives see https://github.com/pyinstaller/pyinstaller/pull/6999
7+
_PyiBlockCipher: TypeAlias = None # noqa: Y047 # Used by other modules
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
# PYZ, EXE and COLLECT referenced in https://pyinstaller.org/en/stable/spec-files.html#spec-file-operation
2+
# MERGE is referenced in https://pyinstaller.org/en/stable/spec-files.html#example-merge-spec-file
3+
# Not to be imported during runtime, but is the type reference for spec files which are executed as python code
4+
import sys
5+
from _typeshed import FileDescriptorOrPath, StrOrBytesPath, StrPath, Unused
6+
from collections.abc import Iterable, Mapping, Sequence
7+
from types import CodeType
8+
from typing import ClassVar
9+
from typing_extensions import Final, Literal, TypeAlias
10+
11+
from PyInstaller.building import _PyiBlockCipher
12+
from PyInstaller.building.build_main import Analysis
13+
from PyInstaller.building.datastruct import TOC, Target, _TOCTuple
14+
from PyInstaller.building.splash import Splash
15+
from PyInstaller.utils.win32.versioninfo import VSVersionInfo
16+
from PyInstaller.utils.win32.winmanifest import Manifest
17+
18+
if sys.platform == "darwin":
19+
_TargetArch: TypeAlias = Literal["x86_64", "arm64", "universal2"]
20+
_SuportedTargetArchParam: TypeAlias = _TargetArch | None
21+
_CodesignIdentity: TypeAlias = str | None
22+
_CodesignIdentityParam: TypeAlias = str | None
23+
else:
24+
_TargetArch: TypeAlias = None
25+
_SuportedTargetArchParam: TypeAlias = object
26+
_CodesignIdentity: TypeAlias = None
27+
_CodesignIdentityParam: TypeAlias = object
28+
29+
if sys.platform == "win32":
30+
_Icon: TypeAlias = list[StrPath] | str
31+
_IconParam: TypeAlias = StrPath | list[StrPath] | None
32+
elif sys.platform == "darwin":
33+
_Icon: TypeAlias = list[StrPath] | None
34+
_IconParam: TypeAlias = StrPath | list[StrPath] | None
35+
else:
36+
_Icon: TypeAlias = None
37+
_IconParam: TypeAlias = object
38+
39+
if sys.platform == "win32":
40+
_VersionSrc: TypeAlias = VSVersionInfo | None
41+
_VersionParam: TypeAlias = VSVersionInfo | StrOrBytesPath | None
42+
_Manifest: TypeAlias = Manifest
43+
_ManifestParam: TypeAlias = Manifest | None
44+
else:
45+
_VersionSrc: TypeAlias = None
46+
_VersionParam: TypeAlias = object
47+
_Manifest: TypeAlias = None
48+
_ManifestParam: TypeAlias = object
49+
50+
class PYZ(Target):
51+
name: str
52+
cipher: _PyiBlockCipher
53+
dependencies: list[_TOCTuple] # type: ignore[assignment]
54+
toc: TOC
55+
code_dict: dict[str, CodeType]
56+
def __init__(self, *tocs: TOC, name: str | None = None, cipher: _PyiBlockCipher = None) -> None: ...
57+
def assemble(self) -> None: ...
58+
59+
class PKG(Target):
60+
xformdict: ClassVar[dict[str, str]]
61+
toc: TOC
62+
cdict: Mapping[str, bool]
63+
name: str
64+
exclude_binaries: bool
65+
strip_binaries: bool
66+
upx_binaries: bool
67+
upx_exclude: Iterable[str]
68+
target_arch: _TargetArch | None
69+
codesign_identity: _CodesignIdentity
70+
entitlements_file: FileDescriptorOrPath | None
71+
def __init__(
72+
self,
73+
toc: TOC,
74+
name: str | None = None,
75+
cdict: Mapping[str, bool] | None = None,
76+
exclude_binaries: bool = False,
77+
strip_binaries: bool = False,
78+
upx_binaries: bool = False,
79+
upx_exclude: Iterable[str] | None = None,
80+
target_arch: _SuportedTargetArchParam = None,
81+
codesign_identity: _CodesignIdentityParam = None,
82+
entitlements_file: FileDescriptorOrPath | None = None,
83+
) -> None: ...
84+
def assemble(self) -> None: ...
85+
86+
class EXE(Target):
87+
exclude_binaries: bool
88+
bootloader_ignore_signals: bool
89+
console: bool
90+
disable_windowed_traceback: bool
91+
debug: bool
92+
name: str
93+
icon: _Icon
94+
versrsrc: _VersionSrc
95+
manifest: _Manifest
96+
embed_manifest: bool
97+
resources: Sequence[str]
98+
strip: bool
99+
upx_exclude: Iterable[str]
100+
runtime_tmpdir: str | None
101+
append_pkg: bool
102+
uac_admin: bool
103+
uac_uiaccess: bool
104+
argv_emulation: bool
105+
target_arch: _TargetArch
106+
codesign_identity: _CodesignIdentity
107+
entitlements_file: FileDescriptorOrPath | None
108+
upx: bool
109+
pkgname: str
110+
toc: TOC
111+
pkg: PKG
112+
dependencies: TOC
113+
exefiles: TOC
114+
def __init__(
115+
self,
116+
*args: Iterable[_TOCTuple] | PYZ | Splash,
117+
exclude_binaries: bool = False,
118+
bootloader_ignore_signals: bool = False,
119+
console: bool = True,
120+
disable_windowed_traceback: bool = False,
121+
debug: bool = False,
122+
name: str | None = None,
123+
icon: _IconParam = None,
124+
version: _VersionParam = None,
125+
manifest: _ManifestParam = None,
126+
embed_manifest: bool = True,
127+
resources: Sequence[str] = ...,
128+
strip: bool = False,
129+
upx_exclude: Iterable[str] = ...,
130+
runtime_tmpdir: str | None = None,
131+
append_pkg: bool = True,
132+
uac_admin: bool = False,
133+
uac_uiaccess: bool = False,
134+
argv_emulation: bool = False,
135+
target_arch: _SuportedTargetArchParam = None,
136+
codesign_identity: _CodesignIdentityParam = None,
137+
entitlements_file: FileDescriptorOrPath | None = None,
138+
upx: bool = False,
139+
cdict: Mapping[str, bool] | None = None,
140+
) -> None: ...
141+
mtm: float
142+
def assemble(self) -> None: ...
143+
144+
class COLLECT(Target):
145+
strip_binaries: bool
146+
upx_exclude: Iterable[str]
147+
console: bool
148+
target_arch: _TargetArch | None
149+
codesign_identity: _CodesignIdentity
150+
entitlements_file: FileDescriptorOrPath | None
151+
upx_binaries: bool
152+
name: str
153+
toc: TOC
154+
def __init__(
155+
self,
156+
*args: Iterable[_TOCTuple] | EXE,
157+
strip: bool = False,
158+
upx_exclude: Iterable[str] = ...,
159+
upx: bool = False,
160+
name: str,
161+
) -> None: ...
162+
def assemble(self) -> None: ...
163+
164+
class MERGE:
165+
def __init__(self, *args: tuple[Analysis, Unused, str]) -> None: ...
166+
167+
UNCOMPRESSED: Final = False
168+
COMPRESSED: Final = True

stubs/pyinstaller/PyInstaller/building/build_main.pyi

+18-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
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-
41
from _typeshed import Incomplete, StrPath
52
from collections.abc import Iterable
63
from typing import Any
74

8-
from PyInstaller.building.datastruct import Target
5+
from PyInstaller.building import _PyiBlockCipher
6+
from PyInstaller.building.datastruct import TOC, Target
97

8+
# Referenced in: https://pyinstaller.org/en/stable/hooks.html#PyInstaller.utils.hooks.get_hook_config
9+
# Not to be imported during runtime, but is the type reference for hooks and analysis configuration
10+
# Also referenced in https://pyinstaller.org/en/stable/spec-files.html
11+
# Not to be imported during runtime, but is the type reference for spec files which are executed as python code
1012
class Analysis(Target):
1113
# https://pyinstaller.org/en/stable/hooks-config.html#hook-configuration-options
1214
hooksconfig: dict[str, dict[str, object]]
15+
# https://pyinstaller.org/en/stable/spec-files.html#spec-file-operation
16+
# https://pyinstaller.org/en/stable/feature-notes.html
17+
pure: TOC
18+
zipped_data: TOC
19+
# https://pyinstaller.org/en/stable/spec-files.html#giving-run-time-python-options
20+
# https://pyinstaller.org/en/stable/spec-files.html#the-splash-target
21+
scripts: TOC
22+
# https://pyinstaller.org/en/stable/feature-notes.html#practical-examples
23+
binaries: TOC
24+
zipfiles: TOC
25+
datas: TOC
1326
def __init__(
1427
self,
1528
scripts: Iterable[StrPath],
@@ -21,7 +34,7 @@ class Analysis(Target):
2134
hooksconfig: dict[str, dict[str, Any]] | None = None,
2235
excludes: Incomplete | None = None,
2336
runtime_hooks: Incomplete | None = None,
24-
cipher: Incomplete | None = None,
37+
cipher: _PyiBlockCipher = None,
2538
win_no_prefer_redirects: bool = False,
2639
win_private_assemblies: bool = False,
2740
noarchive: bool = False,

stubs/pyinstaller/PyInstaller/building/datastruct.pyi

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# https://pyinstaller.org/en/stable/advanced-topics.html#the-toc-and-tree-classes
22
from collections.abc import Iterable, Sequence
33
from typing import ClassVar
4-
from typing_extensions import Literal, LiteralString, SupportsIndex, TypeAlias
4+
from typing_extensions import Literal, LiteralString, Self, SupportsIndex, TypeAlias
55

66
_TypeCode: TypeAlias = Literal["DATA", "BINARY", "EXTENSION", "OPTION"]
77
_TOCTuple: TypeAlias = tuple[str, str | None, _TypeCode | None]
@@ -11,13 +11,22 @@ class TOC(list[_TOCTuple]):
1111
def __init__(self, initlist: Iterable[_TOCTuple] | None = None) -> None: ...
1212
def append(self, entry: _TOCTuple) -> None: ...
1313
def insert(self, pos: SupportsIndex, entry: _TOCTuple) -> None: ...
14+
def __add__(self, other: Iterable[_TOCTuple]) -> TOC: ... # type: ignore[override]
15+
def __radd__(self, other: Iterable[_TOCTuple]) -> TOC: ...
16+
def __iadd__(self, other: Iterable[_TOCTuple]) -> Self: ... # type: ignore[override]
1417
def extend(self, other: Iterable[_TOCTuple]) -> None: ...
18+
def __sub__(self, other: Iterable[_TOCTuple]) -> TOC: ...
19+
def __rsub__(self, other: Iterable[_TOCTuple]) -> TOC: ...
20+
# slicing a TOC is not supported, but has a special case for slice(None, None, None)
21+
def __setitem__(self, key: int | slice, value: Iterable[_TOCTuple]) -> None: ... # type: ignore[override]
1522

1623
class Target:
1724
invcnum: ClassVar[int]
1825
tocfilename: LiteralString
1926
tocbasename: LiteralString
2027
dependencies: TOC
28+
def __init__(self) -> None: ...
29+
def __postinit__(self) -> None: ...
2130

2231
class Tree(Target, TOC):
2332
root: str | None
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from _typeshed import Incomplete, StrPath
2+
from collections.abc import Iterable
3+
4+
from PyInstaller.building.datastruct import TOC, Target, _TOCTuple
5+
6+
splash_requirements: list[str]
7+
8+
# Referenced in https://pyinstaller.org/en/stable/spec-files.html#example-merge-spec-file
9+
# Not to be imported during runtime, but is the type reference for spec files which are executed as python code
10+
class Splash(Target):
11+
image_file: str
12+
full_tk: Incomplete
13+
name: Incomplete
14+
script_name: Incomplete
15+
minify_script: Incomplete
16+
rundir: Incomplete
17+
max_img_size: Incomplete
18+
text_pos: Incomplete
19+
text_size: Incomplete
20+
text_font: Incomplete
21+
text_color: Incomplete
22+
text_default: Incomplete
23+
always_on_top: Incomplete
24+
uses_tkinter: Incomplete
25+
script: Incomplete
26+
splash_requirements: Incomplete
27+
binaries: TOC
28+
def __init__(self, image_file: StrPath, binaries: TOC, datas: Iterable[_TOCTuple], **kwargs: Incomplete) -> None: ...
29+
def assemble(self) -> None: ...
30+
def test_tk_version(self) -> None: ...
31+
def generate_script(self) -> str: ...

stubs/pyinstaller/PyInstaller/utils/hooks/__init__.pyi

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# https://pyinstaller.org/en/stable/hooks.html
22

3-
import logging
43
from _typeshed import StrOrBytesPath, StrPath
54
from collections.abc import Callable, Iterable
65
from typing import Any
@@ -14,7 +13,6 @@ from PyInstaller.utils.hooks.win32 import get_pywin32_module_file_attribute as g
1413

1514
conda_support = conda
1615

17-
logger: logging.Logger
1816
PY_IGNORE_EXTENSIONS: Final[set[str]]
1917
hook_variables: dict[str, str]
2018

stubs/pyinstaller/PyInstaller/utils/hooks/conda.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# https://pyinstaller.org/en/stable/hooks.html?highlight=conda_support#module-PyInstaller.utils.hooks.conda
1+
# https://pyinstaller.org/en/stable/hooks.html#module-PyInstaller.utils.hooks.conda
22

33
import sys
44
from _typeshed import StrOrBytesPath

0 commit comments

Comments
 (0)