o
    Zhk7                     @   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_nameZscript_argspackagespackage_datazpath/subpathN)r   dictosmakedirsparse_command_linerun_commands
tmpdir_cwddist r   U/var/www/html/lang_env/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.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 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pytestZ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   

rK   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sJ td
d | }|sJ tt
|jdtj d}||v sJ d	S )zwWhen provided with the ``existing_egg_info_dir`` attribute, build_py should not
    attempt to run egg_info again.
    r   r2   egg_infoz
*.egg-infor	   )Zside_effectrC   
data_filesNc                 S   s   |  tjdS )N/replacer   sep)xr   r   r   <lambda>   s    z(test_existing_egg_info.<locals>.<lambda>r8   rN   )!r9   r:   r#   r;   r   r<   Zinclude_package_datar=   run_commandnextr   Zegg_baseglobis_dirrB   r   rC   setattr__dict__popZreinitialize_commandZexisting_egg_info_dirZassert_calledZ
reset_mockZassert_not_calledrM   mapget_outputsstrrD   rP   r   rQ   )	r   Zmonkeypatchr   rL   egg_info_dirr	   Zegg_info_runoutputsexampler   r   r   test_existing_egg_info   s:   







ra   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"
        r0   )r.   zmod1.pyzmod2.py)r.   r/   Zsub1Z_sub2)r.   zmod3.pyzL
        global-include *.py *.txt
        global-exclude *.py[cod]
        )pyproject.tomlsrcotherr1   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sJ 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 re   rO   )rg   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)r9   r:   r#   EXAMPLE_ARBITRARY_MAPPINGr   r<   r=   Zeditable_modeZensure_finalizedrD   rP   r   rQ   r\   Zget_output_mappingitems)r   r   r	   rD   r_   mappingr   r   r   test_get_outputs/  s:   

	







ro   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_infoZfoor
   )bar.pyipy.typedr.   zfoo/bar.pyifoo/py.typed)directory_structureexpected_type_filesbar)ru   zmod.pyizfoo/bar/mod.pyizfoo/bar/py.typedzfoo.pyi)	namespace__init__.pyiru   >   zfoo/__init__.pyirv   zfoo/namespace/foo.pyi)Zsimple_namespaceZnested_inside_namespaceZnamespace_nested_inside_regular	pyprojectrq   rr   zpypa/setuptools#4350)r)   )Zmarksr`   c                 C   sX   i | j | d d| j| i}| j | d }tj| t }t|}||ks*J d S Nrw   rb   rx   )EXAMPLES
PYPROJECTSr9   r:   r#   get_finalized_build_pyr\   selfr   r|   r`   	structurerx   r	   r_   r   r   r   #test_type_files_included_by_default  s   
z5TestTypeInfoFiles.test_type_files_included_by_defaultrs   c                 C   sZ   i | j | d d| j| i}| j | d }tj| t }t|}||s+J d S r}   )r~   r   r9   r:   r#   r   r\   
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{   rt   )rb   z	foo-stubszfoo-stubs/__init__.pyizfoo-stubs/bar.pyi)r   r9   r:   r#   r   r\   )r   r   r   rx   r	   r_   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   rp   Q  sj    
$	(
rp   %build_py-test%c                 C   s*   t d| i}|  |d}|  |S )Nr   r	   )r   r<   r=   rB   )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 re   )r   r:   relpathrP   rQ   rf   rI   r   r   rh     s    zget_outputs.<locals>.<setcomp>)r   rD   r\   )r	   r   r   r   r\     s   

r\   )r   )!r   r&   r   r@   pathlibr   Zunittest.mockr   Zjaraco.pathr9   r>   
setuptoolsr   Zsetuptools.distr   textwrapr   r   r    r(   r   rG   rF   r-   r;   rK   rA   ra   rl   ro   rp   r   r\   r   r   r   r   <module>   s~    
	$
.
7*" 
