o
    5‘ðiy7  ã                   @   s@  d dl Z d dlZd dlZd dlZd dlmZ d dlmZ d dlZ	d dl
Z
d dlmZ d dlmZ ddlmZ dd	„ Zd
d„ Zdd„ Ze
jjddedd�dd„ ƒZedƒddddddœdœedƒdœZdd„ Ze
j d¡dd„ ƒZedƒd ddddd!œd"did#œiddd$œed%ƒd&œZd'd(„ ZG d)d*„ d*ƒZd0d,d-„Zd.d/„ Z dS )1é    N)ÚPath)ÚMock)ÚSetuptoolsDeprecationWarning)ÚDistributioné   )ÚDALSc                 C   s<   t tddgdgddgid�ƒ}t d¡ | ¡  | ¡  dS )z†
    Directories matching the glob in package_data should
    not be included in the package data.

    Regression test for #261.
    úsetup.pyÚbuild_pyÚ zpath/*©Úscript_nameÚscript_argsÚpackagesÚpackage_datazpath/subpathN)r   ÚdictÚosÚmakedirsÚparse_command_lineÚrun_commands©Ú
tmpdir_cwdÚdist© r   ú]/root/parts/websockify/install/lib/python3.10/site-packages/setuptools/tests/test_build_py.pyÚ%test_directories_in_package_data_glob   s   üÿ
r   c                 C   sd   t tddgdgddgid�ƒ}t d¡ tddƒ ¡  | ¡  | ¡  t 	t d	¡j
¡s0J d
ƒ‚dS )zt
    Files matching recursive globs (**) in package_data should
    be included in the package data.

    #1806
    r   r	   r
   zpath/**/datar   zpath/subpath/subsubpathzpath/subpath/subsubpath/dataÚwbz&build/lib/path/subpath/subsubpath/datazFile is not includedN)r   r   r   r   ÚopenÚcloser   r   ÚstatÚS_ISREGÚst_moder   r   r   r   Ú#test_recursive_in_package_data_glob%   s   üÿ
ÿr!   c                 C   s~   t tddgdgddgid�ƒ}t d¡ tddƒ ¡  tddƒ ¡  t dtj¡ t dtj¡ | 	¡  | 
¡  t d	¡ d
S )z·
    Ensure read-only flag is not preserved in copy
    for package modules and package data, as that
    causes problems with deleting read-only files on
    Windows.

    #1451
    r   r	   Úpkgzdata.datr   úpkg/__init__.pyr   zpkg/data.datÚbuildN)r   r   r   r   r   r   Úchmodr   ÚS_IREADr   r   ÚshutilÚrmtreer   r   r   r   Útest_read_only?   s    	üÿ
r)   zplatform.system() == "Windows"z-On Windows, files do not have executable bitsT)ÚreasonÚraisesÚstrictc                 C   s~   t tddgdgddgid�ƒ}t d¡ tddƒ ¡  tddƒ ¡  t dd	¡ | ¡  | ¡  t 	d
¡j
t	j@ s=J dƒ‚dS )zv
    Ensure executable bit is preserved in copy for
    package data, as users rely on it for scripts.

    #2041
    r   r	   r"   zrun-mer   r#   r   z
pkg/run-meiÀ  zbuild/lib/pkg/run-mezScript is not executableN)r   r   r   r   r   r   r%   r   r   r   r    ÚS_IEXECr   r   r   r   Útest_executable_dataZ   s"   üÿ
ÿr.   zÒ
        [metadata]
        name = mypkg
        version = 42

        [options]
        include_package_data = True
        packages = find:

        [options.packages.find]
        exclude = *.tests*
        r
   )ú__init__.pyztest_mypkg.pyztest_file.txt)r/   úresource_file.txtÚtestszŒ
        global-include *.py *.txt
        global-exclude *.py[cod]
        prune dist
        prune build
        prune *.egg-info
        )z	setup.cfgÚmypkgúMANIFEST.inc              	   C   s  t j t¡ tddiƒ}| ¡  | d¡}d}tjt	|d�� t
 d¡dkr.tjdd	d
d� | ¡  | ¡  W d   ƒ n1 s@w   Y  t| d¡jƒ}|d  ¡ sUJ ‚|d  ¡ s]J ‚dD ]}t t¡� ||  ¡ roJ ‚W d   ƒ n1 syw   Y  q_t d¡ d S )Nr   ú	%PEP 517%r	   z9Python recognizes 'mypkg\.tests' as an importable package)ÚmatchÚSETUPTOOLS_USE_DISTUTILSÚstdlibÚignorez!'encoding' argument not specifiedzdistutils.text_file)Úmoduleúmypkg/__init__.pyzmypkg/resource_file.txt)zmypkg/tests/__init__.pyzmypkg/tests/test_mypkg.pyzmypkg/tests/test_file.txtzmypkg/testsz#3260)ÚjaracoÚpathr$   ÚEXAMPLE_WITH_MANIFESTr   Úparse_config_filesÚget_command_objÚpytestÚwarnsr   r   ÚgetenvÚwarningsÚfilterwarningsÚfinalize_optionsÚrunr   Ú	build_libÚexistsr+   ÚAssertionErrorÚxfail)r   r   r	   ÚmsgÚ	build_dirÚfr   r   r   Útest_excluded_subpackages    s0   
ý
ðý€rN   z/ignore::setuptools.SetuptoolsDeprecationWarningc           	      C   sF  t j t¡ tddiƒ}| ¡  |jsJ ‚| d¡}| d¡ t	t
|jƒ d¡ƒ}| ¡ s/J ‚| d¡}| ¡  | d¡}t|jd�}| |d|¡ |j dd	¡ | |¡ d	|_| ¡  | ¡  | ¡  |j dd	¡ | |¡ ||_| ¡  | ¡  |js�J ‚td
d„ | ¡ ƒ}|sŽJ ‚tt
|jdƒƒ tj d¡}||v s¡J ‚d	S )zwWhen provided with the ``existing_egg_info_dir`` attribute, build_py should not
    attempt to run egg_info again.
    r   r4   Úegg_infoz
*.egg-infor	   )Úside_effectrF   Ú
data_filesNc                 S   s   |   tjd¡S )Nú/©Úreplacer   Úsep)Úxr   r   r   Ú<lambda>ÿ   s    z(test_existing_egg_info.<locals>.<lambda>r:   rR   )!r;   r<   r$   r=   r   r>   Úinclude_package_datar?   Úrun_commandÚnextr   Úegg_baseÚglobÚis_dirrE   r   rF   ÚsetattrÚ__dict__ÚpopÚreinitialize_commandÚexisting_egg_info_dirÚassert_calledÚ
reset_mockÚassert_not_calledrQ   ÚmapÚget_outputsÚstrrG   rT   r   rU   )	r   Úmonkeypatchr   rO   Úegg_info_dirr	   Úegg_info_runÚoutputsÚexampler   r   r   Útest_existing_egg_infoÎ   s:   







rn   a;  
        [project]
        name = "mypkg"
        version = "42"

        [tool.setuptools]
        packages = ["mypkg", "mypkg.sub1", "mypkg.sub2", "mypkg.sub2.nested"]

        [tool.setuptools.package-dir]
        "" = "src"
        "mypkg.sub2" = "src/mypkg/_sub2"
        "mypkg.sub2.nested" = "other"
        r2   )r/   zmod1.pyzmod2.py)r/   r0   Úsub1Ú_sub2)r/   zmod3.pyzL
        global-include *.py *.txt
        global-exclude *.py[cod]
        )úpyproject.tomlÚsrcÚotherr3   c                 C   s
  t j t¡ tddiƒ}| ¡  | d¡}d|_| ¡  |j	 
tjd¡}dd„ | ¡ D ƒ}||› d�|› d	�|› d
�|› d�|› d�|› d�|› d�hksOJ ‚dd„ | ¡  ¡ D ƒ}||› d�d|› d	�d|› d
�d|› d�d|› d�d|› d�d|› d�diksƒJ ‚d S )Nr   z%test%r	   TrR   c                 S   s   h | ]	}|  tjd ¡’qS ©rR   rS   ©Ú.0rV   r   r   r   Ú	<setcomp>8  s    z#test_get_outputs.<locals>.<setcomp>z/mypkg/__init__.pyz/mypkg/resource_file.txtz/mypkg/sub1/__init__.pyz/mypkg/sub1/mod1.pyz/mypkg/sub2/mod2.pyz/mypkg/sub2/nested/__init__.pyz/mypkg/sub2/nested/mod3.pyc                 S   s*   i | ]\}}|  tjd ¡|  tjd ¡“qS rt   rS   )rv   ÚkÚvr   r   r   Ú
<dictcomp>B  s    ÿÿz$test_get_outputs.<locals>.<dictcomp>zsrc/mypkg/__init__.pyzsrc/mypkg/resource_file.txtzsrc/mypkg/sub1/__init__.pyzsrc/mypkg/sub1/mod1.pyzsrc/mypkg/_sub2/mod2.pyzother/__init__.pyzother/mod3.py)r;   r<   r$   ÚEXAMPLE_ARBITRARY_MAPPINGr   r>   r?   Úeditable_modeÚensure_finalizedrG   rT   r   rU   rg   Úget_output_mappingÚitems)r   r   r	   rG   rl   Úmappingr   r   r   Útest_get_outputs/  s:   

ù	
þ






ùr�   c                	   @   sê   e Zd ZedƒedƒedƒdœZdddddœidd	hd
œdddddœiiddhd
œdddidddœih d£d
œdœZej ddej	dejj
dd�d�g¡ej de ¡ ¡dd„ ƒƒZej ddg¡ej de ¡ ¡dd„ ƒƒZdd „ Zd!S )"ÚTestTypeInfoFileszV
            [project]
            name = "foo"
            version = "1"
            zž
            [project]
            name = "foo"
            version = "1"

            [tool.setuptools]
            include-package-data = false
            zú
            [project]
            name = "foo"
            version = "1"

            [tool.setuptools]
            include-package-data = false

            [tool.setuptools.exclude-package-data]
            "*" = ["py.typed", "*.pyi"]
            )Údefault_pyprojectÚdont_include_package_dataÚexclude_type_infoÚfoor
   )úbar.pyiúpy.typedr/   zfoo/bar.pyiúfoo/py.typed)Údirectory_structureÚexpected_type_filesÚbar)rˆ   zmod.pyizfoo/bar/mod.pyizfoo/bar/py.typedzfoo.pyi)Ú	namespaceú__init__.pyirˆ   >   úfoo/__init__.pyiúfoo/namespace/foo.pyir‰   )Úsimple_namespaceÚnested_inside_namespaceÚnamespace_nested_inside_regularÚ	pyprojectrƒ   r„   zpypa/setuptools#4350)r*   )Úmarksrm   c                 C   sX   i | j | d ¥d| j| i¥}| j | d }tj |¡ tƒ }t|ƒ}||ks*J ‚d S ©NrŠ   rq   r‹   )ÚEXAMPLESÚ
PYPROJECTSr;   r<   r$   Úget_finalized_build_pyrg   ©Úselfr   r”   rm   Ú	structurer‹   r	   rl   r   r   r   Ú#test_type_files_included_by_default›  s   ÿ
þz5TestTypeInfoFiles.test_type_files_included_by_defaultr…   c                 C   sZ   i | j | d ¥d| j| i¥}| j | d }tj |¡ tƒ }t|ƒ}| |¡s+J ‚d S r–   )r—   r˜   r;   r<   r$   r™   rg   Ú
isdisjointrš   r   r   r   Útest_type_files_can_be_excluded²  s   ÿ
þz1TestTypeInfoFiles.test_type_files_can_be_excludedc                 C   sF   t dƒdddœdœ}ddh}tj |¡ tƒ }t|ƒ}||ks!J ‚d S )Nzl
                [project]
                name = "foo-stubs"
                version = "1"
                r
   )rŽ   r‡   )rq   z	foo-stubszfoo-stubs/__init__.pyizfoo-stubs/bar.pyi)r   r;   r<   r$   r™   rg   )r›   r   rœ   r‹   r	   rl   r   r   r   Útest_stub_only_packageÀ  s   ÿø
z(TestTypeInfoFiles.test_stub_only_packageN)Ú__name__Ú
__module__Ú__qualname__r   r˜   r—   r@   ÚmarkÚparametrizeÚparamrJ   Úkeysr�   rŸ   r    r   r   r   r   r‚   Q  sj    ÿÿ
ÿî$ýÿøþÿÿ÷ÿûÿ	öê(þþþ
r‚   ú%build_py-test%c                 C   s*   t d| iƒ}| ¡  | d¡}| ¡  |S )Nr   r	   )r   r>   r?   rE   )r   r   r	   r   r   r   r™   Ó  s
   
r™   c                    s    t | jƒ‰ ‡ fdd„|  ¡ D ƒS )Nc                    s$   h | ]}t j |ˆ ¡ t jd ¡’qS rt   )r   r<   ÚrelpathrT   rU   ru   ©rL   r   r   rw   Ý  s    ÿÿzget_outputs.<locals>.<setcomp>)r   rG   rg   )r	   r   rª   r   rg   Û  s   

þrg   )r¨   )!r   r'   r   rC   Úpathlibr   Úunittest.mockr   Újaraco.pathr;   r@   Ú
setuptoolsr   Úsetuptools.distr   Útextwrapr   r   r!   r)   r¤   rJ   rI   r.   r=   rN   rD   rn   r{   r�   r‚   r™   rg   r   r   r   r   Ú<module>   s~    ü
ÿýý	ÿè$
.
7ÿþÿùÿþÿß*" 
