o
    LK&hj7                     @   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   Q/var/www/html/venv/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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   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sJ 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*" 
