Your IP : 216.73.216.196


Current Path : /opt/alt/python37/lib/python3.7/site-packages/pydocstyle/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/pydocstyle/__pycache__/config.cpython-37.opt-1.pyc

B

;��Yh�@s�dZddlZddlZddlZddlmZmZddlmZddl	m
Z
ddlmZm
Z
ddlmZmZd	d
�ZGdd�de�Zed
d�ZGdd�de�Zedd�ZdS)z)Configuration file parsing and utilities.�N)�Set�
namedtuple)�compile)�RawConfigParser�)�__version__�log)�
ErrorRegistry�conventionscs�fdd�}|S)z4Check that the configuration object was initialized.cs,|jdks|jdkrtd���|f|�|�S)Nz$using an uninitialized configuration)�
_arguments�_options�RuntimeError)�self�args�kwargs)�method��B/opt/alt/python37/lib/python3.7/site-packages/pydocstyle/config.py�
_decoratorsz%check_initialized.<locals>._decoratorr)rrr)rr�check_initializedsrc@s*eZdZdZdZdZdZdZdZe	j
ZdZdZ
d	d
�Zdd�Zd
d�Zedd��Zedd��Zdd�Zdd�Zedd��Zdd�Zdd�Zd9dd�Zed d!��Zed:d#d$��Zed%d&��Zed'd(��Zed)d*��Z ed+d,��Z!ed-d.��Z"ed/d0��Z#ed1d2��Z$ed3d4��Z%ed5d6��Z&ed7d8��Z'dS);�ConfigurationParseraResponsible for parsing configuration from files and CLI.

    There are 2 types of configurations: Run configurations and Check
    configurations.

    Run Configurations:
    ------------------
    Responsible for deciding things that are related to the user interface and
    configuration discovery, e.g. verbosity, debug options, etc.
    All run configurations default to `False` or `None` and are decided only 
    by CLI.

    Check Configurations:
    --------------------
    Configurations that are related to which files and errors will be checked.
    These are configurable in 2 ways: using the CLI, and using configuration
    files.

    Configuration files are nested within the file system, meaning that the
    closer a configuration file is to a checked file, the more relevant it will
    be. For instance, imagine this directory structure:

    A
    +-- tox.ini: sets `select=D100`
    +-- B
        +-- foo.py
        +-- tox.ini: sets `add-ignore=D100`

    Then `foo.py` will not be checked for `D100`.
    The configuration build algorithm is described in `self._get_config`.

    Note: If any of `BASE_ERROR_SELECTION_OPTIONS` was selected in the CLI, all
    configuration files will be ignored and each file will be checked for
    the error codes supplied in the CLI.

    )�
convention�select�ignorez
add-selectz
add-ignore�matchz	match-dirzignore-decorators)rrrz(?!test_).*\.pyz[^\.].*�)z	setup.cfgztox.iniz.pydocstylez.pydocstyle.iniz
.pydocstylercz.pydocstylerc.iniz.pep257)Z
pydocstyle�pep257cCs,i|_d|_d|_|_|_|��|_dS)zCreate a configuration parser.N)�_cache�_override_by_clirr�	_run_conf�_create_option_parser�_parser)rrrr�__init__WszConfigurationParser.__init__cCs|�g�\}}|�|�S)z;Return a `RunConfiguration` object set with default values.)�_parse_args�_create_run_config)r�options�_rrr�get_default_run_configuration`sz1ConfigurationParser.get_default_run_configurationcCsX|��\|_|_|jpdg|_|�|j�s0t��|�|j�|_|j|jdd�}||_dS)z�Parse the configuration.

        If one of `BASE_ERROR_SELECTION_OPTIONS` was selected, overrides all
        error codes to check and disregards any error code related
        configurations from the configuration files.

        �.F)�use_defaultsN)	r#rr�_validate_options�IllegalConfigurationr$r�_create_check_configr)r�configrrr�parseeszConfigurationParser.parsecCs|jS)z,Return the run configuration for the script.)r)rrrr�get_user_run_configurationxsz.ConfigurationParser.get_user_run_configurationc
#sdd�}dd�}x�|jD]�}tj�|�r�x�t�|�D]�\}}}|�tj�|��}||�\}�||�}	�fdd�|D�|dd�<x4|D],}
||
�r�tj�||
�}|t|j	�|	fVq�Wq4Wq|�tj�|��}||�\}}||�}	||�r|t|j	�|	fVqWdS)a�Generate files and error codes to check on each one.

        Walk dir trees under `self._arguments` and yield file names
        that `match` under each directory that `match_dir`.
        The method locates the configuration for each file name and yields a
        tuple of (filename, [error_codes]).

        With every discovery of a new configuration file `IllegalConfiguration`
        might be raised.

        cSs(t|jd�j}t|jd�j}||fS)z:Return the `match` and `match_dir` functions for `config`.�$)�rer�	match_dir)r-Z
match_funcZmatch_dir_funcrrr�_get_matches�sz<ConfigurationParser.get_files_to_check.<locals>._get_matchescSs|jrt|j�}nd}|S)z0Return the `ignore_decorators` as None or regex.N)�ignore_decoratorsr1)r-r4rrr�_get_ignore_decorators�szFConfigurationParser.get_files_to_check.<locals>._get_ignore_decoratorscsg|]}�|�r|�qSrr)�.0�dir)r2rr�
<listcomp>�sz:ConfigurationParser.get_files_to_check.<locals>.<listcomp>N)
r�os�path�isdir�walk�_get_config�abspath�join�list�
checked_codes)
rr3r5�name�root�dirs�	filenamesr-rr4�filename�	full_pathr&r)r2r�get_files_to_check}s&


z&ConfigurationParser.get_files_to_checkc
Cs�|�|�}||jkr|j|S|�|�}|dkr^tj�|�\}}|rP|�|�}q�|�|j�}nH|�	|�\}}tj�|�\}}|r�|r�|�|�}	|�
|	|�}n
|�|�}|S)a�Get a configuration for checking `node` by config discovery.
        
        Config discovery happens when no explicit config file is specified. The
        file system is searched for config files starting from the directory
        containing the file being checked, and up until the root directory of
        the project.
        
        See `_get_config` for further details.
        
        N)�
_get_node_dirr�_get_config_file_in_folderr9r:�splitr=r,r�_read_configuration_file�_merge_configuration)
r�noder:Zconfig_fileZ
parent_dir�tailr-r%�inherit�
parent_configrrr�_get_config_by_discovery�s 





z,ConfigurationParser._get_config_by_discoveryc	Cs*|jjdkr"t�d�|�|�}n�t�d|jj�tj�|jj�sTtd�	|jj���d|j
krh|j
dS|�|jj�\}}|dkr�t�d�|�
|j�}n
|�
|�}i}x8tjD].}t|j|�}t||�}|dk	r�|n|||<q�Wtf|�}|�|j|j�|jjdk	�r||j
d<n||j
|�|�<|S)a�Get and cache the run configuration for `node`.

        If no configuration exists (not local and not for the parent node),
        returns and caches a default configuration.

        The algorithm:
        -------------
        * If the current directory's configuration exists in
           `self._cache` - return it.
        * If a configuration file does not exist in this directory:
          * If the directory is not a root directory:
            * Cache its configuration as this directory's and return it.
          * Else:
            * Cache a default configuration and return it.
        * Else:
          * Read the configuration file.
          * If a parent directory exists AND the configuration file
            allows inheritance:
            * Read the parent configuration by calling this function with the
              parent directory as `node`.
            * Merge the parent configuration with the current one and
              cache it.
        * If the user has specified one of `BASE_ERROR_SELECTION_OPTIONS` in
          the CLI - return the CLI configuration with the configuration match
          clauses
        * Set the `--add-select` and `--add-ignore` CLI configurations.

        Nz&No config file specified, discovering.zUsing config file %rz=Configuration file {!r} specified via --config was not found.zVConfiguration file does not contain a pydocstyle section. Using default configuration.)rr-r�debugrRr9r:�existsr+�formatrrL�warningr,r�CheckConfiguration�_fields�getattrr�_set_add_optionsrArI)	rrNr-r%r&Zfinal_config�attrZcli_valZconf_valrrrr=�s2






zConfigurationParser._get_configcCs(tj�|�}tj�|�r|Stj�|�S)z?Return the absolute path of the directory of a filesystem node.)r9r:r>r;�dirname)rNr:rrrrIsz!ConfigurationParser._get_node_dircCsntdd�}d}d}|�|��rB|�|��rB|jjdd�}x|jjD]}|�|j�qDWtdd�|D��}|�g�\}}	|�|�}
x�|�	|
�D]�}|dkr�|�
|
|�}q�|�dd	�|jkr�t
�d
�|��q�|�d	d�}||}
|
dkr�|�|
|�}n2|
dk�r|�|
|�}n|
d
k�st�|�
|
|�}t|||�q�W|�|�}|dk	�rf|�|��sftd�|���||fS)z�Try to read and parse `path` as a configuration file.

        If the configurations were illegal (checked with
        `self._validate_options`), raises `IllegalConfiguration`.

        Returns (options, should_inherit).

        )�#�;)Zinline_comment_prefixesNTcSsg|]}|j|jp|jf�qSr)�dest�type�action)r6�orrrr86sz@ConfigurationParser._read_configuration_file.<locals>.<listcomp>rPr&�-zUnknown option '{}' ignored)�int�count�string)�
store_trueZstore_falsezin file: {})r�read�_get_section_namer!�option_listZ
option_groups�extend�dictr#r%Z
getboolean�replace�CONFIG_FILE_OPTIONSrrVrUZgetint�get�AssertionError�setattr�_fix_set_optionsr*r+)rr:�parserr%Zshould_inheritZall_options�grouprjZnew_optionsr&�section_name�optZnormalized_optZopt_type�valuerrrrL$s@	





z,ConfigurationParser._read_configuration_filecCsft�|j�}|�|�r |�|�}|�||�t|d�}x$dD]}t||�pRt||�||<q<Wtf|�S)z�Merge parent config into the child options.

        The migration process requires an `options` object for the child in
        order to distinguish between mutually exclusive codes, add-select and
        add-ignore error codes.

        )rA)rr2r4)	�copy�deepcopyrA�_has_exclusive_option�_get_exclusive_error_codesrZrlrYrW)rrQZ
child_optionsZerror_codesr�keyrrrrM[s	



z(ConfigurationParser._merge_configurationNcCs |j�||�\}}|�|�|fS)z@Parse the options using `self._parser` and reformat the options.)r!�
parse_argsrr)rr�valuesr%Z	argumentsrrrr#pszConfigurationParser._parse_argscs"t�fdd�tjD��}tf|�S)z2Create a `RunConfiguration` object from `options`.csg|]}|t�|�f�qSr)rY)r6rv)r%rrr8xsz:ConfigurationParser._create_run_config.<locals>.<listcomp>)rl�RunConfigurationrX)r%r~r)r%rr$usz&ConfigurationParser._create_run_configTcCsrd}|�|�s|r|�|�}t|d�}x@dD]8}t||�dkrV|rVt|d�|����nt||�||<q,Wtf|�S)z�Create a `CheckConfiguration` object from `options`.

        If `use_defaults`, any of the match options that are `None` will
        be replaced with their default value and the default convention will be
        set for the checked codes.

        N)rA)rr2r4zDEFAULT_{0}_RE)rz�_get_checked_errorsrlrYrU�upperrW)�clsr%r)rArr|rrrr,|s	


&z(ConfigurationParser._create_check_configcCs"x|jD]}|�|�r|SqWdS)z$Parse options from relevant section.N)�POSSIBLE_SECTION_NAMESZhas_section)r�rsrurrrri�s
z%ConfigurationParser._get_section_namecCsXtj�|�rtj�|�}x:|jD]0}t�}tj�||�}|�|�r |�|�r |Sq WdS)zkLook for a configuration file in `path`.

        If exists return its full path, otherwise None.

        N)	r9r:�isfiler\�PROJECT_CONFIG_FILESrr?rhri)r�r:�fnr-rGrrrrJ�sz.ConfigurationParser._get_config_file_in_foldercCshtt���}d}|jdk	r0|�|j�}||}n.|jdk	rH|�|j�}n|jdk	r^tt|j�}t	�
|�S)z;Extract the error codes from the selected exclusive option.N)�setr	�get_error_codesr�_expand_error_codesrrrYr
rxry)r�r%�codesrAZignoredrrrr{�s



z.ConfigurationParser._get_exclusive_error_codescCs$||�|j�O}||�|j�8}dS)z@Set `checked_codes` by the `add_ignore` or `add_select` options.N)r��
add_select�
add_ignore)r�rAr%rrrrZ�sz$ConfigurationParser._set_add_optionsc
s�tt���}t�}yLxF|D]>������s,q�fdd�|D�}|sNt�d��|�|�qWWn*tk
r�}zt|��Wdd}~XYnX|S)z0Return an expanded set of error codes to ignore.csh|]}|���r|�qSr)�
startswith)r6�code)�partrr�	<setcomp>�sz:ConfigurationParser._expand_error_codes.<locals>.<setcomp>z9Error code passed is not a prefix of any known errors: %sN)	r�r	r��stripr�warn�update�	TypeErrorr+)Z
code_partsr�Zexpanded_codesZcodes_to_add�er)r�rr��s
z'ConfigurationParser._expand_error_codescCs(|�|�}|dkr|j}|�||�|S)z6Extract the codes needed to be checked from `options`.N)r{�DEFAULT_CONVENTIONrZ)r�r%rArrrr��s

z'ConfigurationParser._get_checked_errorsc	Cs|xDt�|jd�D]2\}}t||�rt||�rt�d�||��dSqW|jrx|jtkrxt�d�|jd�	t�
����dSdS)z�Validate the mutually exclusive options.

        Return `True` iff only zero or one of `BASE_ERROR_SELECTION_OPTIONS`
        was selected.

        �z8Cannot pass both {} and {}. They are mutually exclusive.Fz1Illegal convention '{}'. Possible conventions: {}z, T)�	itertools�permutations�BASE_ERROR_SELECTION_OPTIONSrYr�errorrUrr
r?�keys)r�r%Zopt1Zopt2rrrr*�s
z%ConfigurationParser._validate_optionscst�fdd�|jD��S)z>Return `True` iff one or more exclusive options were selected.csg|]}t�|�dk	�qS)N)rY)r6rv)r%rrr8�sz=ConfigurationParser._has_exclusive_option.<locals>.<listcomp>)�anyr�)r�r%r)r%rrz�sz)ConfigurationParser._has_exclusive_optioncs�d}d}�fdd�}x.|D]&}t||�}|dk	rt||||��qWx@|D]8}t||�}|dkrdd}t|t�sv||�}t|||�qJW|S)z9Alter the set options from None/strings to sets in place.)rr)r�r�cs��t|�d��dh�S)z�Split `value_str` by the delimiter `,` and return a set.

            Removes any occurrences of '' in the set.
            Also expand error code prefixes, to avoid doing this for every
            file.

            �,r)r�r�rK)Z	value_str)r�rr�_get_setsz6ConfigurationParser._fix_set_options.<locals>._get_setNr)rYrq�
isinstancer)r�r%Zoptional_set_optionsZmandatory_set_optionsr�rvrwr)r�rrrs





z$ConfigurationParser._fix_set_optionsc	CsNddlm}m}|tdd�}|j}|ddddd	d
�|ddddd
d
�|dddddd
�|dddddd
�|ddddd
�|ddddd�||dd�}|j}|ddddd�|d ddd!d�|d"d#dd$�d%�t��d�|d&ddd'd�|d(ddd)d�|�|�|d*d+dd,�|j	�d�|d-d+dd.�|j
�d�|d/d0dd1�|j�d�|S)2z<Return an option parser to parse the command line arguments.r)�OptionParser�OptionGroupz+Usage: pydocstyle [options] [<file|dir>...])�versionZusagez-ez	--explainrgFzshow explanation of each error)ra�default�helpz-sz--sourcezshow source for each errorz-dz--debugzprint debug informationz-vz	--verbosezprint status informationz--countz&print total number of errors to stdoutz--configz<path>Nz2use given config file and disable config discovery)�metavarr�r�zError Check Optionsa�Only one of --select, --ignore or --convention can be specified. If none is specified, defaults to `--convention=pep257`. These three options select the "basic list" of error codes to check. If you wish to change that list (for example, if you selected a known convention but wish to ignore a specific error from it or add a new one) you can use `--add-[ignore/select]` in order to do so.z--selectz<codes>z�choose the basic list of checked errors by specifying which errors to check for (with a list of comma-separated error codes or prefixes). for example: --select=D101,D2z--ignorez�choose the basic list of checked errors by specifying which errors to ignore out of all of the available error codes (with a list of comma-separated error codes or prefixes). for example: --ignore=D101,D2z--conventionz<name>zgchoose the basic list of checked errors by specifying an existing convention. Possible conventions: {}.z, z--add-selectzpadd extra error codes to check to the basic list of errors previously set by --select, --ignore or --convention.z--add-ignorezsignore extra error codes by removing them from the basic list previously set by --select, --ignore or --convention.z--matchz	<pattern>z�check only files that exactly match <pattern> regular expression; default is --match='{}' which matches files that don't start with 'test_' but end with '.py'z--match-dirz�search only dirs that exactly match <pattern> regular expression; default is --match-dir='{}', which matches all dirs that don't start with a dotz--ignore-decoratorsz<decorators>z�ignore any functions or methods that are decorated by a function with a name fitting the <decorators> regular expression; default is --ignore-decorators='{0}' which does not ignore any decorated functions.)Zoptparser�r�rZ
add_optionrUr?r
Zadd_option_group�DEFAULT_MATCH_RE�DEFAULT_MATCH_DIR_RE�DEFAULT_IGNORE_DECORATORS_RE)r�r�r�rsZoptionZcheck_groupZ	add_checkrrrr "sX




z)ConfigurationParser._create_option_parser)NN)T)(�__name__�
__module__�__qualname__�__doc__rnr�r�r�r�r
rr�r�r�r"r'r.rr/rHrRr=�staticmethodrIrLrMr#r$�classmethodr,rirJr{rZr�r�r*rzrrr rrrrrsB$
	3*D7
	!rrW)rArr2r4c@seZdZdZdS)r+z(An exception for illegal configurations.N)r�r�r�r�rrrrr+~sr+r)Zexplain�sourcerS�verboserer-)r�rxr�r9�collectionsrrr1rZconfigparserrZutilsrrZ
violationsr	r
r�objectrrW�	Exceptionr+rrrrr�<module>s&	c