B
    0zf                 @   s   d Z ddlZdZdZdZyBddlZdZedd ej	
dD ZedkZed	kZed
kZW n  ek
rz   ddlZdZY nX dZ	dZG dd dZG dd dejZG dd dejZG dd dZdS )zImplementation of pydocstyle integration with Flake8.

pydocstyle docstrings convention needs error code and class parser for be
included as module into flake8
    NF
pydocstylec             c   s   | ]}t |V  qd S )N)int).0num r   T/home/ankuromar296_gmail_com/.local/lib/python3.7/site-packages/flake8_docstrings.py	<genexpr>   s    r   .)   r   r   )r
      r   )r
      r   pep257z1.7.0)pep257Checkerc               @   s   e Zd Zdd ZdS )_ContainsAllc             C   s   dS )NTr   )selfcoder   r   r   __contains__    s    z_ContainsAll.__contains__N)__name__
__module____qualname__r   r   r   r   r   r      s   r   c                   s(   e Zd Z fddZedd Z  ZS )EnvironErrorc                s   t  jddt| d d d S )ND998zEnvironmentError: )r   
short_desccontext)super__init__str)r   err)	__class__r   r   r   %   s    
zEnvironError.__init__c             C   s   dS )z-Return 0 as line number for EnvironmentError.r   r   )r   r   r   r   line,   s    zEnvironError.line)r   r   r   r   propertyr   __classcell__r   r   )r   r   r   $   s   r   c                   s(   e Zd Z fddZedd Z  ZS )AllErrorc                s$   t  jdt|dd d d d S )ND999
r   )r   r   r   )r   r   r   	partition)r   r   )r   r   r   r   3   s    zAllError.__init__c             C   s   dS )z?pep257.AllError does not contain line number. Return 0 instead.r   r   )r   r   r   r   r   :   s    zAllError.line)r   r   r   r   r    r   r!   r   r   )r   r   r"   2   s   r"   c               @   sb   e Zd ZdZdZe de dej Zdd Z	e
dd Ze
d	d
 Zdd Zdd Zdd ZdS )r   z*Flake8 needs a class to check python file.zflake8-docstringsz, z: c             C   s&   || _ || _t | _d|| _dS )zInitialize the checker. N)treefilenamer   ZConventionCheckercheckerjoinsource)r   r'   r(   linesr   r   r   r   F   s    
zpep257Checker.__init__c             C   s   |j ddddttjdg dd |j dddd	d
d trhddlm} |j}|j ddd|d| dd tr~|j ddddd d	S )z*Add plugin configuration option to flake8.z--docstring-conventionstoreTr   allzpydocstyle docstring convention, default 'pep257'. Use the special value 'all' to enable all codes (note: some codes are conflicting so you'll need to then exclude those).)actionparse_from_configdefaultchoiceshelpz--ignore-decoratorsNzpydocstyle ignore-decorators regular expression, default None. Ignore any functions or methods that are decorated by a function with a name fitting this regular expression. The default is not ignore any decorated functions. )r/   r0   r1   r3   r   )ConfigurationParserz--property-decoratorszconsider any method decorated with one of these decorators as a property, and consequently allow a docstring which is not in imperative mood; default is --property-decorators=''z--ignore-self-only-init
store_truez5ignore __init__ methods which only have a self param.)r/   r0   r3   )	
add_optionsortedr   conventionssupports_property_decoratorsZpydocstyle.configr4   ZDEFAULT_PROPERTY_DECORATORSsupports_ignore_self_only_init)clsparserr4   Zdefault_property_decoratorsr   r   r   add_optionsM   s8    zpep257Checker.add_optionsc             C   s<   |j | _|jrt|jnd| _tr,|j| _tr8|j| _dS )z0Parse the configuration options given to flake8.N)	Zdocstring_convention
conventionignore_decoratorsrecompiler:   property_decoratorsr;   ignore_self_only_init)r<   optionsr   r   r   parse_options   s    zpep257Checker.parse_optionsc             C   s`   i }t rd|d< tr2| jr*t| jdnd |d< tr@| j|d< | jj| j	| j
fd| ji|S )NTZignore_inline_noqa,rC   rD   r@   )supports_ignore_inline_noqar:   rC   setsplitr;   rD   r)   check_sourcer+   r(   r@   )r   Zcheck_source_kwargsr   r   r   _call_check_source   s    
z pep257Checker._call_check_sourcec          
   c   sz   yx|   D ]
}|V  qW W nX tjk
rJ } zt|V  W d d }~X Y n, tk
rt } zt|V  W d d }~X Y nX d S )N)rL   r   r"   OSErrorr   )r   r   r   r   r   _check_source   s    zpep257Checker._check_sourcec             c   sx   | j dkrt }ntj| j  ddhB }xL|  D ]@}t|tjr0|j|kr0|j d|j }|j	d|t
| fV  q0W dS )z)Use directly check() api from pydocstyle.r.   r   r#    r   N)r?   r   r   r9   rN   
isinstanceErrorr   r   r   type)r   Zchecked_codeserrormessager   r   r   run   s    

zpep257Checker.runN)r   r   r   __doc__name__version__module_namer   versionr   classmethodr>   rF   rL   rN   rU   r   r   r   r   r   @   s   9	r   )rV   rA   rH   r:   r;   r   r   rY   tuplerX   rJ   Zpydocstyle_versionImportError__all__r   rQ   r   r"   r   r   r   r   r   <module>   s*   
