Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
test_windows_wrappers.cpython-313.pyc144 linesDownload Raw Back to __pycache__
1�

2`j�����SrSSKrSSKrSSKrSSKrSSKrSSKrSSKJr \RR\RS:gSS9r"SS5rS	r
"S3S\5r"SS
\5rg)a14Python Script Wrapper for Windows5=================================6 7setuptools includes wrappers for Python scripts that allows them to be8executed like regular windows programs.  There are 2 wrappers, one9for command-line programs, cli.exe, and one for graphical programs,10gui.exe.  These programs are almost identical, function pretty much11the same way, and are generated from the same source file.  The12wrapper programs are used by copying them to the directory containing13the script they are to wrap and with the same name as the script they14are to wrap.15�N)�	resources�win32zWindows only)�reasonc�4�\rSrSr\S5r\S5rSrg)�
WrapperTester�c�f�[R"[R/5nU[	5-$)N)�16subprocess�list2cmdline�sys�17executable�locals)�cls�template�18python_exes   �XD:\code\apps\devtools\python\Lib\site-packages\setuptools/tests/test_windows_wrappers.py�prep_script�WrapperTester.prep_scripts&���,�,�c�n�n�-=�>�19��&�(�"�"�c���URUR5nXR-RS5nUR	U5 SSS5 XR20-RS5n[R"S5RUR5R5nUR	U5 SSS5 g!,(df   N�=f!,(df   g=f)z�21Create a simple script, foo-script.py22 23Note that the script starts with a Unix-style '#!' line saying which24Python executable to run.  The wrapper will use this line to find the25correct Python executable.26�wN�wb�27setuptools)r�script_tmpl�script_name�open�write�wrapper_namer�files�joinpath�wrapper_source�28read_bytes)r�tmpdir�script�frs     r�
create_script�WrapperTester.create_script"s���������1�����&�
,�
,�S�
1�Q�
�G�G�F�O�2��'�'�'�
-�
-�d�
3�q�����-�6�6�s�7I�7I�J�U�U�W�A�
�G�G�A�J�4�
3�	2�
1��4�
3�s�C�0AC�29C�30C'�N)�__name__�31__module__�__qualname__�__firstlineno__�classmethodrr&�__static_attributes__r(rrrrs(���#��#����rrc�X�US;de[R"5S:XaUS3$US3$)z=A simple routine to select launcher script based on platform.)�cli�gui�ARM64z32-arm64.exez-32.exe)�platform�machine)�prefixs r�win_launcher_exer67s;���^�#�#�#�����W�$����$�$����!�!rc�~�\rSrSrSrSr\"S5r\R"S5R5rSrSr
SrS	rg33)�TestCLI�@�
foo-script.py�foo.exer0z�34        #!%(python_exe)s35        import sys36        input = repr(sys.stdin.read())37        print(sys.argv[0][-14:])38        print(sys.argv[1:])39        print(input)40        if __debug__:41            print('non-optimized')42        c�V�URU5 [US-5SSSSS/n[R"U[R[RSSS	9nURS435upEUR
SS5n[R"S
5R5nXg:Xdeg)a�44When the copy of cli.exe, foo.exe in this example, runs, it examines45the path name it was run with and computes a Python script path name46by removing the '.exe' suffix and adding the '-script.py' suffix. (For47GUI programs, the suffix '-script.pyw' is added.)  This is why we48named out script the way we did.  Now we can run out script by running49the wrapper:50 51This example was a little pathological in that it exercised windows52(MS C runtime) quoting rules:53 54- Strings containing spaces are surrounded by double quotes.55 56- Double quotes in strings need to be escaped by preceding them with57  back slashes.58 59- One or more backslashes preceding double quotes need to be escaped60  by preceding each of them with back slashes.61r;�arg1�arg 2�arg "2\"�arg 4\�	arg5 a\\bT�utf-8��stdout�stdin�text�encoding�hello62world63�
64�65��66            \foo-script.py67            ['arg1', 'arg 2', 'arg "2\\"', 'arg 4\\', 'arg5 a\\\\b']68            'hello\nworld\n'69            non-optimized70            N)71r&�strr72�Popen�PIPE�communicate�replace�textwrap�dedent�lstrip)�selfr#�cmd�procrD�_stderr�actual�expecteds        r�73test_basic�TestCLI.test_basicRs���(	
���6�"����"�#������
74�������?�?��/�/���75���*�*�+;�<��������-���?�?�
�76��&�(�	��!�!�!rc���US-nUR5 URU5 [R"US-5nUR	US-5 [US-5SSSSS/n[R"U[R[RSS	S779nURS5upgURSS
5n[R"S5R5n	X�:Xdeg)z;78Ensure that symlink for the foo.exe is working correctly.79�80script_dirr;r=r>r?r@rATrBrCrHrIrJrKN)�mkdirr&�pathlib�Path�81symlink_torLr82rMrNrOrPrQrRrS)83rTr#r]�symlinkrUrVrDrWrXrYs84          r�test_symlink�TestCLI.test_symlink�s����l�*�85��������:�&��,�,�v�	�1�2�����:�	�1�2�
���"�#������
86�������?�?��/�/���87���*�*�+;�<��������-���?�?�
�88��&�(�	��!�!�!rc	�L�URU5 [R"S5R5nUS-R	S5nURUR
U55 SSS5 [US-5/n[R"U[R[R[RSSS9nUR5upgURS	S895n[R"S5R5n	X�:Xdeg!,(df   N�=f)a�90Specifying Python Command-line Options91--------------------------------------92 93You can specify a single argument on the '#!' line.  This can be used94to specify Python options like -O, to run in optimized mode or -i95to start the interactive interpreter.  You can combine multiple96options as usual. For example, to run in optimized mode and97enter the interpreter after running the script, you could use -Oi:98a,99            #!%(python_exe)s  -Oi100            import sys101            input = repr(sys.stdin.read())102            print(sys.argv[0][-14:])103            print(sys.argv[1:])104            print(input)105            if __debug__:106                print('non-optimized')107            sys.ps1 = '---'108            r:rNr;TrB�rDrE�stderrrFrGrIrJzV109            \foo-script.py110            []111            ''112            ---113            )r&rQrRrSrrrrLr114rMrN�STDOUTrOrP)115rTr#�tmplr%rUrVrDrWrXrYs116          r�test_with_options�TestCLI.test_with_options�s���	
���6�"����117
�118��&�(�	
���&�
,�
,�S�
1�Q�
�G�G�D�$�$�T�*�+�2��6�I�%�&�'�������?�?��/�/��$�$���
119���*�*�,��������-���?�?�
�120��&�(�	��!�!�!�+2�
1�s�121!D�122D#r(N)r)r*r+r,rrr6r!rQrRrSrrZrcrjr.r(rrr8r8@sF��!�K��L�%�e�,�N��/�/�		��
�f�h��."�`#"�J."rr8c�v�\rSrSrSrSr\"S5rSr\	R"S5R5rSr
Srg	)123�TestGUI��z1124Testing the GUI Version125-----------------------126zbar-script.pywr1�bar.exez�127        #!%(python_exe)s128        import sys129        f = open(sys.argv[1], 'wb')130        bytes_written = f.write(repr(sys.argv[2]).encode('utf-8'))131        f.close()132        c	���URU5 [US-5[US-5S/n[R"U[R[R[R133SSS9nUR
5upEU(aeU(aeUS-RS5nUR5RS5nS	S	S	5 W[S5:Xdeg	!,(df   N =f)134z:Test the GUI version with the simple script, bar-script.pyroztest_output.txtz
Test ArgumentTrBrf�rb�asciiN)r&rLr135rMrNrhrOr�read�decode�repr)rTr#rUrVrDrg�f_outrXs        rrZ�TestGUI.test_basic�s������6�"�
���"�#���*�*�+��136��137�����?�?��/�/��$�$���
138���)�)�+�����z���z��(�(�
.�
.�t�
4���Z�Z�\�(�(��1�F�5���o�.�.�.�.�5�
4�s�* C$�$139C2r(N)r)r*r+r,�__doc__rr6r!rrQrR�striprrZr.r(rrrmrm�sA���140#�K�%�e�,�N��L��/�/�	���e�g��/rrm)rxr_r3r141rrQ�pytest�setuptools._importlibr�mark�skipif�142pytestmarkrr6r8rmr(rr�<module>rsm������143��
�+�
�[�[�
�
����� 7��
�
O�144���6"�U"�m�U"�p*/�m�*/r
codekingpro/portable-devtools · Team Ai