3 \x � @ s� d dl mZ d dlmZ yTd dlmZ d dlmZ d dlm Z d dlm Z d dlmZ G dd � d e�Z d ZW n ek r� dZY nX G dd � d e�ZdS )� )�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 ZdZdddgZdddgZdd� Zd d� Zdd� Zdd� Z dd� Z dd� Zdd� ZdS )�checkz"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| _d S )Nr � )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 )Nr+ )r, r �warn)r �msgr r r r/ ; s z check.warnc C sL | j r| j� | jr0tr"| j� n| jr0td��| jrH| jdkrHtd��d S )NzThe docutils package is needed.r zPlease correct your package.)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 ]"}t||�o(t||�s|j|� qW |rP| jddj|� � |jrh|js�| jd� n"|j r�|j s�| jd� n | jd� d S )N�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 supplied)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�}|d kr:|d }nd|d |f }| j|� qW d S )Nr+ �linez%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 d d }~X nX |jS ) N)Z components� )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&