zmc
2023-12-22 9fdbf60165db0400c2e8e6be2dc6e88138ac719a
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
U
W±d´Cã@s dZddlZddlZddlZddlZddlZddlZddlm    Z    ddl
Z
ddl m Z ddl m ZddlmZddlmZddlmZdd    lmZe e¡Zd
d „Zd d „Ze    dœdd„Ze dejdejdejdej d¡Z!e    dœdd„Z"dd„Z#da$dd„Z%dd„Z&dd„Z'dS) z?
Utility functions related to analyzing/bundling dependencies.
éN)ÚCodeType)Úcompat)Úlog)Úbytecode)Úinclude_library)ÚExecCommandFailed)Ú modulegraphc Cs¦ddlm}d dd„tjDƒ¡}d dd„tjDƒ¡}|d|}t |¡}z.tj     |¡rht 
|¡t   d¡t j|dd    ö}d
|_ t| ¡ƒ}|jd d „d |D]È}    t|    ƒtjtjtjfkr¨| |    j¡r¨t|    ƒtjkrò|    j dd¡d}
n|    j dd¡d}
t ¡^} |  tj¡|  t dd¡¡|  d¡||    j ƒ} t! "| | ¡t  #|
¡} | $| |  %¡¡W5QRXq¨W5QRXWn"t&k
r t  'd¡‚YnXdS)zÏ
    Package basic Python modules into .zip file. The .zip file with basic modules is necessary to have on PYTHONPATH
    for initializing libpython3 in order to run the frozen executable with Python 3.
    r)Ústrip_paths_in_codeú|cSsg|]}d|›d‘qS)ú(^z$)©©Ú.0Úxr r úOd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\PyInstaller/depend/utils.pyÚ
<listcomp>0sz+create_py3_base_library.<locals>.<listcomp>cSsg|]}d|›d‘qS)r z\..*$)r r r r rr1sz'Adding python files to base_library.zipÚw)ÚmodeécSs|jS©N)Ú
identifier)Úitemr r rÚ<lambda>?óz)create_py3_base_library.<locals>.<lambda>)ÚkeyÚ.ú/z /__init__.pycz.pycz<Iész&base_library.zip could not be created!N)(ZPyInstaller.building.utilsr    ÚjoinrZPY3_BASE_MODULESÚreÚcompileÚosÚpathÚexistsÚremoveÚloggerÚdebugÚzipfileÚZipFileÚlistZ
iter_graphÚsortÚtyperZ SourceModuleÚPackageZCompiledModuleÚmatchrÚreplaceÚioÚBytesIOÚwriteZBYTECODE_MAGICÚstructÚpackÚcodeÚmarshalÚdumpÚZipInfoÚwritestrÚgetvalueÚ    ExceptionÚerror)Zlibzip_filenameÚgraphr    Z regex_modulesZ regex_submodZ    regex_strZ module_filterÚzfZ graph_nodesÚmodÚnew_nameZfcr4Úinfor r rÚcreate_py3_base_library%s<  
 
 
 
 
 
 
*
rAc    Cs†t|ƒ}t|ƒ}t|ƒD]`}|s,| |¡q|tj |¡krz
|j}Wntk
r^d}YnXt     
d||¡| |¡qt |ƒ}|S)NÚUNKNOWNzPIgnoring %s imported from %s - only basenames are supported with ctypes imports!) Ú*__recursively_scan_code_objects_for_ctypesÚsetr)r$r!r"ÚbasenameÚ co_filenamer:r%ÚwarningÚ_resolveCtypesImports)ÚcoÚbinariesÚbinaryÚfilenamer r rÚscan_code_for_ctypes[s$  
 
ÿ rM)r4c
Cs0ddlm}m}g}|dƒ|dƒ|dƒ|dƒ|dƒ|dƒ|d    ƒ|d
ƒ™}|d ƒ™}t |¡ ¡D]ª}|D] \}}t|ƒd krht|dtƒsŒqh||kr |j    |Žqh||krh|d}    |    rhzt
j   |    ¡}    Wn(t k
rìd }    t d|d¡YnX|    rhtj |    ¡}    |     |    ¡qhq`|t|ƒ ¡D]}
| |
¡q|S)z¹
    Detects ctypes dependencies, using reasonable heuristics that should cover most common ctypes usages; returns a
    list containing names of binaries detected as dependencies.
    r)Ú    any_aliasÚsearch_recursivelyz ctypes.CDLLzctypes.cdll.LoadLibraryz ctypes.WinDLLzctypes.windll.LoadLibraryz ctypes.OleDLLzctypes.oledll.LoadLibraryz ctypes.PyDLLzctypes.pydll.LoadLibraryzctypes.util.find_libraryrNzqctypes.util.find_library raised a FileNotFoundError. Supressing and assuming no lib with the name "%s" was found.)ZPyInstaller.depend.bytecoderNrOrZrecursive_function_callsÚvaluesÚlenÚ
isinstanceÚstrÚappendÚctypesÚutilÚ find_libraryÚFileNotFoundErrorr%rGr!r"rEÚ_scan_code_for_ctypes_getattrÚextend) r4rNrOrJZctypes_dll_namesZfind_library_namesZcallsÚnameÚargsÚlibnameÚir r rrCwsHø ÿ  þ
 rCsV
    # Matches 'foo.bar' or 'foo.bar.whizz'.
 
    # Load the 'foo'.
    (
      (?:(?:s).)*
      (?:s˜).
    )
 
    # Load the 'bar.whizz' (one opcode per name component, each possibly preceded by name reference extension).
    (
      (?:
        (?:(?:s).)*
        (?:s).
      )+
    )
ccs¢d}t t|j¡D]Š}| ¡\}}t ||¡}t ||¡}|rL|ddkrLqt|ƒdkrn||krn|ddVt|ƒdkr|dkr|d|kr|ddVqd    S)
zs
    Detect uses of ``ctypes.cdll.library_name``, which implies that ``library_name.dll`` should be collected.
    )ÚcdllÚoledllÚpydllÚwindlléÿÿÿÿÚ LoadLibraryrrz.dllérUN)rÚfinditerÚ_ctypes_getattr_regexÚco_codeÚgroupsÚloadÚloadsrQ)r4Z    key_namesr-r[Úattrsr r rrYÄs     rYc        srddlm}ddlm‰tjr$d‰ntjr0d‰nd‰‡‡fdd„}‡fd    d
„}g}|ƒ}|D]}z|tj     |¡dƒ}Wnt
k
r’d }YnXtjr$|d kr¨|}t  ˆd ¡  tj ¡D].}tj tj ||¡¡r¼tj ||¡}q$q¼td krútƒ|tkr t|}tj |¡s$t‚nd }|d krHt|ƒs:q\t d |¡q\t|ƒsTq\| ||df¡q\||ƒ|S)a
    Completes ctypes BINARY entries for modules with their full path.
 
    Input is a list of c-binary-names (as found by `scan_code_instruction_for_ctypes`). Output is a list of tuples
    ready to be appended to the ``binaries`` of a modules.
 
    This function temporarily extents PATH, LD_LIBRARY_PATH or DYLD_LIBRARY_PATH (depending on the platform) by
    CONF['pathex'] so shared libs will be search there, too.
 
    Example:
    >>> _resolveCtypesImports(['libgs.so'])
    [(libgs.so', ''/usr/lib/libgs.so', 'BINARY')]
    r)rW)ÚCONFZLD_LIBRARY_PATHZDYLD_LIBRARY_PATHÚPATHcsBtj ˆd¡}t ˆ¡}|dk    r2tj ||f¡}t ˆ|¡|S)NZpathex)r!ÚpathseprrÚgetenvÚsetenv)r"Úold©rmÚenvvarr rÚ    _setPaths÷s 
 z(_resolveCtypesImports.<locals>._setPathscs$|dkrt ˆ¡n t ˆ|¡dSr)rÚunsetenvrq)rr)rtr rÚ _restorePathsÿs z,_resolveCtypesImports.<locals>._restorePathsNÚz(Library %s required via ctypes not foundÚBINARY)Ú ctypes.utilrWZPyInstaller.configrmrZis_unixZ    is_darwinr!r"ÚsplitextrXrpÚsplitroÚisfilerÚLDCONFIG_CACHEÚload_ldconfig_cacheÚAssertionErrorrr%rGrT)    Z    cbinariesrWrurwÚretrrZcbinZcpathÚdr rsrrHÞsL   
 
 
 
 
 
rHc Cs”tdk    r dStjriadSddlm}|dƒ}|dkrP|ddƒ}|dkrPiadStjs\tjrpd}d}t d¡}nd    }d
}t d ¡}zt     ||¡}Wn$t
k
r¶t   d ¡iaYdSX|  ¡ ¡|d…}ia|D]º}| |¡}|dkrt d |¡rúqÔt   d|¡qÔ| ¡d}tjs$tjrttj |¡ dd
¡d}    d| d
¡}
|
 |    ¡sZt‚|    d|
t|    ƒd…}
n
| d
¡}
|
tkrÔ|t|
<qÔdS)zš
    Create a cache of the `ldconfig`-output to call it only once.
    It contains thousands of libraries and running it on every dylib is expensive.
    Nr)Úfind_executableÚldconfigz"/usr/sbin:/sbin:/usr/bin:/usr/sbinz-rrez^\s+\d+:-l(\S+)(\s.*)? => (\S+)z-prz^\s+(\S+)(\s.*)? => (\S+)z/Failed to execute ldconfig. Disabling LD cache.zCache generated by:z,Unrecognised line of output %r from ldconfigrcz.soÚlib)r~rZis_muslÚdistutils.spawnrƒZ
is_freebsdZ
is_openbsdrr Z exec_commandrr%rGÚstripÚ
splitlinesr-Úsearchrir!r"rEr|ÚgroupÚ
startswithr€rQ) rƒr„Z ldconfig_argZsplitlines_countÚpatternÚtextÚlineÚmr"Zbnamer[r r rr6sV 
 
 
 
 
 
rcCsZd}|rV||krVtj |¡d ¡dkrDtj |¡s@tj |¡rD|S|}tj |¡}qdS)z‘
    Return the path to the python egg file, if the given path points to a file inside (or directly to) an egg.
    Return `None` otherwise.
    Nrz.egg)r!r"r{Úlowerr}ÚisdirÚdirname)r"Zlastpathr r rÚget_path_to_eggs r“cCs t|ƒdk    S)z]
    Check if the given path points to a file inside (or directly to) a python egg file.
    N)r“)r"r r rÚis_path_to_egg sr”)(Ú__doc__rzrUr/r!rr2r'Útypesrr5Z PyInstallerrrÚloggingZPyInstaller.dependrZPyInstaller.depend.dylibrZPyInstaller.exceptionsrZPyInstaller.lib.modulegraphrÚ    getLoggerÚ__name__r%rArMrCZbytecode_regexZ_OPCODES_EXTENDED_ARGZ_OPCODES_FUNCTION_GLOBALZ_OPCODES_FUNCTION_LOADrgrYrHr~rr“r”r r r rÚ<module> sV       
68ûûúú ô ô ó óÿUY