U
    -c                  	   @   s   d Z ddlZddlmZ ddlmZ ee: ddlZ	ddl
Z	ddlZ	ddlZ	G dd de	jjZW 5 Q R X G dd	 d	eZdS )
zCdistutils.command.check

Implements the Distutils 'check' command.
    N   )Command)DistutilsSetupErrorc                       s&   e Zd Zd	 fdd	Zdd Z  ZS )
SilentReporterNr   asciireplacec              	      s"   g | _ t ||||||| d S N)messagessuper__init__)selfsourcereport_level
halt_levelstreamdebugencodingerror_handler	__class__ G/tmp/pip-unpacked-wheel-izj_87as/setuptools/_distutils/command/check.pyr      s    
      zSilentReporter.__init__c                 O   s8   | j ||||f tjj|f||| j| d|S )N)leveltype)r	   appenddocutilsnodessystem_messagelevels)r   r   messagechildrenkwargsr   r   r   r       s     zSilentReporter.system_message)Nr   r   r   )__name__
__module____qualname__r   r   __classcell__r   r   r   r   r      s       r   c                   @   s`   e Zd ZdZdZdddgZdddgZd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd ZdS )checkz1This command checks the meta-data of the package.z"perform some checks on the package)metadatamzVerify meta-data)restructuredtextrzEChecks if long string meta-data syntax are reStructuredText-compliant)strictsz(Will exit with an error if a check failsr'   r)   r+   c                 C   s   d| _ d| _d| _d| _dS )z Sets default values for options.r      N)r)   r'   r+   	_warningsr   r   r   r   initialize_options:   s    zcheck.initialize_optionsc                 C   s   d S r   r   r/   r   r   r   finalize_optionsA   s    zcheck.finalize_optionsc                 C   s   |  j d7  _ t| |S )z*Counts the number of warnings that occurs.r-   )r.   r   warn)r   msgr   r   r   r2   D   s    z
check.warnc              
   C   s   | j r|   | jrjdt kr\z|   W qj tk
rX } ztt|W 5 d}~X Y qjX n| jrjtd| jr| j	dkrtddS )zRuns the command.r   NzThe docutils package is needed.r   zPlease correct your package.)
r'   check_metadatar)   globalscheck_restructuredtext	TypeErrorr   strr+   r.   )r   excr   r   r   runI   s    
 z	check.runc                 C   sH   | j j}g }dD ]}t||ds|| q|rD| dd|  dS )zEnsures that all required elements of meta-data are supplied.

        Required fields:
            name, version

        Warns if any are missing.
        )nameversionNzmissing required meta-data: %sz, )distributionr'   getattrr   r2   join)r   r'   missingattrr   r   r   r4   \   s    zcheck.check_metadatac                 C   sX   | j  }| |D ]>}|d d}|dkr8|d }nd|d |}| | qdS )z4Checks if the long string fields are reST-compliant.lineNr-   z{} (line {}))r=   get_long_description_check_rst_datagetformatr2   )r   datawarningrC   r   r   r   r6   n   s    

zcheck.check_restructuredtextc              
   C   s   | j jp
d}tjj }tjjtjjjfd }d|_	d|_
d|_t||j|j|j|j|j|jd}tjj|||d}||d z||| W n: tk
r } z|jdd| d	i f W 5 d}~X Y nX |jS )
z8Returns warnings when the provided data doesn't compile.zsetup.py)
components   N)r   r   r   r   )r   rB   z!Could not finish the parsing: %s. )r=   script_namer   parsersZrstParserZfrontendOptionParserget_default_valuesZ	tab_widthZpep_referencesZrfc_referencesr   r   r   Zwarning_streamr   Zerror_encodingZerror_encoding_error_handlerr   documentZnote_sourceparseAttributeErrorr	   r   )r   rH   source_pathparsersettingsZreporterrR   er   r   r   rE   y   s4    


zcheck._check_rst_dataN)r"   r#   r$   __doc__descriptionuser_optionsboolean_optionsr0   r1   r2   r:   r4   r6   rE   r   r   r   r   r&   '   s   
r&   )rY   
contextlibcorer   errorsr   suppressImportErrorZdocutils.utilsr   Zdocutils.parsers.rstZdocutils.frontendZdocutils.nodesutilsZReporterr   r&   r   r   r   r   <module>   s   