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
U
X±d´[ã    @s$ddlZddlZddlZddlZddlZddlZddlZddlmZe     ¡ 
e  ¡¡ddl Z ddl Z ddlZddlZej ej ej ej e¡¡dd¡¡Zej e¡ddlmZddlmZddlmZmZmZddl m!Z!ddl"m#Z#dd    l$m%Z%dd
l&m'Z'd Z(d d dhZ)ej* +dd¡dkZ,ej-dd„ƒZ.ej-dd„ƒZ/dd„Z0ej1ddddd„ƒZ2dd„Z3dd„Z4dd „Z5d!d"„Z6d#d$„Z7d%d&„Z8ej-d'd(„ƒZ9d)d*„Z:ej-d+d,„ƒZ;Gd-d.„d.ƒZ<ej-d/d0d1d2„ƒZ=ej-d3d4gd5d6d7„ƒZ>ej-d8d9„ƒZ?e -¡d:d;„ƒZ@ej-e<d<œd=d>„ƒZAdS)?éN)Úsuppressz..)Ú__main__)Ú    configure)Ú architectureÚ    is_darwinÚis_win)Úinitialize_modgraph)Úpkg_archive_contents)Úgen_sourcefile)Úwinutilsé´ÚdarwinÚlinuxÚwin32ZPYI_BUILDER_CLEANUPÚ1cCstj t|ƒ¡S)z@
    Return the directory where the test spec-files reside.
    )ÚpyÚpathÚlocalÚ _get_spec_dir©Úrequest©rúQd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\PyInstaller/utils/conftest.pyÚSPEC_DIR7srcCstj t|ƒ¡S)z=
    Return the directory where the test scripts reside.
    ©rrrÚ_get_script_dirrrrrÚ
SCRIPT_DIR?srcCs<t dd„| ¡Dƒ¡}tj}|r8||kr8t d|¡dS)aR
    Markers to skip tests based on the current platform.
    https://pytest.org/en/stable/example/markers.html#marking-platform-specific-tests-with-pytest
 
    Available markers: see setup.cfg [tool:pytest] markers
        - @pytest.mark.darwin (macOS)
        - @pytest.mark.linux (GNU/Linux)
        - @pytest.mark.win32 (Windows)
    css|] }|jVqdS©N)Úname)Ú.0ÚmarkrrrÚ    <genexpr>Qsz'pytest_runtest_setup.<locals>.<genexpr>zdoes not run on %sN)ÚSUPPORTED_OSESÚ intersectionZ iter_markersÚsysÚplatformÚpytestÚskip)ÚitemÚsupported_platformsÚplatrrrÚpytest_runtest_setupGs
 r+T)ZtryfirstZ hookwrapperccs$dV}| ¡}t|d|j|ƒdS)NZrep_)Z
get_resultÚsetattrÚwhen)r(ÚcallZoutcomeÚreprrrÚpytest_runtest_makereportWsr0cCstj tj |jj¡¡Sr)ÚosrÚdirnameÚabspathÚfspathÚstrpathrrrrÚ _get_base_dirbsr6cCstj t|ƒd¡S)NÚscripts©r1rÚjoinr6rrrrrgsrcCstj t|ƒd¡S)NÚmodulesr8rrrrÚ_get_modules_dirlsr;cCstj t|ƒd¡S)NZlogsr8rrrrÚ _get_logs_dirqsr<cCstj t|ƒd¡S©NÚdatar8rrrrÚ _get_data_dirvsr?cCstj t|ƒd¡S)NÚspecsr8rrrrr{srcCstj t|ƒ¡SrrrrrrÚ
script_dirsrAcCs6tj t|ƒ¡ |¡}| d|¡}t |j|j¡|Sr=)rrrr?r9ÚshutilÚcopytreer5)rZ subdir_nameÚtmpdirZsource_data_dirÚ tmp_data_dirrrrÚ_data_dir_copy…s
 rFcCs|jjdd…}t|||ƒS)Né)ÚfunctionÚ__name__rF)rrDrrrrÚdata_dir˜s rJc@s^eZdZdd„Zdd„Zdd„Zdd    d
„Zd d „Zd d„Zdd„Z    dd„Z
dd„Z dd„Z dS)Ú
AppBuildercCsB||_||_||_t|ƒ|_t|dƒ|_t|dƒ|_d|_dS)NÚdistÚbuildF)Ú_tmpdirÚ_requestÚ_modeÚstrÚ_specdirÚ_distdirÚ    _builddirÚ_is_spec)ÚselfrDrZ bundle_moderrrÚ__init__ªs
zAppBuilder.__init__cOs0d}tj t|jƒ|¡}d|_|j|f|ž|ŽS)zU
        Test a Python script that is referenced in the supplied .spec file.
        T)r1rr9rrOrUÚ test_script)rVZspecfileÚargsÚkwargsÚ__tracebackhide__rrrÚ    test_spec³szAppBuilder.test_speccOs4d}t|j|| d¡ƒ}|d=|jt|ƒf|ž|ŽS)a’
        Test a Python script given as source code.
 
        The source will be written into a file named like the test-function. This file will then be passed to
        `test_script`. If you need other related file, e.g., as `.toc`-file for testing the content, put it at at the
        normal place. Just mind to take the basnename from the test-function's name.
 
        :param script: Source code to create executable from. This will be saved into a temporary file which is then
                       passed on to `test_script`.
 
        :param test_id: Test-id for parametrized tests. If given, it will be appended to the script filename, separated
                        by two underscores.
 
        All other arguments are passed straight on to `test_script`.
 
        Ensure that the caller of `test_source` is in a UTF-8 encoded file with the correct '# -*- coding: utf-8 -*-'
        marker.
 
        TZtest_id)r
rNÚ
setdefaultrXrQ)rVÚsourcerYrZr[Z
scriptfilerrrÚ test_source½szAppBuilder.test_sourceNFc
Ksæd}dd„}    |dkrg}|dkr$g}|r>|jsV| d|g¡ntj tj |¡¡d}tj |¡svtj t|j    ƒ|¡}||_
tj  |j
¡s–t d|ƒ‚|    dƒ|j |d    s¸t d
|¡|    d ƒ|j|f|||d œ|—Ž|    d ƒdS)a0
        Main method to wrap all phases of testing a Python script.
 
        :param script: Name of script to create executable from.
        :param pyi_args: Additional arguments to pass to PyInstaller when creating executable.
        :param app_name: Name of the executable. This is equivalent to argument --name=APPNAME.
        :param app_args: Additional arguments to pass to
        :param runtime: Time in seconds how long to keep executable running.
        :param toc_log: List of modules that are expected to be bundled with the executable.
        TcSs"td|dƒtd|dtjddS)Nz-------)Úfile)Úprintr$Ústderr)ÚlinerrrÚmarkeræs z&AppBuilder.test_script.<locals>.markerNz--namerzScript %s not found.zStarting build.)rYzBuilding of %s failed.z'Build finished, now running executable.)rYÚruntimeÚ run_from_pathzRunning executable finished.)rUÚextendr1rÚsplitextÚbasenameÚisabsr9rrOÚscriptÚexistsÚAssertionErrorÚ_test_buildingr&ÚfailÚ_test_executables)
rVrkÚpyi_argsZapp_nameZapp_argsrerfrZr[rdrrrrX×s(   zAppBuilder.test_scriptc     Ks°d}| |¡}|gkstdƒ‚|D]ˆ}tj t|jƒtj tj |¡¡dd¡}    tj     |    ¡rx| 
||    ¡sxt   d|¡|  ||||¡}
|
| dd¡kr"t   d||
f¡q"dS)    a`
        Run created executable to make sure it works.
 
        Multipackage-tests generate more than one exe-file and all of them have to be run.
 
        :param args: CLI options to pass to the created executable.
        :param runtime: Time in seconds how long to keep the executable running.
 
        :return: Exit code of the executable.
        TzNo executable file was found.rz.toczMatching .toc of %s failed.Úretcodez*Running exe %s failed with return-code %s.N)Ú_find_executablesrmr1rr9r<rOrhrirlÚ_examine_executabler&roÚ_run_executableÚget) rVrrYrerfrZr[ÚexesÚexeÚtoc_logrrrrrrps 
,  zAppBuilder._test_executablesc    Cs¨g}tj |j||¡}tj |j|¡}|||d|dg}trLdd„|Dƒ}trttj |j|ddd|¡}| |¡|D]*}t |¡D]}tj |¡r†| |¡q†qx|S)ac
        Search for all executables generated by the testcase.
 
        If the test-case is called e.g. 'test_multipackage1', this is searching for each of 'test_multipackage1.exe'
        and 'multipackage1_?.exe' in both one-file- and one-dir-mode.
 
        :param name: Name of the executable to look for.
 
        :return: List of executables
        z_?cSsg|] }|d‘qS)z.exer)rÚptrrrÚ
<listcomp>6sz0AppBuilder._find_executables.<locals>.<listcomp>z.appZContentsZMacOS)    r1rr9rSrrÚappendÚglobÚisfile)    rVrrwZ    onedir_ptZ
onefile_ptÚpatternsrzÚpatternÚprogrrrrss$ ú    
 zAppBuilder._find_executablesc    Cs¶t tj¡}d|d<|d=tr2tj t ¡¡|d<|}|rvt    |j
ƒ}tj   |¡}tj |  dd¡tj  |¡g¡|d<n$tj  |¡}tj  tjtj   |¡¡}|g|}| |||||¡S)z}
        Run executable created by PyInstaller.
 
        :param args: CLI options to pass to the created executable.
        ÚÚPATH)ÚcopyÚdeepcopyr1ÚenvironrÚpathsepr9r Zget_system_pathrQrNrrirvr2ÚcurdirÚ_run_executable_)    rVrrYrfreÚprog_envÚexe_pathÚprog_cwdZ    prog_namerrrruCs 
 & 
zAppBuilder._run_executablec stj||tjtj||d‰‡fdd„}|dt|ƒdt|ƒƒz&|rF|nt}ˆj|d\}}    ˆj}
Wn€tjtjfk
râ|r„d}
nd}
|d    |›d
ƒt    ˆj
d d ƒˆgD]"} t tj ƒ|   ¡W5QRXq®ˆ ¡\}}    YnXtjj |¡tjj |    ¡|
S) N)Ú
executableÚstdoutrbÚenvÚcwdcs tdtˆjƒdf|žŽdS)Nú[z] )rarQÚpid)Útext©ÚprocessrrÚ_msgjsz)AppBuilder._run_executable_.<locals>._msgz    RUNNING: z, args: )Útimeoutréz-TIMED OUT while running executable (timeout: z sec)!T)Ú    recursive)ÚpsutilÚPopenÚ
subprocessÚPIPEÚreprÚ _EXE_TIMEOUTÚ communicateÚ
returncodeÚTimeoutExpiredÚlistÚchildrenrZ NoSuchProcessÚkillr$rŽÚbufferÚwriterb) rVrYr‹rŠrŒrer–r—rŽrbrrÚprr”rr‰es4ÿ  
 zAppBuilder._run_executable_c Cs¬|jrd|jd|jdg}nPddd|jd|jd|jdt|jƒdg }|jdkrV| d    ¡n|jd
krj| d ¡|jg||}t    j
d d }t |j ƒ|d<t  ||¡d}|dkS)z¥
        Run building of test script.
 
        :param args: additional CLI options for PyInstaller.
 
        Return True if build succeeded False otherwise.
        z
--distpathz
--workpathz--log-level=INFOz--debug=bootloaderz--noupxz
--specpathz--pathÚonedirz--onedirÚonefilez    --onefileN)Zupx_dirZcachedirr)rUrSrTrRr;rOrPr|rkrZ
get_configrQrNÚpyi_mainÚrun)rVrYZ default_argsrqZ
PYI_CONFIGrrrrrrnŠs:ýù
 
 
  zAppBuilder._test_buildingc
    Csªtd|ƒt|ƒ}t|dƒ}t| ¡ƒ}W5QRX| ¡g}|D]@}|D]"}t ||¡rLtd|d|ƒqDqL| |¡td|ƒqD|r¦|D]}    td|    d|ƒqŽdSd    S)
z{
        Compare log files (now used mostly by multipackage test_name).
 
        :return: True if .toc files match
        zEXECUTING MATCHING:ÚrzMATCH:z-->zMISSING:ZMissingÚinFT)    rar    ÚopenÚevalÚreadÚsortÚreÚmatchr|)
rVrxryZ
fname_listÚfZ pattern_listÚmissingr€ÚfnameÚmrrrrtµs$
 
 zAppBuilder._examine_executable)NNNNF) rIÚ
__module__Ú __qualname__rWr\r_rXrprsrur‰rnrtrrrrrK©s    
ÿ
.%"%+rKÚsession)ZscopecCs$ddlm}|j |j¡tƒdS)Nr)ZPyInstaller.logÚlogÚloggerÚsetLevelÚDEBUGr)ÚloggingrrrÚ pyi_modgraph×s rÁr©rª)Úparamsccsx| dtjd¡| d¡| |¡| ddgi¡t|||jƒVtrt|j    j
j rt|j    j j rt|  ¡rt|jddddS)NrƒúPyInstaller.config.CONFÚpathexr˜T)ZrecÚ ignore_errors)Úsetenvr1r†Úsyspath_prependÚchdirr,rKÚparamÚ_PYI_BUILDER_CLEANUPÚnodeZ    rep_setupZpassedZrep_callrlÚremove)rDÚ monkeypatchrrÁrrrÚ pyi_builderás
 
rÎcCsB| dtjd¡| |¡| d¡| ddgi¡t||dƒS)NrƒrÃrÄ)rÆr1r†rÈrÇr,rK)rDrrÍrÁrrrÚpyi_builder_specös
 
 
rÏc Cst|d|ƒ}| ¡}zútrˆ| d¡}tdkr0dnd}tjd|ddd    }|d
krúd
d lm}|ƒ}|     ¡|j
}tj|d d gdd    }nrt râ| d¡}tdkr¢dnd}    d|    d}
tj|
dd    }t j  d¡} tjd| fdd    }n| d¡}tjddd    }|d
ks tdƒ‚W5| ¡X|S)NZ ctypes_dylibzctypes_dylib.dllÚ32bitz-m32z-m64z gcc -shared z# ctypes_dylib.c -o ctypes_dylib.dllT)Úshellr)Ú MSVCCompilerz/LDzctypes_dylib.cFzctypes_dylib.dylibÚi386Úx86_64z
gcc -arch zT -Wall -dynamiclib ctypes_dylib.c -o ctypes_dylib.dylib -headerpad_max_install_namesz+install_name_tool -id %s ctypes_dylib.dylibzctypes_dylib.soz3gcc -fPIC -shared ctypes_dylib.c -o ctypes_dylib.sozCompile ctypes_dylib failed.)rFrÈrr9rrœr.Zdistutils.msvccompilerrÒZ
initializeÚccrr1rr3rm) rDrrEZold_wdÚmarchÚretrÒÚcompZcl_pathÚarchÚcmdZid_dylibrrrÚcompiled_dylibs4 
 
 
ÿ 
 
rÛ)rÎccsdd„}||_|VdS)z=A pyi_builder equivalent for testing --windowed applications.cSstj|f|•|||djS)N)rrr—)rœr¬r¡)rYr‹rŠrŒrerrrr‰;sz.pyi_windowed_builder.<locals>._run_executable_N)r‰)rÎr‰rrrÚpyi_windowed_builder3srÜ)Br„r}rÀr1r³rBrœÚ
contextlibrÚ    getLoggerÚ
addHandlerÚ NullHandlerršrr&r$rÚnormpathr9r2r3Ú__file__Z    _ROOT_DIRr|Z PyInstallerrr«rZPyInstaller.compatrrrZPyInstaller.depend.analysisrZPyInstaller.archive.readersr    ZPyInstaller.utils.testsr
ZPyInstaller.utils.win32r rŸr"r†rvrÊZfixturerrr+Zhookimplr0r6rr;r<r?rrArFrJrKrÁrÎrÏrÛrÜrrrrÚ<module> sn (       
 
 
 
 
 
 
0
 
    
 
 
+