o
    tBh@                  
   @   s   d Z ddlZddlZzddlZW n ey   ddlZY nw ddlmZ ddg g g g dddd	ZG dd	 d	e	Z
d
d Zdd Zdd ZdddZdddZdS )zz
This module handles retrieval of configuration values from either the
command-line arguments or the pyproject.toml file.
    N   )__version__pyproject.tomlF)	configmin_confidencepathsexcludeignore_decoratorsignore_namesmake_whitelistsort_by_sizeverbosec                   @   s   e Zd Zdd ZdS )
InputErrorc                 C   s
   || _ d S N)message)selfr    r   e/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/vulture/config.py__init__      
zInputError.__init__N)__name__
__module____qualname__r   r   r   r   r   r      s    r   c                 C   sb   |   D ]*\}}|tvrtd| t|tt| ur.tt| j}td| d|qdS )z
    Checks the types of the values in *data* against the expected types of
    config-values. If a value has the wrong type, raise an InputError.
    zUnknown configuration key: zData type for z	 must be N)itemsDEFAULTSr   typer   )datakeyvalueexpected_typer   r   r   _check_input_config"   s   r    c                 C   s   | d st ddS )z
    Run sanity checks on the generated config after all parsing and
    preprocessing is done.

    Raise InputError if an error is encountered.
    r   z*Please pass at least one file or directoryN)r   )r   r   r   r   _check_output_config1   s   r!   c                 C   s*   t | }|di di }t| |S )a  
    Parse a TOML file for config values.

    It will search for a section named ``[tool.vulture]`` which contains the
    same keys as the CLI arguments seen with ``--help``. All leading dashes are
    removed and other dashes are replaced by underscores (so ``--sort-by-size``
    becomes ``sort_by_size``).

    Arguments containing multiple values are standard TOML lists.

    Example::

        [tool.vulture]
        exclude = ["file*.py", "dir/"]
        ignore_decorators = ["deco1", "deco2"]
        ignore_names = ["name1", "name2"]
        make_whitelist = true
        min_confidence = 10
        sort_by_size = true
        verbose = true
        paths = ["path1", "path2"]
    toolvulture)tomllibloadgetr    )infiler   settingsr   r   r   _parse_toml<   s   
r)   c                    s,  t   dd }d}dt }d}tjd|d}|jdd	d
 dd |jdd| d| dd |jdd| d| d |jdd| d| d |jdd dd |jdt dd |jdd dd |jdtd d!d |jd"d#d d$ |jd%d&|d' || } fd(d)t|	 D }t
| |S )*z
    Parse CLI arguments.

    :param args: A list of strings representing the CLI arguments. If left to
        the default, this will default to ``sys.argv``.
    c                 S   s
   |  dS )N,)split)r   r   r   r   csvd   r   z_parse_args.<locals>.csvz%(prog)s [options] [PATH ...]zvulture z:Patterns may contain glob wildcards (*, ?, [abc], [!abc]).r#   )progusager   *PATHzgPaths may be Python files or directories. For each directory Vulture analyzes all contained *.py files.)nargsmetavardefaulthelpz	--excludePATTERNSz^Comma-separated list of path patterns to ignore (e.g., "*settings.py,docs,*/test_*.py,venv"). zg A PATTERN without glob wildcards is treated as *PATTERN*. Patterns are matched against absolute paths.)r2   r   r3   r4   z--ignore-decoratorsz~Comma-separated list of decorators. Functions and classes using these decorators are ignored (e.g., "@app.route,@require_*"). z--ignore-namesz@Comma-separated list of names to ignore (e.g., "visit_*,do_*"). z--make-whitelist
store_truezGReport unused code in a format that can be added to a whitelist module.)actionr3   r4   z--min-confidencezIMinimum confidence (between 0 and 100) for code to be reported as unused.)r   r3   r4   z--sort-by-sizez9Sort unused functions and classes by their lines of code.z--configr   z#Path to pyproject.toml config file.z-vz	--verbose)r7   r3   z	--versionversion)r7   r8   c                    s   i | ]\}}| ur||qS r   r   ).0r   r   missingr   r   
<dictcomp>   s
    z_parse_args.<locals>.<dictcomp>)objectr   argparseArgumentParseradd_argumentintstr
parse_argsvarsr   r    )argsr,   r.   r8   	glob_helpparser	namespacecli_argsr   r:   r   _parse_argsY   s   	

	


rJ   c           	      C   s   t | }d}|rt|}t|}n-t|d  }| r<t|d}t|}W d   n1 s2w   Y  t|}ni }|| t	
 D ]
\}}||| qG|r_|d r_td|  t| |S )a  
    Returns a config object for vulture, merging both ``pyproject.toml`` and
    CLI arguments (CLI arguments have precedence).

    :param argv: The CLI arguments to be parsed. This value is transparently
        passed through to :py:meth:`argparse.ArgumentParser.parse_args`.
    :param tomlfile: An IO instance containing TOML data. By default this will
        auto-detect an existing ``pyproject.toml`` file and exists solely for
        unit-testing.
     r   rbNr   zReading configuration from )rJ   r)   rB   pathlibPathresolveis_fileopenupdater   r   
setdefaultprintr!   )	argvtomlfile
cli_configdetected_toml_pathr   	toml_pathfconfigr   r   r   r   r   make_config   s&   



r[   r   )NN)__doc__r>   rM   r$   ModuleNotFoundErrortomlir8   r   r   	Exceptionr   r    r!   r)   rJ   r[   r   r   r   r   <module>   s2    
]