
][\l                 @   s   d  Z  d d l m Z d d l m Z yp d d l m Z d d l m Z d d l	 m
 Z
 d d l	 m Z d d l m Z Gd	 d
   d
 e  Z d Z Wn e k
 r d Z Yn XGd d   d e  Z d S)zCdistutils.command.check

Implements the Distutils 'check' command.
    )Command)DistutilsSetupError)Reporter)Parser)frontend)nodes)StringIOc               @   s4   e  Z d  Z d d d d d d  Z d d   Z d S)	SilentReporterNr   asciireplacec          	   C   s/   g  |  _  t j |  | | | | | | |  d  S)N)messagesr   __init__)selfsourcereport_level
halt_levelstreamdebugencodingerror_handler r   -/usr/lib/python3.4/distutils/command/check.pyr      s    	zSilentReporter.__init__c             O   sB   |  j  j | | | | f  t j | d | d |  j | | | S)Nleveltype)r   appendr   system_messageZlevels)r   r   messageZchildrenkwargsr   r   r   r      s    
zSilentReporter.system_message)__name__
__module____qualname__r   r   r   r   r   r   r	      s   r	   TFc               @   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)checkz6This command checks the meta-data of the package.
    z"perform some checks on the packagemetadatamVerify meta-datarestructuredtextrEChecks if long string meta-data syntax are reStructuredText-compliantstricts(Will exit with an error if a check failsc             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_options1   s    			zcheck.initialize_optionsc             C   s   d  S)Nr   )r   r   r   r   finalize_options8   s    zcheck.finalize_optionsc             C   s   |  j  d 7_  t j |  |  S)z*Counts the number of warnings that occurs.r+   )r,   r   warn)r   msgr   r   r   r/   ;   s    z
check.warnc             C   sx   |  j  r |  j   n  |  j rM t r2 |  j   qM |  j rM t d   qM n  |  j rt |  j d k rt t d   n  d S)zRuns the command.zThe docutils package is needed.r   zPlease correct your package.N)r"   check_metadatar%   HAS_DOCUTILScheck_restructuredtextr(   r   r,   )r   r   r   r   run@   s    			z	check.runc             C   s   |  j  j } g  } x< d D]4 } t | |  o: t | |  s | j |  q q W| rt |  j d d j |   n  | j r | j s |  j d d  q n> | j	 r | j
 s |  j d d	  q n |  j d
 d d  d S)zEnsures that all required elements of meta-data are supplied.

        name, version, URL, (author and author_email) or
        (maintainer and maintainer_email)).

        Warns if any are missing.
        nameversionurlzmissing required meta-data: %sz, z)missing meta-data: if 'author' supplied, z#'author_email' must be supplied tooz-missing meta-data: if 'maintainer' supplied, z''maintainer_email' must be supplied tooz4missing meta-data: either (author and author_email) z%or (maintainer and maintainer_email) zmust be suppliedN)znamezversionr7   )distributionr"   hasattrgetattrr   r/   joinZauthorZauthor_emailZ
maintainerZmaintainer_email)r   r"   Zmissingattrr   r   r   r1   P   s$    						zcheck.check_metadatac             C   sz   |  j  j   } xd |  j |  D]S } | d j d  } | d k rQ | d } n d | d | f } |  j |  q Wd S)z4Checks if the long string fields are reST-compliant.r+   lineNz%s (line %s))r8   Zget_long_description_check_rst_datagetr/   )r   dataZwarningr=   r   r   r   r3   n   s    zcheck.check_restructuredtextc             C   s   t    } t   } t j   j   } d | _ d | _ d | _ t | | j	 | j
 d | j d | j d | j d | j } t j | | d | } | j | d  y | j | |  Wn. t k
 r | j j d d	 d
 i  f  Yn X| j S)z8Returns warnings when the provided data doesn't compile.   Nr   r   r   r   r   r+   zCould not finish the parsing. r>   r>   )r   r   r   ZOptionParserZ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   rA   source_pathparserZsettingsZreporterrD   r   r   r   r?   y   s*    									zcheck._check_rst_dataN)zmetadatar#   r$   )zrestructuredtextr&   r'   )zstrictr)   r*   )r   r   r    __doc__ZdescriptionZuser_optionsZboolean_optionsr-   r.   r/   r4   r1   r3   r?   r   r   r   r   r!   $   s     	r!   N)rI   Zdistutils.corer   Zdistutils.errorsr   Zdocutils.utilsr   Zdocutils.parsers.rstr   Zdocutilsr   r   ior   r	   r2   	Exceptionr!   r   r   r   r   <module>   s   
