U
    aÊ¹jk7  ã                   @   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   ú]/var/www/html/bwave/python/venv/lib/python3.8/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
¡s`t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_modeÚAssertionErrorr   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@ szt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   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)r0   úresource_file.txtZ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��4 t
 d¡dkr\tjdd	d
d� | ¡  | ¡  W 5 Q R X t| d¡jƒ}|d  ¡ s–t‚|d  ¡ s¦t‚dD ]*}t t¡� ||  ¡ rÊt‚W 5 Q R X qªt d¡ d S )Nr   ú	%PEP 517%r	   z9Python recognizes 'mypkg\.tests' as an importable package)ÚmatchZ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ÚpytestZwarnsr   r   ÚgetenvÚwarningsÚfilterwarningsÚfinalize_optionsÚrunr   Ú	build_libÚexistsr!   r,   Úxfail)r   r   r	   ÚmsgÚ	build_dirÚfr   r   r   Útest_excluded_subpackages    s*    
ýrK   z/ignore::setuptools.SetuptoolsDeprecationWarningc           	      C   sL  t j t¡ tddiƒ}| ¡  |js*t‚| d¡}| 	d¡ t
t|jƒ d¡ƒ}| ¡ s^t‚| d¡}| ¡  | d¡}t|jd�}| |d|¡ |j dd	¡ | |¡ d	|_| ¡  | ¡  | ¡  |j dd	¡ | |¡ ||_| ¡  | ¡  |j�st‚td
d„ | ¡ ƒ}|�s t‚tt|jdƒƒ t j!d¡}||k�sHt‚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	   )Zside_effectrD   Ú
data_filesNc                 S   s   |   tjd¡S )Nú/©Úreplacer   Úsep)Úxr   r   r   Ú<lambda>ÿ   ó    z(test_existing_egg_info.<locals>.<lambda>r9   rN   )"r:   r;   r%   r<   r   r=   Zinclude_package_datar!   r>   Úrun_commandÚnextr   Zegg_baseÚglobÚis_dirrC   r   rD   ÚsetattrÚ__dict__ÚpopÚreinitialize_commandZexisting_egg_info_dirZassert_calledZ
reset_mockZassert_not_calledrM   ÚmapÚget_outputsÚstrrE   rP   r   rQ   )	r   Zmonkeypatchr   rL   Úegg_info_dirr	   Zegg_info_runÚoutputsÚexampler   r   r   Útest_existing_egg_infoÎ   s:    







rc   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   )r0   zmod1.pyzmod2.py)r0   r1   Zsub1Z_sub2)r0   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sžt‚dd„ | ¡  ¡ D ƒ}||› d�d|› d	�d|› d
�d|› d�d|› d�d|› d�d|› d�dik�st‚d S )Nr   z%test%r	   TrN   c                 S   s   h | ]}|  tjd ¡’qS ©rN   rO   ©Ú.0rR   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 rg   rO   )ri   Ú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>   Zeditable_modeÚensure_finalizedrE   rP   r   rQ   r^   r!   Zget_output_mappingÚitems)r   r   r	   rE   ra   Úmappingr   r   r   Útest_get_outputs/  sH    
ù
	
þ       ùrr   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ddd	h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_infoZfoor
   )úbar.pyiúpy.typedr0   zfoo/bar.pyizfoo/py.typed)Údirectory_structureÚexpected_type_filesÚbar)rx   zmod.pyizfoo/bar/mod.pyizfoo/bar/py.typedzfoo.pyi)Ú	namespaceú__init__.pyirx   zfoo/namespace/foo.pyizfoo/__init__.pyi)Zsimple_namespaceZnested_inside_namespaceZnamespace_nested_inside_regularÚ	pyprojectrt   ru   zpypa/setuptools#4350)r+   )Zmarksrb   c                 C   sT   | j | d d| j| i–}| j | d }tj |¡ tƒ }t|ƒ}||ksPt‚d S ©Nry   rd   rz   )ÚEXAMPLESÚ
PYPROJECTSr:   r;   r%   Úget_finalized_build_pyr^   r!   ©Úselfr   r~   rb   Ú	structurerz   r	   ra   r   r   r   Ú#test_type_files_included_by_default›  s     þz5TestTypeInfoFiles.test_type_files_included_by_defaultrv   c                 C   sV   | j | d d| j| i–}| j | d }tj |¡ tƒ }t|ƒ}| |¡sRt‚d S r   )	r€   r�   r:   r;   r%   r‚   r^   Ú
isdisjointr!   rƒ   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sBt‚d S )Nzl
                [project]
                name = "foo-stubs"
                version = "1"
                r
   )r}   rw   )rd   z	foo-stubszfoo-stubs/__init__.pyizfoo-stubs/bar.pyi)r   r:   r;   r%   r‚   r^   r!   )r„   r   r…   rz   r	   ra   r   r   r   Útest_stub_only_packageÀ  s    ÿø
z(TestTypeInfoFiles.test_stub_only_packageN)Ú__name__Ú
__module__Ú__qualname__r   r�   r€   r?   ÚmarkZparametrizeÚparamrG   Úkeysr†   rˆ   r‰   r   r   r   r   rs   Q  sp   ÿÿ
ÿî$ýÿøþÿÿ÷ ÿûÿ
ýöê(þþþ
rs   ú%build_py-test%c                 C   s*   t d| iƒ}| ¡  | d¡}| ¡  |S )Nr   r	   )r   r=   r>   rC   )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 rg   )r   r;   ÚrelpathrP   rQ   rh   ©rI   r   r   rj   Ý  s   ÿzget_outputs.<locals>.<setcomp>)r   rE   r^   )r	   r   r’   r   r^   Û  s    

þr^   )r�   )!r   r(   r   rA   Úpathlibr   Zunittest.mockr   Zjaraco.pathr:   r?   Ú
setuptoolsr   Zsetuptools.distr   Útextwrapr   r   r"   r*   r�   rG   r!   r/   r<   rK   rB   rc   rn   rr   rs   r‚   r^   r   r   r   r   Ú<module>   s~   ü
ÿýý	ÿè$.

7ÿþ ÿùÿþÿß*" 
