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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
U
X±dsÕã@sVddlmZddlZddlZddlZddlZddlZddlmZddl    m
Z
ddl m Z ddl Z ddlmZmZddlmZddlmZdd    lmZdd
lmZdd lmZe e¡ZeejƒZiZ d†d d„Z!d‡dd„Z"ddœdd„Z#ddœdd„Z$ddœdd„Z%ej&ddœdd„ƒZ'dˆddœdd„Z(ddd œd!d"„Z)ddd#œd$d%„Z*dd&œd'd(„Z+ej&ddœd)d*„ƒZ,ddd+œd,d-„Z-dd.œd/d0„Z.d‰d2d3dd4œd5d6„Z/ddœd7d8„Z0dd.œd9d:„Z1ddd;œd<d=„Z2dd.œd>d?„Z3d@dA„dBfddCddDœdEdF„Z4dGdH„Z5dddIœdJdK„Z6dLdMdNgZ7de7fddOdPdQœdRdS„Z8dŠddUdVdWdWdXœdYdZ„Z9d‹ddVdUd[œd\d]„Z:dŒddUd^œd_d`„Z;dddaœdbdc„Z<ddde„Z=ddddfœdgdh„Z>ddiœdjdk„Z?dldm„Z@e@dndo„ƒZAddpœdqdr„ZBdddUdsdWdWddtœdudv„ZCddwœdxdy„ZDdzddd{œd|d}„ZEdŽddWdWd~œdd€„ZFddd‚„ZGejHr0ddƒlImJZKn"ejLrRdd„lMmNZOe Pd…eO¡[OdS)é)Ú annotationsN)ÚPath©Údeque)ÚCallable)ÚHOMEPATHÚcompat)Úlog)Ú PostGraphAPI)ÚExecCommandFailed)Ú!get_pywin32_module_file_attribute)ÚisolatedTcCsšddlm}|dkri}t tj¡}| |¡tj |dt    g¡}d|krbtj | 
d¡|g¡}||d<|r†t j |d|iŽ}|  ¡St j|d|iŽSdS)zÑ
    Executes an externally spawned Python interpreter. If capture_stdout is set to True, returns anything that was
    emitted in the standard output as a single string. Otherwise, returns the exit code.
    r)ÚCONFNZpathexÚ
PYTHONPATHÚenv)ZPyInstaller.configrÚcopyÚdeepcopyÚosÚenvironÚupdateÚpathsepÚjoinrÚgetrZ exec_pythonÚstripZexec_python_rc)ÚcmdrÚcapture_stdoutrZpp_envÚppÚtxt©rúWd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\PyInstaller/utils/hooks/__init__.pyÚ__exec_python_cmd0s  
r cCst |¡}d|g}t||dS)Nz-c©r)ÚtextwrapÚdedentr )Ú    statementrrrrrÚ__exec_statementLs
r%Ústr©r$cCs t|ddS)a
    Execute a single Python statement in an externally-spawned interpreter, and return the resulting standard output
    as a string.
 
    Examples::
 
        tk_version = exec_statement("from _tkinter import TK_VERSION; print(TK_VERSION)")
 
        mpl_data_dir = exec_statement("import matplotlib; print(matplotlib.get_data_path())")
        datas = [ (mpl_data_dir, "") ]
 
    Notes:
        As of v5.0, usage of this function is discouraged in favour of the
        new :mod:`PyInstaller.isolated` module.
 
    Tr!©r%r'rrrÚexec_statementRsr)cCs t|ddS)zf
    Executes a Python statement in an externally spawned interpreter, and returns the exit code.
    Fr!r(r'rrrÚexec_statement_rcfsr*cCst|ƒ ¡}|sdSt|ƒS)aë
    Execute a single Python statement in an externally-spawned interpreter, and :func:`eval` its output (if any).
 
    Example::
 
      databases = eval_statement('''
         import sqlalchemy.databases
         print(sqlalchemy.databases.__all__)
         ''')
      for db in databases:
         hiddenimports.append("sqlalchemy.databases." + db)
 
    Notes:
        As of v5.0, usage of this function is discouraged in favour of the
        new :mod:`PyInstaller.isolated` module.
 
    Ú)r)rÚeval)r$rrrrÚeval_statementms r-©Ú module_namecCsDddl}ddl}t|j ¡ƒ}| |¡tt|j ¡ƒ||hƒS)aÇ
    Return list of modules required by binary (C/C++) Python extension.
 
    Python extension files ends with .so (Unix) or .pyd (Windows). It is almost impossible to analyze binary extension
    and its dependencies.
 
    Module cannot be imported directly.
 
    Let's at least try import it in a subprocess and observe the difference in module list from sys.modules.
 
    This function could be used for 'hiddenimports' in PyInstaller hooks files.
    rN)ÚsysÚ    importlibÚsetÚmodulesÚkeysÚ import_moduleÚlist)r/r0r1ÚoriginalrrrÚget_pyextension_imports†s
 
r8r+)ÚformulacCs¬ddl}ddg}d}|r,| |¡d|}nd}z$| |¡ ¡}t d||f¡Wn@tk
rrt d¡Yn$|jk
r”t d    |¡YnX|r¤| d
¡SdSdS) z§
    Return the homebrew path to the requested formula, or the global prefix when called with no argument.
 
    Returns the path as a string or None if not found.
    rNZbrewz--prefixzhomebrew formula "%s"zhomebrew prefixzFound %s at "%s"zDetected homebrew not installedz#homebrew formula "%s" not installedÚutf8)    Ú
subprocessÚappendÚ check_outputrÚloggerÚdebugÚOSErrorÚCalledProcessErrorÚdecode)r9r;ZbrewcmdÚpathZdbgstrrrrÚget_homebrew_path s"
 
 
rD©ÚstringÚprefixcCs"| |¡r|t|ƒd…S|SdS)zŸ
    This function removes the given prefix from a string, if the string does indeed begin with the prefix; otherwise,
    it returns the original string.
    N)Ú
startswithÚlenrErrrÚ remove_prefix»s
rJ©rFÚsuffixcCs(|r | |¡r |dt|ƒ …S|SdS)z
    This function removes the given suffix from a string, if the string does indeed end with the suffix; otherwise,
    it returns the original string.
    N)ÚendswithrIrKrrrÚ remove_suffixÆsrN)ÚfilenamecCs<tjD]$}| |¡r|d| |¡…Sqtj |¡dS)z†
    This function returns filename without its extension.
 
    For Python C modules it removes even whole '.cpython-34m.so' etc.
    r)rÚEXTENSION_SUFFIXESrMÚrfindrrCÚsplitext)rOÚsuffrrrÚremove_file_extensionÓs
 
rTcCs*zt|ƒWdStk
r$YdSXdS)aš
    Check if the specified module can be imported.
 
    Intended as a silent module availability check, as it does not print ModuleNotFoundError traceback to stderr when
    the module is unavailable.
 
    Parameters
    ----------
    module_name : str
        Fully-qualified name of the module.
 
    Returns
    ----------
    bool
        Boolean indicating whether the module can be imported or not.
    TFN)Ú
__import__Ú    Exceptionr.rrrÚcan_import_moduleàs
rW)r/Ú    attr_namec
CsXtjdd„ƒ}z |||ƒWStk
rR}ztd|›d|›ƒ|‚W5d}~XYnXdS)a·
    Get the string value of the passed attribute from the passed module if this attribute is defined by this module
    _or_ raise `AttributeError` otherwise.
 
    Since modules cannot be directly imported during analysis, this function spawns a subprocess importing this module
    and returning the string value of this attribute in this module.
 
    Parameters
    ----------
    module_name : str
        Fully-qualified name of this module.
    attr_name : str
        Name of the attribute in this module to be retrieved.
 
    Returns
    ----------
    str
        String value of this attribute.
 
    Raises
    ----------
    AttributeError
        If this attribute is undefined.
    cSsddl}| |¡}t||ƒS©Nr)r1r5Úgetattr)r/rXr1ÚmodulerrrÚ_get_module_attributes
z3get_module_attribute.<locals>._get_module_attributezFailed to retrieve attribute z  from module N)r ÚdecoraterVÚAttributeError)r/rXr\ÚerrrÚget_module_attributeús 
 r`©Úpackagec
Cs¤d}d|krPz*ddl}| |¡}| |¡}|r4|WSWnttfk
rNYnXtjdd„ƒ}z ||ƒ}Wn4tk
rž}ztd|›dƒ|‚W5d}~XYnX|S)aù
    Get the absolute path to the specified module or package.
 
    Modules and packages *must not* be directly imported in the main process during the analysis. Therefore, to
    avoid leaking the imports, this function uses an isolated subprocess when it needs to import the module and
    obtain its ``__file__`` attribute.
 
    Parameters
    ----------
    package : str
        Fully-qualified name of module or package.
 
    Returns
    ----------
    str
        Absolute path of this module.
    NÚ.rc    Ss\z*ddl}| |¡}| |¡}|r(|WSWnttfk
rBYnXddl}| |¡}|jSrY)ÚpkgutilÚ find_loaderÚ get_filenamer^Ú ImportErrorr1r5Ú__file__)rbrdÚloaderrOr1ÚprrrÚ_get_module_file_attributeCs
 
 
 
z=get_module_file_attribute.<locals>._get_module_file_attributez:Failed to obtain the __file__ attribute of package/module ú!)rdrerfr^rgr r]rV)rbrOrdrirkr_rrrÚget_module_file_attribute s"
 
 
 
 $rmÚ __version__z list | pkg_resources.Requirementz'str | pkg_resources.Distribution | None)Ú requirementsÚversionÚ version_attrc    Cs”|dkrNzt |¡Wn2tjk
r,Yn"tjtjfk
rHYdSXdStj |¡}|dkr€|j}t|ƒr|t    ||ƒ}nd}|sˆdS||kSdS)aD
 
    Test if a :pep:`0440` requirement is installed.
 
    Parameters
    ----------
    requirements : str
        Requirements in `pkg_resources.Requirements.parse()` format.
    version : str
        Optional PEP 0440-compliant version (e.g., `3.14-rc5`) to be used _instead_ of the current version of this
        module. If non-`None`, this function ignores all `setuptools` distributions for this module and instead
        compares this version against the version embedded in the passed requirements. This ignores the module name
        embedded in the passed requirements, permitting arbitrary versions to be compared in a robust manner.
        See examples below.
    version_attr : str
        Optional name of the version attribute defined by this module, defaulting to `__version__`. If a
        `setuptools` distribution exists for this module (it usually does) _and_ the `version` parameter is `None`
        (it usually is), this parameter is ignored.
 
    Returns
    ----------
    bool
        Boolean result of the desired validation.
 
    Raises
    ----------
    AttributeError
        If no `setuptools` distribution exists for this module _and_ this module defines no attribute whose name is the
        passed `version_attr` parameter.
    ValueError
        If the passed specification does _not_ comply with `pkg_resources.Requirements`_ syntax.
 
    Examples
    --------
 
    ::
 
        # Assume PIL 2.9.0, Sphinx 1.3.1, and SQLAlchemy 0.6 are all installed.
        >>> from PyInstaller.utils.hooks import is_module_satisfies
        >>> is_module_satisfies('sphinx >= 1.3.1')
        True
        >>> is_module_satisfies('sqlalchemy != 0.6')
        False
 
        >>> is_module_satisfies('sphinx >= 1.3.1; sqlalchemy != 0.6')
        False
 
 
        # Compare two arbitrary versions. In this case, the module name "sqlalchemy" is simply ignored.
        >>> is_module_satisfies('sqlalchemy != 0.6', version='0.5')
        True
 
        # Since the "pillow" project providing PIL publishes its version via the custom "PILLOW_VERSION" attribute
        # (rather than the standard "__version__" attribute), an attribute name is passed as a fallback to validate PIL
        # when not installed by setuptools. As PIL is usually installed by setuptools, this optional parameter is
        # usually ignored.
        >>> is_module_satisfies('PIL == 2.9.0', version_attr='PILLOW_VERSION')
        True
 
    .. seealso::
 
        `pkg_resources.Requirements`_ for the syntax details.
 
    .. _`pkg_resources.Requirements`:
            https://pythonhosted.org/setuptools/pkg_resources.html#id12
    NFT)
Ú pkg_resourcesÚget_distributionÚDistributionNotFoundÚ UnknownExtraÚVersionConflictÚ RequirementÚparseÚ project_namerWr`)rorprqZrequirements_parsedr/rrrÚis_module_satisfies_s"G  rzcCs.ddœdd„}d|kr||ƒSt ||¡SdS)zû
    Check if a Python module is really a module or is a package containing other modules, without importing anything
    in the main process.
 
    :param module_name: Module name to check.
    :return: True if module is a package else otherwise.
    r&r.cSs<z ddl}|j |¡}t|jƒWStk
r6YdSXdS)aD
        Determines whether the given name represents a package or not. If the name represents a top-level module or
        a package, it is not imported. If the name represents a sub-module or a sub-package, its parent is imported.
        In such cases, this function should be called from an isolated suprocess.
        rNF)Úimportlib.utilÚutilÚ    find_specÚboolÚsubmodule_search_locationsrV)r/r1ÚspecrrrÚ _is_packageÑs   zis_package.<locals>._is_packagercN©r Úcall)r/rrrrÚ
is_packageÉsr„cCs0ddœdd„}d|kr ||ƒ}n t ||¡}|S)a
    Given a package name, return all paths associated with the package. Typically, packages have a single location
    path, but PEP 420 namespace packages may be split across multiple locations. Returns an empty list if the specified
    package is not found or is not a package.
    r&racSsTz6ddl}|j |¡}|r |js&gWSdd„|jDƒWStk
rNgYSXdS)aç
        Retrieve package path(s), as advertised by submodule_search_paths attribute of the spec obtained via
        importlib.util.find_spec(package). If the name represents a top-level package, the package is not imported.
        If the name represents a sub-module or a sub-package, its parent is imported. In such cases, this function
        should be called from an isolated suprocess. Returns an empty list if specified package is not found or is not
        a package.
        rNcSsg|] }t|ƒ‘qSr)r&)Ú.0rCrrrÚ
<listcomp>ùszEget_all_package_paths.<locals>._get_package_paths.<locals>.<listcomp>)r{r|r}rrV)rbr1r€rrrÚ_get_package_pathsìs 
z1get_all_package_paths.<locals>._get_package_pathsrcr‚)rbr‡Ú    pkg_pathsrrrÚget_all_package_pathsæs
 
 r‰©Ú package_pathrbcCst|| dtj¡ƒS)a6
    Given a package location path and package name, return the package base path, i.e., the directory in which the
    top-level package is located. For example, given the path ``/abs/path/to/python/libs/pkg/subpkg`` and
    package name ``pkg.subpkg``, the function returns ``/abs/path/to/python/libs``.
    rc)rNÚreplacerÚseprŠrrrÚpackage_base_pathsrŽcCsPt|ƒ}|std|›dƒ‚t|ƒdkr6t d||¡|d}t||ƒ}||fS)a£
    Given a package, return the path to packages stored on this machine and also returns the path to this particular
    package. For example, if pkg.subpkg lives in /abs/path/to/python/libs, then this function returns
    ``(/abs/path/to/python/libs, /abs/path/to/python/libs/pkg/subpkg)``.
 
    NOTE: due to backwards compatibility, this function returns only one package path along with its base directory.
    In case of PEP 420 namespace package with multiple location, only first location is returned. To obtain all
    package paths, use the ``get_all_package_paths`` function and obtain corresponding base directories using the
    ``package_base_path`` helper.
    z    Package 'z%' does not exist or is not a package!ézQget_package_paths - package %s has multiple paths (%r); returning only first one!r)r‰Ú
ValueErrorrIr>ÚwarningrŽ)rbrˆÚpkg_dirÚpkg_baserrrÚget_package_pathss  ÿ
r”cCsdS)NTr©ÚnamerrrÚ<lambda>,ór—ú    warn oncezCallable[[str], bool])rbÚfilterÚon_errorc
    sðt|tƒstdƒ‚|dkr*td|›dƒ‚t d|¡t|ƒs\t d|¡t|ƒrX|gSgSg}tƒ}|     |¡t
  ¡Z}|rÎ|  ¡}|  t||¡\}}}|‡fdd„|Dƒ7}|D]}    ˆ|    ƒr´|     |    ¡q´qzW5QRXt|ƒ}t d    |¡|S)
a›
    List all submodules of a given package.
 
    Arguments:
        package:
            An ``import``-able package.
        filter:
            Filter the submodules found: A callable that takes a submodule name and returns True if it should be
            included.
        on_error:
            The action to take when a submodule fails to import. May be any of:
 
            - raise: Errors are reraised and terminate the build.
            - warn: Errors are downgraded to warnings.
            - warn once: The first error issues a warning but all
              subsequent errors are ignored to minimise *stderr pollution*. This
              is the default.
            - ignore: Skip all errors. Don't warn about anything.
    Returns:
        All submodules to be assigned to ``hiddenimports`` in a hook.
 
    This function is intended to be used by hook scripts, not by main PyInstaller code.
 
    Examples::
 
        # Collect all submodules of Sphinx don't contain the word ``test``.
        hiddenimports = collect_submodules(
            "Sphinx", ``filter=lambda name: 'test' not in name)
 
    .. versionchanged:: 4.5
        Add the **on_error** parameter.
 
    úpackage must be a str)Úignorer™ÚwarnÚraisezInvalid on-error action 'z:': Must be one of ('ignore', 'warn once', 'warn', 'raise')zCollecting submodules for %sz)collect_submodules - %s is not a package.csg|]}ˆ|ƒr|‘qSrr)r…r[©ršrrr†psz&collect_submodules.<locals>.<listcomp>z)collect_submodules - found submodules: %s)Ú
isinstancer&Ú    TypeErrorrr>r?r„rWrr<r ÚPythonÚpoprƒÚ_collect_submodulesÚsorted)
rbršr›Zpackage_submodulesÚtodoZisolated_pythonr–r3Ú subpackagesZsubpackage_namerr rÚcollect_submodules*s4'
 
ÿ  
 
 r©c Cs†ddl}ddl}ddlm}ddlm}| d|¡g}g}z t|ƒWn¢tk
rê}z„|dkrÀddl    m}d 
|t |ƒ|ƒ¡  ¡}|  d|›d|›d    |›¡|d
kr®d }|||fWY¢ S|d krÚtd |›dƒ|‚W5d}~XYnX||jkr|||fSt|j|ddƒpg}    |    s*|||fS| |¡| d||    ¡| |    |d¡D](\}
}} | sn| |¡n
| |¡qR|||fS)Nr)Úformat_exception_only)r>z-collect_submodules - scanning (sub)package %s)ržr™r+z"Failed to collect submodules for 'z' because importing 'z
' raised: r™rrŸzUnable to load subpackage 'ú'.Ú__path__z@collect_submodules - scanning (sub)package %s in location(s): %src)r0rdÚ    tracebackrªÚPyInstaller.utils.hooksr>r?rUrVZPyInstaller.logrÚtyperr‘rgr3rZr<Ú iter_modules) r–r›r0rdrªr>r3r¨ÚexÚpathsÚimporterÚispkgrrrr¥~s>     $ 
 
 
 r¥©r–Z mod_or_submodcCs| |d¡p||kS)a 
    This helper function is designed for use in the ``filter`` argument of :func:`collect_submodules`, by returning
    ``True`` if the given ``name`` is a module or a submodule of ``mod_or_submod``.
 
    Examples:
 
        The following excludes ``foo.test`` and ``foo.test.one`` but not ``foo.testifier``. ::
 
            collect_submodules('foo', lambda name: not is_module_or_submodule(name, 'foo.test'))``
    rc)rHrµrrrÚis_module_or_submodule°s r¶ú*.dllz*.dylibzlib*.soz
str | Nonez[str])rbÚdestdirÚsearch_patternsc Cs¼t d|¡t|tƒs tdƒ‚t|ƒs8t d|¡gSt|ƒ}g}|D]n}t||ƒ}|D]Z}t    |ƒ 
|¡}|D]B}    |r~|}
n |    j   |¡}
t d|    |
f¡|  t|    ƒt|
ƒf¡qpqZqH|S)až
    This function produces a list of (source, dest) of dynamic library files that reside in package. Its output can be
    directly assigned to ``binaries`` in a hook script. The package parameter must be a string which names the package.
 
    :param destdir: Relative path to ./dist/APPNAME where the libraries should be put.
    :param search_patterns: List of dynamic library filename patterns to collect.
    z#Collecting dynamic libraries for %srœzZcollect_dynamic_libs - skipping library collection for module '%s' as it is not a package.z %s, %s)r>r?r¡r&r¢r„r‘r‰rŽrÚrglobÚparentÚ relative_tor<) rbr¸r¹Úpkg_dirsZdylibsr’r“ÚpatternÚfilesÚsourceÚdestrrrÚcollect_dynamic_libsÆs,
ÿ
 rÂFr~zstr | os.PathLike | Nonez list | None)rbÚinclude_py_filesÚsubdirÚexcludesÚincludesc s t d|¡t|tƒs tdƒ‚t|ƒs8t d|¡gS|rDt|ƒng}t|ƒ}|sh|dd„t    j
Dƒ7}|s€dt    j
kr€|  d¡|rŒt|ƒndg}t|ƒ}‡fd    d
„}g}t |ƒ}    |    D]X}
t ƒ‰t|
|ƒ‰|rÜtj |
|¡}
||
||d ƒ||
||d ƒ|‡fd d„ˆDƒ7}q¶t d|¡|S)aÔ
    This function produces a list of ``(source, dest)`` non-Python (i.e., data) files that reside in ``package``.
    Its output can be directly assigned to ``datas`` in a hook script; for example, see ``hook-sphinx.py``.
    Parameters:
 
    -   The ``package`` parameter is a string which names the package.
    -   By default, all Python executable files (those ending in ``.py``, ``.pyc``, and so on) will NOT be collected;
        setting the ``include_py_files`` argument to ``True`` collects these files as well. This is typically used with
        Python functions (such as those in ``pkgutil``) that search a given directory for Python executable files and
        load them as extensions or plugins.
    -   The ``subdir`` argument gives a subdirectory relative to ``package`` to search, which is helpful when submodules
        are imported at run-time from a directory lacking ``__init__.py``.
    -   The ``excludes`` argument contains a sequence of strings or Paths. These provide a list of
        `globs <https://docs.python.org/3/library/pathlib.html#pathlib.Path.glob>`_
        to exclude from the collected data files; if a directory matches the provided glob, all files it contains will
        be excluded as well. All elements must be relative paths, which are relative to the provided package's path
        (/ ``subdir`` if provided).
 
        Therefore, ``*.txt`` will exclude only ``.txt`` files in ``package``\ 's path, while ``**/*.txt`` will exclude
        all ``.txt`` files in ``package``\ 's path and all its subdirectories. Likewise, ``**/__pycache__`` will exclude
        all files contained in any subdirectory named ``__pycache__``.
    -   The ``includes`` function like ``excludes``, but only include matching paths. ``excludes`` override
        ``includes``: a file or directory in both lists will be excluded.
 
    This function does not work on zipped Python eggs.
 
    This function is intended to be used by hook scripts, not by main PyInstaller code.
    zCollecting data files for %srœzUcollect_data_files - skipping data collection for module '%s' as it is not a package.cSsg|] }d|‘qS)ú**/*r©r…Úsrrrr†%sz&collect_data_files.<locals>.<listcomp>z.pyoz**/*.pyorÇcslt|ƒD]^\}}t|ƒ |¡D]F}| ¡rL||krd| t|d |¡ƒ¡q|rZˆ |¡nˆ |¡qqdS)NrÇ)    Ú    enumeraterÚglobÚis_dirr<r&r¼ÚaddÚdiscard)r’ZcludesZ    clude_lenZ
is_includeÚiÚcÚg)ÚsourcesrrÚ clude_walker2s
z(collect_data_files.<locals>.clude_walkerTFcs$g|]}t|ƒt|j ˆ¡ƒf‘qSr©r&r»r¼rÈ©r“rrr†Wsz$collect_data_files - Found files: %s)r>r?r¡r&r¢r„r‘r6rIrÚ ALL_SUFFIXESr<r‰r2rŽrrCr) rbrÃrÄrÅrÆZ excludes_lenZ includes_lenrÓÚdatasr½r’r)r“rÒrÚcollect_data_filesðs6#
 
 
 rØ)rCr¸rÃc Csšt|tƒstdƒ‚g}t |¡D]t\}}}|D]d}tj |¡d}|sN|tkr.tj ||¡}    tt    |ƒ 
|¡ƒ}
|dk    r„tj ||
¡}
|  |    |
f¡q.q |S)a
    This function produces a list of (source, dest) non-Python (i.e., data) files that reside somewhere on the system.
    Its output can be directly assigned to ``datas`` in a hook script.
 
    This function is intended to be used by hook scripts, not by main PyInstaller code.
    zpath must be a strrN) r¡r&r¢rÚwalkrCrRÚPY_IGNORE_EXTENSIONSrrr¼r<) rCr¸rÃr×ÚdirpathÚdirnamesr¿ÚfÚ    extensionrÀrÁrrrÚcollect_system_data_files]s
 rß)Ú package_nameÚ    recursivec    CsÊddlm}||gƒ}tƒ}g}|rÆ| ¡}||kr6q t |¡}|jdk    rjt|j|jƒ}|     |j|f¡n0t
|ƒ}|dkrŒt d|j›dƒ‚|     |df¡|s¢|S|  |¡|  dd„| ¡Dƒ¡q |S)    a«
    Collect distribution metadata so that ``pkg_resources.get_distribution()`` can find it.
 
    This function returns a list to be assigned to the ``datas`` global variable. This list instructs PyInstaller to
    copy the metadata for the given package to the frozen application's data directory.
 
    Parameters
    ----------
    package_name : str
        Specifies the name of the package for which metadata should be copied.
    recursive : bool
        If true, collect metadata for the package's dependencies too. This enables use of
        ``pkg_resources.require('package')`` inside the frozen application.
 
    Returns
    -------
    list
        This should be assigned to ``datas``.
 
    Examples
    --------
        >>> from PyInstaller.utils.hooks import copy_metadata
        >>> copy_metadata('sphinx')
        [('c:\python27\lib\site-packages\Sphinx-1.3.2.dist-info',
          'Sphinx-1.3.2.dist-info')]
 
 
    Some packages rely on metadata files accessed through the ``pkg_resources`` module. Normally PyInstaller does not
    include these metadata files. If a package fails without them, you can use this function in a hook file to easily
    add them to the frozen bundle. The tuples in the returned list have two strings. The first is the full pathname to a
    folder in this system. The second is the folder name only. When these tuples are added to ``datas``\ , the folder
    will be bundled at the top level.
 
    .. versionchanged:: 4.3.1
 
        Prevent ``dist-info`` metadata folders being renamed to ``egg-info`` which broke ``pkg_resources.require`` with
        *extras* (see :issue:`#3033`).
 
    .. versionchanged:: 4.4.0
 
        Add the **recursive** option.
    rrNú)No metadata path found for distribution 'z"' (legacy fallback search failed).rccss|] }|jVqdS)N)ry)r…rÏrrrÚ    <genexpr>Àsz copy_metadata.<locals>.<genexpr>)Ú collectionsrr2r¤rrrsÚegg_infoÚ_copy_metadata_destryr<Ú_resolve_legacy_metadata_pathÚ RuntimeErrorrÍÚextendÚrequires)    ràrárr§ÚdoneÚoutÚdistrÁZdist_srcrrrÚ copy_metadataxs.+ 
 
 
 ÿ
rî)r–ÚreturncCs| ¡ dd¡S)NÚ_ú-)ÚlowerrŒr•rrrÚ_normalise_distÅsrócCs¸| ¡›d|j›d|j›d|j dd¡›d|j›dg}dtjd›dtjd›}| ¡ |¡r†| | ¡dt|ƒ …d¡|D](}t    j
  |j |¡}t    j
  |¡rŠ|SqŠdS)    ai
    Attempt to resolve the legacy metadata file for the given distribution.
    The .egg-info file is commonly used by Debian/Ubuntu when packaging python packages.
 
    Args:
        dist:
            The distribution information as returned by ``pkg_resources.get_distribution("xyz")``.
    Returns:
        The path to the distribution's metadata file.
    z    .egg-inforñrðz-pyrrcrN)Úegg_nameryrprŒr0Ú version_inforMr<rIrrCrÚlocationÚisfile)ríÚ
candidatesZ pyxx_suffixÚ    candidateZcandidate_pathrrrrçÉs ù   
rç)Úegg_pathryrïcCs|dkrtd|›dƒ‚t|ƒ}t|ƒ}t|jƒ |¡r>|jSt|jƒdkrvt|jdƒ |¡rvtjj    |jdd…ŽStd|›d|›dƒ‚dS)    a2
    Choose an appropriate destination path for a distribution's metadata.
 
    Args:
        egg_path:
            The output of ``pkg_resources.get_distribution("xyz").egg_info``: a full path to the source
            ``xyz-version.dist-info`` or ``xyz-version.egg-info`` folder containing package metadata.
        project_name:
            The distribution name given.
    Returns:
        The *dest* parameter: where in the bundle should this folder go.
    Raises:
        RuntimeError:
            If **egg_path** is None, i.e., no metadata is found.
    Nrâr«ééþÿÿÿzUnknown metadata type 'z ' from the 'zT' distribution. Please report this at https://github/pyinstaller/pyinstaller/issues.)
rèrrór–rHrIÚpartsrrCr)rúryÚ _project_namerrrræìs    ÿræ)r[c
Csft|ƒ}|d| d¡tdƒ…}t |¡}d}|D]}| ¡|jkr4|}qPq4t|ƒd\}}tj     
|d¡}tj      |¡râtj      |¡rât |dƒL}    |     ¡}
|
ddkrØ|
d d¡} t d | ||¡¡| W5QR£SW5QRXtjrbz4t d    d
|¡} d | krt d  ||¡¡Wd SWntk
r4YnXtj     |¡} d| krbt d ||¡¡dSdS)zˆ
    Try to find which package manager installed a module.
 
    :param module: Module to check
    :return: Package manager or None
    Nz site-packagesrÚ    INSTALLERÚrr+z
z<Found installer: '{0}' for module: '{1}' from package: '{2}'ÚportÚprovideszis provided byzAFound installer: 'macports' for module: '{0}' from package: '{1}'ZmacportsZCellarzAFound installer: 'homebrew' for module: '{0}' from package: '{1}'Zhomebrew)rmÚindexrIrrÚfind_distributionsròÚkeyrîrrCrÚisdirÚexistsÚopenÚ    readlinesÚrstripr>r?ÚformatrZ    is_darwinZexec_command_stdoutr Úrealpath)r[Ú    file_nameZsite_dirÚpkgsrbÚpkgÚ metadata_dirÚdest_dirÚinstaller_fileZinstaller_file_objectÚlinesÚ    installerÚoutputÚ    real_pathrrrÚ get_installersD
   ÿ
 
ÿ
 
rcsg‰‡‡fdd„}|S)Ncsˆsˆ ˆƒ¡ˆdSrY)r<r©rÝÚmemorrÚhelperRs z_memoize.<locals>.helperr)rÝrrrrÚ_memoizeOsrc
CsŒt d¡i}tjD]r}|s d}zt |¡}Wntk
rBYqX|D]<}zt |¡}Wntk
rnYqHX|     |j
g¡  |¡qHq|S)Nz5Determining a mapping of distributions to packages...rc) r>Úinfor0rCrÚlistdirrVrrrsÚ
setdefaultrr<)Údist_to_packagesrjZldsZldrírrrÚ_map_distribution_to_packages[s 
 
r )ràcCs`g}tƒ}t |¡ ¡D]4}|j|kr<||j}| |¡qt d|j|¡qt     d||¡|S)Nz:Unable to find package for requirement %s from package %s.zPackages required by %s:
%s)
r rrrsrêrrér>r‘ryr)ràÚ hiddenimportsrÚ requirementZrequired_packagesrrrÚrequirements_for_packagews
 
 ÿr#zCallable | None)ràrÃÚfilter_submodulesÚ exclude_datasÚ include_datasr›c
 
CsÊg}z|t|ƒ7}Wn0tk
rD}zt d||¡W5d}~XYnX|t||||d7}t|ƒ}|rvt|||d}    nt|ƒ}    z|    t|ƒ7}    Wn0tk
r¾}zt d||¡W5d}~XYnX|||    fS)a°
    Collect everything for a given package name.
 
    Arguments:
        package_name:
            An ``import``-able package name.
        include_py_files:
            Forwarded to :func:`collect_data_files`.
        filter_submodules:
            Forwarded to :func:`collect_submodules`.
        exclude_datas:
            Forwarded to :func:`collect_data_files`.
        include_datas:
            Forwarded to :func:`collect_data_files`.
        on_error:
            Forwarded onto :func:`collect_submodules`.
 
    Returns:
        tuple: A ``(datas, binaries, hiddenimports)`` triplet containing:
 
        - All data files, raw Python files (if **include_py_files**), and package metadata folders.
        - All dynamic libraries as returned by :func:`collect_dynamic_libs`.
        - All submodules of **packagename** and its dependencies.
 
    Typical use::
 
        datas, binaries, hiddenimports = collect_all('my_module_name')
    z"Unable to copy metadata for %s: %sN)rÅrÆ)r›ršz+Unable to determine requirements for %s: %s)rîrVr>r‘rØrÂr©r#)
ràrÃr$r%r&r›r×r_Úbinariesr!rrrÚ collect_allˆs$  r(r•cCsVddl}g}g}| |¡D]2}|jdkr,dn|jj}|t|ƒ7}| |j¡q||fS)ai
    Collect modules and metadata for all exporters of a given entry point.
 
    Args:
        name:
            The name of the entry point. Check the documentation for the library that uses the entry point to find
            its name.
    Returns:
        A ``(datas, hiddenimports)`` pair that should be assigned to the ``datas`` and ``hiddenimports``, respectively.
 
    For libraries, such as ``pytest`` or ``keyring``, that rely on plugins to extend their behaviour.
 
    Examples:
        Pytest uses an entry point called ``'pytest11'`` for its extensions.
        To collect all those extensions use::
 
            datas, hiddenimports = collect_entry_point("pytest11")
 
        These values may be used in a hook or added to the ``datas`` and ``hiddenimports`` arguments in the ``.spec``
        file. See :ref:`using spec files`.
 
    .. versionadded:: 4.3
    rNr+)rrÚiter_entry_pointsríryrîr<r/)r–rrr×ZimportsríryrrrÚcollect_entry_point¿s r*r
)Úhook_apir/rcCs0|jj}d}||kr,|||kr,|||}|S)aÔ
    Get user settings for hooks.
 
    Args:
        module_name:
            The module/package for which the key setting belong to.
        key:
            A key for the config.
    Returns:
        The value for the config. ``None`` if not set.
 
    The ``get_hook_config`` function will lookup settings in the ``Analysis.hooksconfig`` dict.
 
    The hook settings can be added to ``.spec`` file in the form of::
 
        a = Analysis(["my-app.py"],
            ...
            hooksconfig = {
                "gi": {
                    "icons": ["Adwaita"],
                    "themes": ["Adwaita"],
                    "languages": ["en_GB", "zh_CN"],
                },
            },
            ...
        )
    N)ZanalysisZ hooksconfig)r+r/rÚconfigÚvaluerrrÚget_hook_configás
 r.)rOÚ include_listÚ exclude_listcCsN|dk    r&|D]}t ||¡r q&q dS|dk    rJ|D]}t ||¡r2dSq2dS)a
    Generic inclusion/exclusion decision function based on filename and list of include and exclude patterns.
 
    Args:
        filename:
            Filename considered for inclusion.
        include_list:
            List of inclusion file patterns.
        exclude_list:
            List of exclusion file patterns.
 
    Returns:
        A boolean indicating whether the file should be included or not.
 
    If ``include_list`` is provided, True is returned only if the filename matches one of include patterns (and does not
    match any patterns in ``exclude_list``, if provided). If ``include_list`` is not provided, True is returned if
    filename does not match any patterns in ``exclude list``, if provided. If neither list is provided, True is
    returned for any filename.
    NFT)Úfnmatch)rOr/r0r¾rrrÚinclude_or_exclude_files  r2csš|pg}|pg}|dkr |d}tjs.||fSt|ƒ\‰}tˆƒ‰ˆ|}| ¡sZ||fS|‡fdd„| d¡Dƒ7}|‡fdd„| d¡Dƒ7}||fS)a 
    Collect data files and binaries from the .libs directory of a delvewheel-enabled python wheel. Such wheels ship
    their shared libraries in a .libs directory that is located next to the package directory, and therefore falls
    outside the purview of the collect_dynamic_libs() utility function.
 
    Args:
        package_name:
            Name of the package (e.g., scipy).
        libdir_name:
            Optional name of the .libs directory (e.g., scipy.libs). If not provided, ".libs" is added to
            ``package_name``.
        datas:
            Optional list of datas to which collected data file entries are added. The combined result is retuned
            as part of the output tuple.
        binaries:
            Optional list of binaries to which collected binaries entries are added. The combined result is retuned
            as part of the output tuple.
 
    Returns:
        tuple: A ``(datas, binaries)`` pair that should be assigned to the ``datas`` and ``binaries``, respectively.
 
    Examples:
        Collect the ``scipy.libs`` delvewheel directory belonging to the Windows ``scipy`` wheel::
 
            datas, binaries = collect_delvewheel_libs_directory("scipy")
 
        When the collected entries should be added to existing ``datas`` and ``binaries`` listst, the following form
        can be used to avoid using intermediate temporary variables and merging those into existing lists::
 
            datas, binaries = collect_delvewheel_libs_directory("scipy", datas=datas, binaries=binaries)
 
    .. versionadded:: 5.6
    Nz.libscs$g|]}t|ƒt|j ˆ¡ƒf‘qSrrÔ)r…Zdll_filerÕrrr†dsz5collect_delvewheel_libs_directory.<locals>.<listcomp>r·cs$g|]}t|ƒt|j ˆ¡ƒf‘qSrrÔ)r…Zload_order_filerÕrrr†isÿz.load[-_]order*)rZis_winr”rrÌrË)ràZ libdir_namer×r'r’Zlibs_dirrrÕrÚ!collect_delvewheel_libs_directory+s #  ÿr3)Úconda)ÚCONDA_META_DIRz¨Assuming this is not an Anaconda environment or an additional venv/pipenv/... environment manager is being used on top, because the conda-meta folder %s does not exist.)NT)T)r+)Nrn)FNNN)NF)F)TNNNr™)NN)NNN)QÚ
__future__rrrr0r"r1ÚpathlibrrärÚtypingrrrZ PyInstallerrrr    ÚloggingZPyInstaller.depend.imphookapir
ZPyInstaller.exceptionsr ZPyInstaller.utils.hooks.win32r r Ú    getLoggerÚ__name__r>r2rÖrÚZhook_variablesr r%r)r*r-r]r8rDrJrNrTrWr`rmrzr„r‰rŽr”r©r¥r¶ZPY_DYLIB_PATTERNSrÂrØrßrîrórçrærrr r#r(r*r.r2r3Z is_pure_condar®r4Z conda_supportZis_condaZPyInstaller.utils.hooks.condar5Z_tmpr‘rrrrÚ<module> s¬         
 
 
 
   &Aýj!    ýT2ý,ûmM#21 
ú7"%ý'
D þ