zmc
2023-08-08 e792e9a60d958b93aef96050644f369feb25d61b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
U
W±d‰Pã@sNdZddlmZddlmZmZGdd„dƒZGdd„dƒZGdd    „d    ƒZd
S) aÐ
Classes facilitating communication between PyInstaller and import hooks.
 
PyInstaller passes instances of classes defined by this module to corresponding functions defined by external import
hooks, which commonly modify the contents of these instances before returning. PyInstaller then detects and converts
these modifications into appropriate operations on the current `PyiModuleGraph` instance, thus modifying which
modules will be frozen into the executable.
é)Úformat_binaries_and_datas)Ú RuntimeModuleÚRuntimePackagec@sPeZdZdZdd„Zedd„ƒZedd„ƒZdd    „Zd
d „Z    d d „Z
dd„Z dS)ÚPreSafeImportModuleAPIa*    
    Metadata communicating changes made by the current **pre-safe import module hook** (i.e., hook run immediately
    _before_ a call to `ModuleGraph._safe_import_module()` recursively adding the hooked module, package,
    or C extension and all transitive imports thereof to the module graph) back to PyInstaller.
 
    Pre-safe import module hooks _must_ define a `pre_safe_import_module()` function accepting an instance of this
    class, whose attributes describe the subsequent `ModuleGraph._safe_import_module()` call creating the hooked
    module's graph node.
 
    Each pre-safe import module hook is run _only_ on the first attempt to create the hooked module's graph node and
    then subsequently ignored. If this hook successfully creates that graph node, the subsequent
    `ModuleGraph._safe_import_module()` call will observe this fact and silently return without attempting to
    recreate that graph node.
 
    Pre-safe import module hooks are typically used to create graph nodes for **runtime modules** (i.e.,
    modules dynamically defined at runtime). Most modules are physically defined in external `.py`-suffixed scripts.
    Some modules, however, are dynamically defined at runtime (e.g., `six.moves`, dynamically defined by the
    physically defined `six.py` module). However, `ModuleGraph` only parses `import` statements residing in external
    scripts. `ModuleGraph` is _not_ a full-fledged, Turing-complete Python interpreter and hence has no means of
    parsing `import` statements performed by runtime modules existing only in-memory.
 
    'With great power comes great responsibility.'
 
 
    Attributes (Immutable)
    ----------------------------
    The following attributes are **immutable** (i.e., read-only). For safety, any attempts to change these attributes
    _will_ result in a raised exception:
 
    module_graph : PyiModuleGraph
        Current module graph.
    parent_package : Package
        Graph node for the package providing this module _or_ `None` if this module is a top-level module.
 
    Attributes (Mutable)
    -----------------------------
    The following attributes are editable.
 
    module_basename : str
        Unqualified name of the module to be imported (e.g., `text`).
    module_name : str
        Fully-qualified name of this module (e.g., `email.mime.text`).
    cCs||_||_||_||_dS©N)Ú _module_graphÚmodule_basenameÚ module_nameÚ_parent_package)ÚselfÚ module_graphrr    Úparent_package©rúTd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\PyInstaller/depend/imphookapi.pyÚ__init__DszPreSafeImportModuleAPI.__init__cCs|jS©z'
        Current module graph.
        ©r©r rrrr Ksz#PreSafeImportModuleAPI.module_graphcCs|jS)z.
        Parent Package of this node.
        )r
rrrrr Rsz%PreSafeImportModuleAPI.parent_packagecCs|j t|ƒ¡dS)as
        Add a graph node representing a non-package Python module with the passed name dynamically defined at runtime.
 
        Most modules are statically defined on-disk as standard Python files. Some modules, however, are dynamically
        defined in-memory at runtime (e.g., `gi.repository.Gst`, dynamically defined by the statically defined
        `gi.repository.__init__` module).
 
        This method adds a graph node representing such a runtime module. Since this module is _not_ a package,
        all attempts to import submodules from this module in `from`-style import statements (e.g., the `queue`
        submodule in `from six.moves import queue`) will be silently ignored. To circumvent this, simply call
        `add_runtime_package()` instead.
 
        Parameters
        ----------
        module_name : str
            Fully-qualified name of this module (e.g., `gi.repository.Gst`).
 
        Examples
        ----------
        This method is typically called by `pre_safe_import_module()` hooks, e.g.:
 
            def pre_safe_import_module(api):
                api.add_runtime_module(api.module_name)
        N)rÚ
add_moduler)r r    rrrÚadd_runtime_moduleYsz)PreSafeImportModuleAPI.add_runtime_modulecCs|j t|ƒ¡dS)a:
        Add a graph node representing a non-namespace Python package with the passed name dynamically defined at
        runtime.
 
        Most packages are statically defined on-disk as standard subdirectories containing `__init__.py` files. Some
        packages, however, are dynamically defined in-memory at runtime (e.g., `six.moves`, dynamically defined by
        the statically defined `six` module).
 
        This method adds a graph node representing such a runtime package. All attributes imported from this package
        in `from`-style import statements that are submodules of this package (e.g., the `queue` submodule in `from
        six.moves import queue`) will be imported rather than ignored.
 
        Parameters
        ----------
        package_name : str
            Fully-qualified name of this package (e.g., `six.moves`).
 
        Examples
        ----------
        This method is typically called by `pre_safe_import_module()` hooks, e.g.:
 
            def pre_safe_import_module(api):
                api.add_runtime_package(api.module_name)
        N)rrr)r Ú package_namerrrÚadd_runtime_packageusz*PreSafeImportModuleAPI.add_runtime_packagecCs|j ||¡dS)a’
        Alias the source module to the target module with the passed names.
 
        This method ensures that the next call to findNode() given the target module name will resolve this alias.
        This includes importing and adding a graph node for the source module if needed as well as adding a reference
        from the target to the source module.
 
        Parameters
        ----------
        real_module_name : str
            Fully-qualified name of the **existing module** (i.e., the module being aliased).
        alias_module_name : str
            Fully-qualified name of the **non-existent module** (i.e., the alias to be created).
        N)rZ alias_module)r Zreal_module_nameZalias_module_namerrrÚadd_alias_module‘sz'PreSafeImportModuleAPI.add_alias_modulecCs|j |j|¡dS)aÖ
        Modulegraph does a good job at simulating Python's, but it cannot handle packagepath `__path__` modifications
        packages make at runtime.
 
        Therefore there is a mechanism whereby you can register extra paths in this map for a package, and it will be
        honored.
 
        Parameters
        ----------
        directory : str
            Absolute or relative path of the directory to be appended to this package's `__path__` attribute.
        N)rÚappend_package_pathr    )r Ú    directoryrrrr£sz*PreSafeImportModuleAPI.append_package_pathN) Ú__name__Ú
__module__Ú __qualname__Ú__doc__rÚpropertyr r rrrrrrrrrs+
 
rc@s0eZdZdZdd„Zedd„ƒZedd„ƒZdS)    ÚPreFindModulePathAPIa
    Metadata communicating changes made by the current **pre-find module path hook** (i.e., hook run immediately
    _before_ a call to `ModuleGraph._find_module_path()` finding the hooked module's absolute path) back to PyInstaller.
 
    Pre-find module path hooks _must_ define a `pre_find_module_path()` function accepting an instance of this class,
    whose attributes describe the subsequent `ModuleGraph._find_module_path()` call to be performed.
 
    Pre-find module path hooks are typically used to change the absolute path from which a module will be
    subsequently imported and thus frozen into the executable. To do so, hooks may overwrite the default
    `search_dirs` list of the absolute paths of all directories to be searched for that module: e.g.,
 
        def pre_find_module_path(api):
            api.search_dirs = ['/the/one/true/package/providing/this/module']
 
    Each pre-find module path hook is run _only_ on the first call to `ModuleGraph._find_module_path()` for the
    corresponding module.
 
    Attributes
    ----------
    The following attributes are **mutable** (i.e., modifiable). All changes to these attributes will be immediately
    respected by PyInstaller:
 
    search_dirs : list
        List of the absolute paths of all directories to be searched for this module (in order). Searching will halt
        at the first directory containing this module.
 
    Attributes (Immutable)
    ----------
    The following attributes are **immutable** (i.e., read-only). For safety, any attempts to change these attributes
    _will_ result in a raised exception:
 
    module_name : str
        Fully-qualified name of this module.
    module_graph : PyiModuleGraph
        Current module graph. For efficiency, this attribute is technically mutable. To preserve graph integrity,
        this attribute should nonetheless _never_ be modified. While read-only `PyiModuleGraph` methods (e.g.,
        `findNode()`) are safely callable from within pre-find module path hooks, methods modifying the graph are
        _not_. If graph modifications are required, consider an alternative type of hook (e.g., pre-import module
        hooks).
    cCs||_||_||_dSr)Ú search_dirsrÚ _module_name)r r r    r!rrrrÝszPreFindModulePathAPI.__init__cCs|jSrrrrrrr ësz!PreFindModulePathAPI.module_graphcCs|jS)z6
        Fully-qualified name of this module.
        )r"rrrrr    òsz PreFindModulePathAPI.module_nameN)rrrrrrr r    rrrrr ´s (
r c@s¬eZdZdZdd„Zedd„ƒZedd„ƒZedd    „ƒZed
d „ƒZed d „ƒZ    edd„ƒZ
edd„ƒZ edd„ƒZ edd„ƒZ dd„Zdd„Zdd„Zdd„Zdd„Zd S)!Ú PostGraphAPIa€
    Metadata communicating changes made by the current **post-graph hook** (i.e., hook run for a specific module
    transitively imported by the current application _after_ the module graph of all `import` statements performed by
    this application has been constructed) back to PyInstaller.
 
    Post-graph hooks may optionally define a `post_graph()` function accepting an instance of this class,
    whose attributes describe the current state of the module graph and the hooked module's graph node.
 
    Attributes (Mutable)
    ----------
    The following attributes are **mutable** (i.e., modifiable). All changes to these attributes will be immediately
    respected by PyInstaller:
 
    module_graph : PyiModuleGraph
        Current module graph.
    module : Node
        Graph node for the currently hooked module.
 
    'With great power comes great responsibility.'
 
    Attributes (Immutable)
    ----------
    The following attributes are **immutable** (i.e., read-only). For safety, any attempts to change these attributes
    _will_ result in a raised exception:
 
    __name__ : str
        Fully-qualified name of this module (e.g., `six.moves.tkinter`).
    __file__ : str
        Absolute path of this module. If this module is:
        * A standard (rather than namespace) package, this is the absolute path of this package's directory.
        * A namespace (rather than standard) package, this is the abstract placeholder `-`. (Don't ask. Don't tell.)
        * A non-package module or C extension, this is the absolute path of the corresponding file.
    __path__ : list
        List of the absolute paths of all directories comprising this package if this module is a package _or_ `None`
        otherwise. If this module is a standard (rather than namespace) package, this list contains only the absolute
        path of this package's directory.
    co : code
        Code object compiled from the contents of `__file__` (e.g., via the `compile()` builtin).
    analysis: build_main.Analysis
        The Analysis that load the hook.
 
    Attributes (Private)
    ----------
    The following attributes are technically mutable but private, and hence should _never_ be externally accessed or
    modified by hooks. Call the corresponding public methods instead:
 
    _added_datas : list
        List of the `(name, path)` 2-tuples or TOC objects of all external data files required by the current hook,
        defaulting to the empty list. This is equivalent to the global `datas` hook attribute.
    _added_imports : list
        List of the fully-qualified names of all modules imported by the current hook, defaulting to the empty list.
        This is equivalent to the global `hiddenimports` hook attribute.
    _added_binaries : list
        List of the `(name, path)` 2-tuples or TOC objects of all external C extensions imported by the current hook,
        defaulting to the empty list. This is equivalent to the global `binaries` hook attribute.
    _module_collection_mode : dict
        Dictionary of package/module names and their corresponding collection mode strings. This is equivalent to the
        global `module_collection_mode` hook attribute.
    cCs€||_| |¡|_|jdk    s t‚||_|jj|_|jj|_||_    |jj
dk    rXt |jj
ƒnd|_ g|_ g|_g|_g|_i|_dSr)r Z    find_nodeÚmoduleÚAssertionErrorÚ    ___name__ÚfilenameÚ    ___file__ÚcodeÚ_coÚ    _analysisZ packagepathÚtupleÚ    ___path__Ú_added_binariesÚ _added_datasÚ_added_importsÚ_deleted_importsÚ_module_collection_mode)r r    r Úanalysisrrrr6s  
 
 
ÿÿzPostGraphAPI.__init__cCs|jS)z6
        Absolute path of this module's file.
        )r(rrrrÚ__file__QszPostGraphAPI.__file__cCs|jS)a
        List of the absolute paths of all directories comprising this package if this module is a package _or_ `None`
        otherwise. If this module is a standard (rather than namespace) package, this list contains only the absolute
        path of this package's directory.
        )r-rrrrÚ__path__XszPostGraphAPI.__path__cCs|jS)zR
        Fully-qualified name of this module (e.g., `six.moves.tkinter`).
        ©r&rrrrraszPostGraphAPI.__name__cCs|jS)zk
        Code object compiled from the contents of `__file__` (e.g., via the `compile()` builtin).
        )r*rrrrÚcohszPostGraphAPI.cocCs|jS)z:
        build_main.Analysis that calls the hook.
        )r+rrrrr3oszPostGraphAPI.analysiscCs|jS)z
        Fully-qualified name of this module (e.g., `six.moves.tkinter`).
 
        **This property has been deprecated by the `__name__` property.**
        r6rrrrÚnamewszPostGraphAPI.namecCs|jS)zv
        Current module graph.
 
        **This property has been deprecated by the `module_graph` property.**
        )r rrrrÚgraph€szPostGraphAPI.graphcCs|jS)z†
        Graph node for the currently hooked module.
 
        **This property has been deprecated by the `module` property.**
        )r$rrrrÚnode‰szPostGraphAPI.nodecCs|jj|jdS)zZ
        List of the graph nodes of all modules directly imported by this module.
        )Ústart)r Z
iter_graphr$rrrrÚimports–szPostGraphAPI.importscGs|j |¡dS)a
        Add all Python modules whose fully-qualified names are in the passed list as "hidden imports" upon which the
        current module depends.
 
        This is equivalent to appending such names to the hook-specific `hiddenimports` attribute.
        N)r0Úextend©r Z module_namesrrrÚ add_importsszPostGraphAPI.add_importscGs|j |¡dS)a
        Remove the named fully-qualified modules from the set of imports (either hidden or visible) upon which the
        current module depends.
 
        This is equivalent to appending such names to the hook-specific `excludedimports` attribute.
        N)r1r=r>rrrÚ del_imports§szPostGraphAPI.del_importscCs@|r,t|dƒdkr,|j dd„|Dƒ¡n|j t|ƒ¡dS)aU
        Add all external dynamic libraries in the passed list of `(src_name, dest_name)` 2-tuples as dependencies of the
        current module. This is equivalent to adding to the global `binaries` hook attribute.
 
        For convenience, the `binaries` may also be a list of TOC-style 3-tuples `(dest_name, src_name, typecode)`.
        récss|]}|dd…VqdS©Nér©Ú.0ÚentryrrrÚ    <genexpr>ºsz,PostGraphAPI.add_binaries.<locals>.<genexpr>N)Úlenr.r=r)r ZbinariesrrrÚ add_binaries°s    zPostGraphAPI.add_binariescCs@|r,t|dƒdkr,|j dd„|Dƒ¡n|j t|ƒ¡dS)aH
        Add all external data files in the passed list of `(src_name, dest_name)` 2-tuples as dependencies of the
        current module. This is equivalent to adding to the global `datas` hook attribute.
 
        For convenience, the `datas` may also be a list of TOC-style 3-tuples `(dest_name, src_name, typecode)`.
        rrAcss|]}|dd…VqdSrBrrDrrrrGÊsz)PostGraphAPI.add_datas.<locals>.<genexpr>N)rHr/r=r)r ZdatasrrrÚ    add_datasÀs    zPostGraphAPI.add_datascCs2|dkr|j}|dkr$|j |¡n
||j|<dS)uf"
        Set the package/module collection mode for the specified module name. If `name` is `None`, the hooked
        module/package name is used. `mode` can be one of valid mode strings (`'pyz'`, `'pyc'`, Ë™'py'˙, `'pyz+py'`,
        Ë™'py+pyz'`) or `None`, which clears the setting for the module/package - but only  within this hook's context!
        N)rr2Úpop)r r8ÚmoderrrÚset_module_collection_modeÐs
z'PostGraphAPI.set_module_collection_modeN)rrrrrrr4r5r7r3r8r9r:r<r?r@rIrJrMrrrrr#ús2;
 
 
 
 
 
 
 
 
 
    r#N)    rZPyInstaller.building.utilsrZ'PyInstaller.lib.modulegraph.modulegraphrrrr r#rrrrÚ<module> s      F