o
    iX                     @  s  d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dlmZm	Z	 d dl
mZ d dlmZmZmZmZ d dlZd dlmZ d dlmZ d dlmZ d d	lmZmZ d d
lmZmZ d dlmZ d dl m!Z!m"Z" d dl#m$Z$m%Z%m&Z&m'Z' d dl(m)Z) erd dl*m+Z+ d dl,m-Z-m.Z. d dlm/Z/m0Z0 e1dd2 Z3	 G dd dej4Z5dZddZ6dddddddddddd d[d5d6Z7d7Z8d\d:d;Z9d]d=d>Z:ddddddddddddddd?d^dFdGZ;		d_dddddddddddH
d`dTdUZ<dadbdXdYZ=dS )c    )annotationsN)datetimetimezone)Path)IOTYPE_CHECKINGAnyCallable)debug)find_breaking_changes)JSONEncoder)ExplanationStyleParser)ExtensionErrorGitError)load_extensions)_get_latest_tag_get_repo_root)GriffeLoaderloadload_git	load_pypi)logger)Sequence)DocstringOptionsDocstringStyle)	Extension
ExtensionsGRIFFE_LOG_LEVELINFOc                      s*   e Zd Zdd fdd	ZdddZ  ZS )
_DebugInfor   nargsint | str | Nonekwargsr   returnNonec                   s   t  jdd|i| d S )Nr!    )super__init__)selfr!   r#   	__class__r&   Z/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/griffe/_internal/cli.pyr(   4      z_DebugInfo.__init__argsc                 O  s   t   td d S )Nr   )r
   _print_debug_infosysexit)r)   r.   r#   r&   r&   r,   __call__7   s   z_DebugInfo.__call__)r   )r!   r"   r#   r   r$   r%   )r.   r   r#   r   r$   r%   )__name__
__module____qualname__r(   r2   __classcell__r&   r&   r*   r,   r    3   s    r    datastroutput_filestr | IO | Noner$   r%   c                 C  sh   t |tr%t|ddd}t| |d W d    d S 1 sw   Y  d S |d u r,tj}t| |d d S )Nwutf8)encodingfile)
isinstancer8   openprintr0   stdout)r7   r9   fdr&   r&   r,   _print_data<   s   
"rE   TF
extensionssearch_pathsdocstring_parserdocstring_optionsresolve_aliasesresolve_implicitresolve_externalallow_inspectionforce_inspectionstore_sourcefind_stubs_packagepackagesSequence[str]rG   Extensions | NonerH   Sequence[str | Path] | NonerI   DocstringStyle | Parser | NonerJ   DocstringOptions | NonerK   boolrL   rM   bool | NonerN   rO   rP   rQ   r   c                C  s   t ||||||	|
d}| D ]A}|std qtd| z
|j|d|d W q ty@ } ztd|| W Y d }~qd }~w tyN   td| Y qw td |rwtd	 |j	||d
\}}|rqtdt
|| |S td| |S )N)rG   rH   rI   rJ   rN   rO   rP   zEmpty package name, continuingzLoading package %sT)try_relative_pathrQ   zCould not find package %s: %sz%Tried but could not import package %szFinished loading packageszStarting alias resolution)implicitexternalz4%s aliases were still unresolved after %s iterationsz-All aliases were resolved after %s iterations)r   r   r
   infor   ModuleNotFoundErrorerrorImportError	exceptionrK   len)rR   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   loaderpackager_   
unresolved
iterationsr&   r&   r,   _load_packagesF   s>   


rg   )DEBUGr   WARNINGERRORCRITICALvalueSequence[str | dict[str, Any]]c                 C  s,   zt | W S  t jy   | d Y S w )N,)jsonloadsJSONDecodeErrorsplitrl   r&   r&   r,   _extensions_type|   s
   rt   argparse.ArgumentParserc                    s6  d} d}	 	 t jd| |dd}d}d |jdd	}|jd
dd|d |jddddt  d |jdtdd dp fdd}|jdddddddqfd%d&}|d'd(}|jd)d	}|jd*d+d,d-d. |jd/d0d1dd2d3 |jd4d5tj	d6d7 |jd8d9d:d;t
d<d= |jd>d?d@i tjdAd= |jdBdCd1dDd |jdEdFd1dGd |jdHdIdJd1dKdL |jdMdJdNdOdL |jdPdQd1dRd || |dSdT}	|	jdUd	}
|
jdVd+dWdX |
jdYdZd[d\dX |
jd]d^d_d`dX |
jdadbd1d;dcdd |
jdedbdNd;dfdd |
jdgdhd1did djdk tD }|
jd/dldm|d;dndo ||	 |S )rzNReturn the CLI argument parser.

    Returns:
        An argparse parser.
    z3%(prog)s [GLOBAL_OPTS...] COMMAND [COMMAND_OPTS...]z'Signatures for entire Python programs. Fgriffe)add_helpusagedescriptionprogzKShow this help message and exit. Commands also accept the -h/--help option.z Show this help message and exit.zGlobal optionstitle-h--helphelpactionr   z-Vz	--versionversionz	%(prog)s )r   r   z--debug-infozPrint debug information.	subparserru   r$   r%   c              	     s   | j dd}|jddd d | j dd}|jdd	d
dtdd |jdddddd | j dd}|jddddddd |jddi tdd |jdd d!d"d#d$d |jd%d&d'ddd(d | j d)d}|jd*d+d,tttjd-d. d S )/NzCommon optionsr{   r}   r~   r   r   zSearch optionsz-sz--searchrH   appendzPaths to search packages into.)destr   typer   z-yz
--sys-pathappend_sys_path
store_truezAWhether to append `sys.path` to search paths specified with `-s`.r   r   r   zLoading optionsz-Bz--find-stubs-packagesrQ   FzJWhether to look for stubs-only packages and merge them with concrete ones.r   r   defaultr   z-ez--extensionszA list of extensions to use.)r   r   r   z-Xz--no-inspectionrN   store_falseTz:Disallow inspection of builtin/compiled/not found modules.z-xz--force-inspectionrO   z<Force inspection of everything, even when sources are found.zDebugging optionsz-Lz--log-levelLEVELzCSet the log level: `DEBUG`, `INFO`, `WARNING`, `ERROR`, `CRITICAL`.)metavarr   choicesr   r   )add_argument_groupadd_argumentr   rt   DEFAULT_LOG_LEVEL_level_choicesr8   upper)r   common_optionssearch_optionsloading_optionsdebug_options)subcommand_helpr&   r,   add_common_options   sx   
z&get_parser.<locals>.add_common_options
subcommandCommandsCOMMANDT)r   r|   r   rz   requiredcommandr8   textr#   r   c                   s    j | fd||d|S )NF)rw   r   ry   )
add_parser)r   r   r#   )
subparsersr&   r,   add_subparser   r-   z!get_parser.<locals>.add_subparserdumpz.Load package-signatures and dump them as JSON.zDump optionsrR   PACKAGE+z Packages to find, load and dump.)r   r!   r   z-fz--fullr   z"Whether to dump full data in JSON.)r   r   r   z-oz--outputzZOutput file. Supports templating to output each package in its own file, with `{package}`.)r   r   z-dz
--docstylerI   NzThe docstring style to parse.)r   r   r   r   z-Dz	--docoptsrJ   z%The options for the docstring parser.z-rz--resolve-aliaseszWhether to resolve aliases.z-Iz--resolve-implicitzrWhether to resolve implicitly exported aliases as well. Aliases are explicitly exported when defined in `__all__`.z-Uz--resolve-externalrM   zAlways resolve aliases pointing to external/unknown modules (not loaded directly).Default is to resolve only from one module to its private sibling (`ast` -> `_ast`).r   z--no-resolve-externalr   zNever resolve aliases pointing to external/unknown modules (not loaded directly).Default is to resolve only from one module to its private sibling (`ast` -> `_ast`).z-Sz--statszShow statistics at the end.checkz1Check for API breakages or possible improvements.zCheck optionsrd   z)Package to find, load and check, as path.)r   r   z-az	--againstREFzUOlder Git reference (commit, branch, tag) to check against. Default: load latest tag.z-bz
--base-refBASE_REFzIGit reference (commit, branch, tag) to check. Default: load current code.z--colorcolorz"Force enable colors in the output.r   z
--no-colorz#Force disable colors in the output.z-vz	--verbosezVerbose output.c                 S  s   g | ]}|j qS r&   rs   ).0fmtr&   r&   r,   
<listcomp>E  s    zget_parser.<locals>.<listcomp>z--formatstylezOutput format.)r   r   r   r   )r   ru   r$   r%   )r   r8   r   r8   r#   r   r$   ru   )argparseArgumentParserr   r   r
   _get_versionr    add_subparsersr0   rC   r   ro   rp   r   )rx   ry   parser	main_helpglobal_optionsr   r   dump_parserdump_optionscheck_parsercheck_optionsformatsr&   )r   r   r,   
get_parser   s   ?

r   )outputfullrI   rJ   rG   rK   rL   rM   rH   rQ   r   rN   rO   statsr   r   CSequence[str | dict[str, Any] | Extension | type[Extension]] | Noner   r   intc                C  sL  d}t |tr|jdd|krd}|	rt|	ng }	|r!|	tj zt|p&d }W n ty8   t	
d Y dS w t| ||	|||||||d|
d}|jj}tjtjd	}|rq| D ]\}}|jd
|dd}t||j|d qZntj|td
|dd}t|| tjtjd	| }|r| }|j|_t	|  t|t| krdS dS )a  Load packages data and dump it as JSON.

    Parameters:
        packages: The packages to load and dump.
        output: Where to output the JSON-serialized data.
        full: Whether to output full or minimal data.
        docstring_parser: The docstring parser to use. By default, no parsing is done.
        docstring_options: Docstring parsing options.
        resolve_aliases: Whether to resolve aliases (indirect objects references).
        resolve_implicit: Whether to resolve every alias or only the explicitly exported ones.
        resolve_external: Whether to load additional, unspecified modules to resolve aliases.
            Default is to resolve only from one module to its private sibling (`ast` -> `_ast`).
        extensions: The extensions to use.
        search_paths: The paths to search into.
        find_stubs_package: Whether to search for stubs-only packages.
            If both the package and its stubs are found, they'll be merged together.
            If only the stubs are found, they'll be used as the package itself.
        append_sys_path: Whether to append the contents of `sys.path` to the search paths.
        allow_inspection: Whether to allow inspecting modules when visiting them is not possible.
        force_inspection: Whether to force using dynamic analysis when loading data.
        stats: Whether to compute and log stats about loading.

    Returns:
        `0` for success, `1` for failure.
    Frd   )rd   Tr&   Could not load extensions   rF   )tz   )indentr   	sort_keys)clsr   r   r   r   )r@   r8   formatlistextendr0   pathr   r   r   ra   rg   modules_collectionmembersr   nowr   utcitemsas_jsonrE   ro   dumpsr   r   microsecondstime_spent_serializingr]   as_textrb   )rR   r   r   rI   rJ   rG   rK   rL   rM   rH   rQ   r   rN   rO   r   per_package_outputloaded_extensionsrc   data_packagesstartedpackage_namer7   
serializedelapsedloader_statsr&   r&   r,   r   L  sR   ,

r   )
base_refrG   rH   r   rQ   rN   rO   verboser   r   rd   
str | Pathagainst
str | Noneagainst_pathstr | Path | Noner   r   r   r   str | ExplanationStyle | Nonec       
         C  s  |rt |ng }|r|tj |p| }zt|pd }W n ty+   td Y dS w t	d|p2d }r|
dp>t|  dd}|
d}tt| ||||||	|d	d
d
}|rt	d| }sltd| d|
dptt|  dd}|
d}n|}d}tt| ||||||	|d	d
d
}nZ|p| }z|pt| }t|}W n ty } ztd| tjd W Y d
}~dS d
}~ww t|||||||	|d	d
d
}|rt| ||||||	|d	d
d
}nt| d	||||	|d	d
d	}t t||}|d
u rtdd
 }d
ur| dv }t  tj|d
u r|n| d |d
u r.|
r*tjntj}nt|}|D ]}t|j |dtjd q4|rHdS dS )a*  Check for API breaking changes in two versions of the same package.

    Parameters:
        package: The package to load and check.
        against: Older Git reference (commit, branch, tag) to check against.
        against_path: Path when the "against" reference is checked out.
        base_ref: Git reference (commit, branch, tag) to check.
        extensions: The extensions to use.
        search_paths: The paths to search into.
        append_sys_path: Whether to append the contents of `sys.path` to the search paths.
        allow_inspection: Whether to allow inspecting modules when visiting them is not possible.
        force_inspection: Whether to force using dynamic analysis when loading data.
        verbose: Use a verbose output.

    Returns:
        `0` for success, `1` for failure.
    r&   r   r   z([\w.-]+)?((==|<=|<|>=|>|!=).+) -_r   TN)rG   rH   rN   rO   rQ   rK   rM   zBase z% is not a valid dependency specifier.zgriffe: error: r>   )	refreporG   rH   rN   rO   rQ   rK   rM   )rZ   rG   rH   rN   rO   rQ   rK   rM   FORCE_COLOR>   1yonyestrue)strip)r   r   )!r   r   r0   r   r   r   r   ra   rematchgroupr8   lowerreplacer   
ValueErrorr   r   r   rB   stderrr   r   r   osgetenvcoloramadeinitinitr   VERBOSEONE_LINEexplain)rd   r   r   r   rG   rH   r   rQ   rN   rO   r   r   r   r   match_againstagainst_distagainst_versionold_package
match_base	base_distbase_versionnew_package
repositoryr_   	breakagesforce_colorbreakager&   r&   r,   r     s   "

 
r   r.   list[str] | Nonec           	   	   C  s   t  }|| }|j}|d |d}|dt}ztt|}W n ty?   dt	}t
d| d| dtjd Y d	S w tjd
|d ttdt  ttd}|| di |S )zRun the main program.

    This function is executed when you type `griffe` or `python -m griffe`.

    Parameters:
        args: Arguments passed from the command line.

    Returns:
        An exit code.
    
debug_infor   	log_levelz', 'z"griffe: error: invalid log level 'z' (choose from 'z')r>   r   z%(levelname)-10s %(message)s)r   leveli  )r   r   Nr&   )r   
parse_args__dict__popr   getattrloggingAttributeErrorjoinr   rB   r0   r   basicConfigsetrecursionlimitmaxgetrecursionlimitr   r   )	r.   r   opts	opts_dictr   r  r  r   commandsr&   r&   r,   mainA  s(   




r  )r7   r8   r9   r:   r$   r%   )rR   rS   rG   rT   rH   rU   rI   rV   rJ   rW   rK   rX   rL   rX   rM   rY   rN   rX   rO   rX   rP   rX   rQ   rX   r$   r   )rl   r8   r$   rm   )r$   ru   ) rR   rS   r   r:   r   rX   rI   rV   rJ   rW   rG   r   rK   rX   rL   rX   rM   rY   rH   rU   rQ   rX   r   rX   rN   rX   rO   rX   r   rX   r$   r   )NN)rd   r   r   r   r   r   r   r   rG   r   rH   rU   r   rX   rQ   rX   rN   rX   rO   rX   r   rX   r   rY   r   r   r$   r   )N)r.   r  r$   r   )>
__future__r   r   ro   r  r   r   r0   r   r   pathlibr   typingr   r   r   r	   r   griffe._internalr
   griffe._internal.diffr   griffe._internal.encodersr   griffe._internal.enumerationsr   r   griffe._internal.exceptionsr   r    griffe._internal.extensions.baser   griffe._internal.gitr   r   griffe._internal.loaderr   r   r   r   griffe._internal.loggerr   collections.abcr   #griffe._internal.docstrings.parsersr   r   r   r   r   r   r   Actionr    rE   rg   r   rt   r   r   r   r  r&   r&   r&   r,   <module>   s   
	3

 M` 