3 \x � @ s� d Z ddlmZ ddlmZ yTddlmZ ddlmZ ddl m Z ddl mZ ddlm Z G d d � d e�ZdZW n ek r� dZY nX G d d� de�ZdS )zCdistutils.command.check Implements the Distutils 'check' command. � )�Command)�DistutilsSetupError)�Reporter)�Parser)�frontend)�nodes)�StringIOc @ s e Zd Zd dd�Zdd� ZdS ) �SilentReporterNr �ascii�replacec C s" g | _ tj| |||||||� d S )N)�messagesr �__init__)�self�source�report_level� halt_level�stream�debug�encoding� error_handler� r �//usr/lib64/python3.6/distutils/command/check.pyr s zSilentReporter.__init__c O s6 | j j||||f� tj|f|�|| j| d�|��S )N)�level�type)r �appendr �system_messageZlevels)r r �messageZchildren�kwargsr r r r s zSilentReporter.system_message)Nr r r )�__name__� __module__�__qualname__r r r r r r r s r TFc @ s` e Zd ZdZdZdddgZddd gZdd � Zdd� Zdd� Z dd� Z dd� Zdd� Zdd� Z dS )�checkz6This command checks the meta-data of the package. z"perform some checks on the package�metadata�m�Verify meta-data�restructuredtext�r�EChecks 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| _dS )z Sets default values for options.r � N)r% r" r( � _warnings)r r r r �initialize_options1 s zcheck.initialize_optionsc C s d S )Nr )r r r r �finalize_options8 s zcheck.finalize_optionsc C s | j d7 _ tj| |�S )z*Counts the number of warnings that occurs.r+ )r, r �warn)r �msgr r r r/ ; s z check.warnc C sL | j r| j� | jr0tr"| j� n| jr0td��| jrH| jdkrHtd��dS )zRuns the command.zThe docutils package is needed.r zPlease 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*dD ]"}t||�o(t||�s|j|� qW |rP| jddj|� � |jrh|js�| jd� n"|j r�|j s�| jd� n | jd� d S )z�Ensures 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�urlzmissing 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) zmust be suppliedN)r5 r6 r7 zLmissing meta-data: if 'author' supplied, 'author_email' must be supplied toozTmissing meta-data: if 'maintainer' supplied, 'maintainer_email' must be supplied toozYmissing meta-data: either (author and author_email) or (maintainer and maintainer_email) zimissing meta-data: either (author and author_email) or (maintainer and maintainer_email) must be supplied)�distributionr" �hasattr�getattrr r/ �joinZauthorZauthor_emailZ maintainerZmaintainer_email)r r" Zmissing�attrr r r r1 P s$ zcheck.check_metadatac C s\ | j j� }xL| j|�D ]>}|d jd�}|dkr:|d }nd|d |f }| j|� qW dS )z4Checks if the long string fields are reST-compliant.r+ �lineNz%s (line %s)�����)r8 Zget_long_description�_check_rst_data�getr/ )r �dataZwarningr= r r r r3 n s zcheck.check_restructuredtextc C s� t � }t� }tjtfd�j� }d|_d|_d|_t||j |j |j|j|j |jd�}tj|||d�}|j|d � y|j||� W n: tk r� } z|jjd d| di f� W Y dd}~X nX |jS )z8Returns warnings when the provided data doesn't compile.)Z components� N)r r r r )r r+ z!Could not finish the parsing: %s.� r> r> )r r r ZOptionParserZget_default_valuesZ tab_widthZpep_referencesZrfc_referencesr r r Zwarning_streamr Zerror_encodingZerror_encoding_error_handlerr �documentZnote_source�parse�AttributeErrorr r )r rA �source_path�parserZsettingsZreporterrD �er r r r? y s* $zcheck._check_rst_dataN)r" r# r$ )r% r&