U
    ui                     @   s   d Z ddlZddlZddlZddlZddlZddlmZ ddlZddl	Z	ddl
mZ ddlmZ eejjddZG d	d
 d
ZG dd dZdd Zdd ZdS )z$Test .dist-info style distributions.    N)partial)unpack_archive   )DALSutf-8encodingc                   @   sd   e Zd ZedZedd Zejdd Z	dd Z
dd	 Zd
d Zdd Zejdddd ZdS )TestDistInfoz
        Metadata-Version: 1.2
        Requires-Dist: splort (==4)
        Provides-Extra: baz
        Requires-Dist: quux (>=1.1); extra == 'baz'
        c                 K   s"   dd |  D }| jd| S )Nc                 s   s    | ]\}}d j f t V  qdS )z{key}: {value}
N)formatlocals).0keyvalue r   C/tmp/pip-unpacked-wheel-9osl9suo/setuptools/tests/test_dist_info.py	<genexpr>    s     z.TestDistInfo.build_metadata.<locals>.<genexpr> )itemsmetadata_basejoin)clskwargslinesr   r   r   build_metadata   s    zTestDistInfo.build_metadatac                 C   sv   d}|| }|   |d }| jdd}|j|dd d}|| }|   |d }| jdd	d
}|j|dd t|S )Nz%VersionedDistribution-2.718.dist-infoMETADATAVersionedDistribution)Namer   r   z!UnversionedDistribution.dist-infoUnversionedDistribution0.3)r   Version)mkdirr   
write_textstr)selfZtmpdirZdist_info_name	versionedfilenamecontentunversionedr   r   r   metadata#   s$    zTestDistInfo.metadatac                 C   s\   t dd t|D }t|dks,t||d }|d }|jdksJt|jdksXtd S )Nc                 s   s   | ]}|j |fV  qd S N)project_name)r   dr   r   r   r   ;   s    z-TestDistInfo.test_distinfo.<locals>.<genexpr>   r   r   z2.718r   )dictpkg_resourcesfind_distributionslenAssertionErrorversion)r#   r(   distsr'   r$   r   r   r   test_distinfo:   s    zTestDistInfo.test_distinfoc                 C   sv   d}t ttjj|}t|D ]P}| |d d ks<t|jdd|d tjdgks`t|jdgks tq d S )N)z	splort==4z	quux>=1.1r   )baz)extrasr   zquux>=1.1;extra=="baz"r5   )	listmapr.   Requirementparser/   requiresr1   r6   )r#   r(   specsr;   r+   r   r   r   test_conditional_dependenciesG   s    


z*TestDistInfo.test_conditional_dependenciesc                 C   sh   d}|d j |dd tdtjtjB }td|dd}|jsBt||j	sRtt
|d	rdtd
S )zA
        Supplying an invalid version crashes dist_info.
        z@[metadata]
name=proj
version=42
[egg_info]
tag_build=invalid!!!
	setup.cfgr   r   zinvalid version	dist_infoF)cwdcheck*.dist-infoN)r!   recompileMIrun_command_inner
returncoder1   searchstdoutr7   glob)r#   tmp_pathconfigmsgprocr   r   r   test_invalid_versionS   s    
z!TestDistInfo.test_invalid_versionc                 C   s   d}|d j |dd ttdd|d t|d}|jd	sFtt	| ttdd
d|d t|d}|jdstd S )Nz
        [metadata]
        name=proj
        version=42
        [egg_info]
        tag_date=1
        tag_build=.post
        r>   r   r   r?   z	--no-dater@   rB   zproj-42z--tag-buildz.azproj-42a)
r!   printrun_commandnextrK   name
startswithr1   shutilrmtree)r#   rL   rM   r?   r   r   r   test_tag_arguments_   s    
zTestDistInfo.test_tag_argumentskeep_egg_info)FTc                 C   s   d}|d j |dd |d }|  |r0dgng }tdd|f|d	|i tt|d
dksfttt|d
dkstt|}tt|d|ksttt|ddksttt|ddksttt|ddkstd S )Nz [metadata]
name=proj
version=42
r>   r   r   Z__outz--keep-egg-infor?   z--output-dirr@   rB   r   r   z
*.egg-infoz	*.__bkp__)r!   r    rS   r0   r7   rK   r1   int)r#   rL   rZ   rM   outoptsZexpected_egg_infor   r   r   test_output_dirs   s    zTestDistInfo.test_output_dirN)__name__
__module____qualname__r   r   classmethodr   pytestZfixturer(   r4   r=   rP   rY   markparametrizer^   r   r   r   r   r	      s   	

r	   c                   @   sd   e Zd ZdZedZddddddd	d
gZej	dd
 ej	ddgej	dedd ZdS )TestWheelCompatibilityzMake sure the .dist-info directory produced with the ``dist_info`` command
    is the same as the one produced by ``bdist_wheel``.
    ae  
    [metadata]
    name = {name}
    version = {version}

    [options]
    install_requires =
        foo>=12; sys_platform != "linux"

    [options.extras_require]
    test = pytest

    [options.entry_points]
    console_scripts =
        executable-name = my_package.module:function
    discover =
        myproj = my_package.other_module:function
    )r   r   ).postz[egg_info]
tag_build = post
)rg   z[egg_info]
tag_build = .post
)rg   z)[egg_info]
tag_build = post
tag_date = 1
).devz[egg_info]
tag_build = .dev
)rh   z)[egg_info]
tag_build = .dev
tag_date = 1
)Za1z[egg_info]
tag_build = .a1
)z+localz[egg_info]
tag_build = +local
rU   zmy-proj my_proj my.proj My.Projr2   z0.42.13zsuffix, cfgc                 C   s   | j j||d| }dD ]&}||   || d j|dd qtd|d d t|d	}t||d
  t|d}	td|d d t|d}
|
j|	jkst	|
j
d| | st	dD ] }t|
| t|	| kst	qd S )N)rU   r2   )	dir_wheeldir_distr>   r   r   bdist_wheelri   rQ   zdir_wheel/dist/*.whlunpackzunpack/*.dist-infor?   rj   zdir_dist/*.dist-infozmy_proj-)r   zentry_points.txt)SETUPCFGr
   r    r!   rS   rT   rK   r   rU   r1   rV   read)r#   rU   r2   rL   suffixcfgrM   iwheelZwheel_dist_infor?   filer   r   r   &test_dist_info_is_the_same_as_in_wheel   s    z=TestWheelCompatibility.test_dist_info_is_the_same_as_in_wheelN)r_   r`   ra   __doc__r   rm   ZEGG_INFO_OPTSrc   rd   re   splitrt   r   r   r   r   rf      s"   rf   c                  O   s<   t jt jdddd|}tjddftt| } t j| f|S )NTr   )stderrrJ   textr   rA   z-cz __import__('setuptools').setup())
subprocessSTDOUTPIPEsys
executabler8   r"   run)cmdr   r]   r   r   r   rG      s    rG   c                  O   s   t | |jS r)   )rG   rJ   )argsr   r   r   r   rS      s    rS   )ru   pathlibrC   rW   ry   r|   	functoolsr   rc   r.   Zsetuptools.archive_utilr   textwrapr   Path	read_textrn   r	   rf   rG   rS   r   r   r   r   <module>   s   p@