#B jdZddlZddlZddlZddlZddlZddlmZddlm Z ddl m Z m Z m Z ddlmZddlmZdd lmZdd lmZdd lmZmZejd krddlZn ddlZn #e$rdZYnwxYwd ZGddZGddZeddZ Gdde!Z"eddZ#dS)z)Configuration file parsing and utilities.N) namedtuple)Set) NoOptionErrorNoSectionErrorRawConfigParser)reduce)compile) __version__)log) ErrorRegistry conventions) cfd}|S)z4Check that the configuration object was initialized.cV|j|jtd|g|Ri|S)Nz$using an uninitialized configuration) _arguments_options RuntimeError)selfargskwargsmethods /srv/buildsys-work-dir/castor/build_node/builder-2/WGSG1/unpkd_srcs/cloudlinux-venv-1.0.6/venv/lib/python3.11/site-packages/pydocstyle/config.py _decoratorz%check_initialized.._decoratorsA ? "dm&;EFF Fvd,T,,,V,,,)rrs` rcheck_initializedrs$----- rcLeZdZdZdZd dZddZdZdZdd d Z d Z d Z dS) TomlParseraConfigParser that partially mimics RawConfigParser but for toml files. See RawConfigParser for more info. Also, please note that not all RawConfigParser functionality is implemented, but only the subset that is currently used by pydocstyle. ci|_dS)zCreate a toml parser.N)_configrs r__init__zTomlParser.__init__.s  rNc t|tttjfr|g}g}|D]} t |d5}t s"tjd| ddd=|j t j |dddn #1swxYwYn#t$rYwxYwt|tjrtj |}|||S)aRead and parse a filename or an iterable of filenames. Files that cannot be opened are silently ignored; this is designed so that you can specify an iterable of potential configuration file locations (e.g. current directory, user's home directory, systemwide directory), and all existing configuration files in the iterable will be read. A single filename may also be given. Return list of successfully read files. rbzTThe %s configuration file was ignored, because the `tomli` package is not installed.N) isinstancestrbytesosPathLikeopentomllibr warningr"updateloadOSErrorfspathappend)r filenamesencodingread_okfilenamefps rreadzTomlParser.read2sp i#ubk!: ; ; $" I! % %H (D)):R"! L$ !:::::::L'' R(8(8999:::::::::::::::    (BK00 /9X.. NN8 $ $ $ $sAB0B$ B0,,B$ B0$B( (B0+B( ,B00 B=<B=Fc ttj|d|jd}n#t $rd}YnwxYwt |tr|S|rdSt|)N.tool) roperatorgetitemsplitr"KeyErrorr'dictr)rsection allow_nonecurrents r _get_sectionzTomlParser._get_sectionSs   c"" V$GG    GGG  gt $ $ *N  *4 )) )s9< A  A c4||dduS)zCIndicate whether the named section is present in the configuration.T)rCN)rE)rrBs r has_sectionzTomlParser.has_sectionds   T ::$FFrcn||}t|S)z9Return a list of option names for the given section name.)rElistkeys)rrBrDs roptionszTomlParser.optionshs+##G,,GLLNN###r_convcR||}|} ||}n#t$rt||wxYwt |t rt d|d|d|(t ||st d|d|d||S)z(Get an option value for a given section.z Expected r;z to be an option, not a section.Nz The type of z should be )rElowerr@rr'rA TypeError)rrBoptionrMdvalues rgetzTomlParser.getms   g & & 1fIEE 1 1 100 0 1 eT " " NGNNfNNN   Zu%=%= CwCCCCECC  s 4Ac<|||tS)z/Get a boolean option value for a given section.rL)rTboolrrBrQs r getbooleanzTomlParser.getbooleansxxtx444rc<|||tS)z0Get an integer option value for a given section.rL)rTintrWs rgetintzTomlParser.getintsxxsx333rN)F) __name__ __module__ __qualname____doc__r$r9rErGrKrTrXr[rrrr r &sB****"GGG$$$ -1.55544444rr ceZdZdZdZdZdZdZdZdZ e j Z dZ d Zd Zd Zd Zd ZedZedZdZdZedZdZdZd$dZedZed%dZedZ edZ!edZ"edZ#edZ$edZ%ed Z&ed!Z'ed"Z(ed#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. ) conventionselectignorez add-selectz add-ignorematchz match-dirzignore-decoratorszignore-self-only-init)rerdrcz(?!test_).*\.pyz[^\.].*z2property,cached_property,functools.cached_propertyF)z setup.cfgztox.iniz .pydocstylez.pydocstyle.iniz .pydocstylercz.pydocstylerc.inizpyproject.tomlz.pep257) pydocstylepep257c~i|_d|_dx|_x|_|_||_dS)zCreate a configuration parser.N)_cache_override_by_clirr _run_conf_create_option_parser_parserr#s rr$zConfigurationParser.__init__s= $;?? ?$.1133 rc\|g\}}||S)z;Return a `RunConfiguration` object set with default values.) _parse_args_create_run_config)rrK_s rget_default_run_configurationz1ConfigurationParser.get_default_run_configurations-%%b)) &&w///rc:|\|_|_|jpdg|_||jst ||j|_||jd}||_dS)zParse 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. r;F) use_defaultsN) rqrr_validate_optionsIllegalConfigurationrrrm_create_check_configrl)rconfigs rparsezConfigurationParser.parses*.)9)9););& t/2cU%%dm44 )&(( (00??**4=u*MM &rc|jS)z,Return the run configuration for the script.)rmr#s rget_user_run_configurationz.ConfigurationParser.get_user_run_configurations ~rc#Kd}d}d}|jD]}tj|rtj|D]\}}}|tj|}||\} ||} ||} fd|D|dd<ttjj|D]M} | | r@tj || } | t|j | | |j fVNݐ|tj|}||\} }||} ||} | tj|r |t|j | | |j fVdS)aGenerate 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. czt|jdzj}t|jdzj}||fS)z:Return the `match` and `match_dir` functions for `config`.$)rerf match_dir)conf match_funcmatch_dir_funcs r _get_matchesz._get_matches s;DJ,--3J 455;N~- -rc<|jrt|jndS)z0Return the `ignore_decorators` as None or regex.N)ignore_decoratorsrrs r_get_ignore_decoratorszFConfigurationParser.get_files_to_check.._get_ignore_decoratorss$/3.DN4)***$ rcb|jr't|jdndS)z0Return the `property_decorators` as None or set.,N)property_decoratorssetr?rs r_get_property_decoratorszHConfigurationParser.get_files_to_check.._get_property_decoratorss5+D,22377888 rc*g|]}| |Srr).0rRrs r z:ConfigurationParser.get_files_to_check..(s&???Q))A,,?q???rN) rr*pathisdirwalk _get_configabspathmapbasenamejoinrI checked_codesignore_self_only_init)rrrrnamerootdirsr4rzrfrrr7 full_pathrsrs @rget_files_to_checkz&ConfigurationParser.get_files_to_checks+ . . .        O! ! Dw}}T"" -/WT]])D$ !--bgood.C.CDDF'3|F';';$E9(>(>v(F(F%*B*B6*J*J'@???$???DG$'(8)$D$D   5??(* T8(D(DI ) $V%9 : : 1 3 & < # ())"'//$*?*?@@'<//q$:$:6$B$B!&>&>v&F&F#5))$//00V122)+4 7! ! rc2||}||jvr |j|S||}|Utj|\}}|r||}n||j}n| |\}}tj|\}}|r.|r,||} | | |}n||}|S)awGet 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. ) _get_node_dirrk_get_config_file_in_folderr*rr?rryr_read_configuration_file_merge_configuration) rnoder config_file parent_dirtailrzrKinherit parent_configs r_get_config_by_discoveryz,ConfigurationParser._get_config_by_discoveryDs!!$'' 4;  ;t$ $55d;;  !w}}T22 J B))*55224=AA $<<[II GW!w}}T22 J < < $ 0 0 < < 22='JJ227;; rc|jj*tjd||}ntjd|jjt j|jjs,td |jjd|j vr |j dS| |jj\}}|/tj d| |j}n| |}i}tjD]0}t#|j|}t#||}||n|||<1tdi|}||j|j|jj ||j d<n||j ||<|S)aGet 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.r)rmrzr debugrr*rexistsrxformatrkrr.ryrCheckConfiguration_fieldsgetattrrl_set_add_optionsrr) rrrzrKrs final_configattrcli_valconf_vals rrzConfigurationParser._get_configns: > ( I> ? ? ?22488FF I,dn.C D D D7>>$."788 *228&9N2O2O t{""{4((66t~7LMMJGQ G224=AA227;; &. N NDd3T::Gvt,,H,3,?XL  #33l33 f2DMBBB > , &DK  4:DK**400 1 rctj|}tj|r|ntj|S)z?Return the absolute path of the directory of a filesystem node.)r*rrrdirname)rrs rrz!ConfigurationParser._get_node_dirsBwt$$w}}T**Ett0E0EErc|drt}ntd}d}d}||r||ry|jjdd}|jjD]}||jd|D}| g\}} ||} | | D]} | dkr| | | }| dd |j vrtjd | d U| d d} || } | d vr|| | }n9| d kr|| | }n| dvsJ| | | }t%|| |||}|'||st+d|||fS)zTry 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). .toml#;inline_comment_prefixesNTc6i|]}|j|jp|jSr)desttypeaction)ros r z@ConfigurationParser._read_configuration_file..s%KKK!1616#5QXKKKrrrs-zUnknown option 'z ' ignored)rZcountstring) store_true store_falsez in file: )endswithr rr9_get_section_namero option_list option_groupsextendrqrKrXreplaceCONFIG_FILE_OPTIONSr r.r[rTsetattr_fix_set_optionsrwrx)rrparserrKshould_inherit all_optionsgroupr new_optionsrs section_nameoptnormalized_optopt_typerSs rrz,ConfigurationParser._read_configuration_filesO == ! ! I\\FF$ZHHHF ;;t  ! 9!7!7!?!?! 9,21115K3 6 6""5#45555KK{KKKK"--b11NK 11&99L~~l33 < <)##%+%6%6|S%I%IN;;sC((0HHHK A3 A A ABBB!$S#!6!6&~6///"MM,<>>&&rcDtj|j}||r||}|||t |}dD])}t||}||nt||||<*tdi|S)zMerge 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. rrfrrrrNr) copydeepcopyr_has_exclusive_option_get_exclusive_error_codesrrArr)rr child_options error_codesrkey child_values rrz(ConfigurationParser._merge_configurationsmM$?@@  % %m 4 4 I99-HHK k=999K000  C"-55K* ]C00 3KK "++F+++rNcl|j||\}}|||fS)z@Parse the options using `self._parser` and reformat the options.)ro parse_argsr)rrvaluesrK argumentss rrqzConfigurationParser._parse_argss7!\44T6BB$$W--y88rcLfdtjD}tdi|S)z2Create a `RunConfiguration` object from `options`.c2i|]}|t|SrrrrrKs rrz:ConfigurationParser._create_run_config..s2   +.C#&&   rr)RunConfigurationr)rKrs` rrrz&ConfigurationParser._create_run_configsD    2B2J    ))&)))rTcJd}||s|r||}t|}dddddd}|D]=\}}t |||rt |d |nt ||||<>t d i|S) zCreate 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. NrMATCH_RE MATCH_DIR_REIGNORE_DECORATORS_REPROPERTY_DECORATORSIGNORE_SELF_ONLY_INITrDEFAULT_r)r_get_checked_errorsrAitemsrr)clsrKrvrrdefaultsrdefaults rryz(ConfigurationParser._create_check_config s  $ $W - - = =33G<sD 6 $ $L!!,// $#### $trctj|rtj|}|jD]}|drt }ntd}tj||}| |r| |r|cSdS)zkLook for a configuration file in `path`. If exists return its full path, otherwise None. rrrN) r*risfilerPROJECT_CONFIG_FILESrr rrr9r)rrfnrzrs rrz.ConfigurationParser._get_config_file_in_folderGs 7>>$   )7??4((D* ! !B{{7## M#(LLL T2..I{{9%% !#*?*?*G*G !     ! !rcBttj}d}|j ||j}||z }nC|j||j}n!|jtt|j}tj |S)z;Extract the error codes from the selected exclusive option.N) rr get_error_codesre_expand_error_codesrdrcrrrr)rrKcodesrignoreds rrz.ConfigurationParser._get_exclusive_error_codesZsM13344 > %--gn==G!GOMM ^ '33GNCCMM   +#K1CDDM}]+++rcz|||jz}|||jz}dS)z@Set `checked_codes` by the `add_ignore` or `add_select` options.N)r add_select add_ignore)rrrKs rrz$ConfigurationParser._set_add_optionsks> 001CDDD 001CDDD rcXttj}t} |D]Ssfd|D}|st jd||Tn"#t$r}t||d}~wwxYw|S)z0Return an expanded set of error codes to ignore.c>h|]}||Sr) startswith)rcodeparts r z:ConfigurationParser._expand_error_codes..s:   !dood.C.C    rz9Error code passed is not a prefix of any known errors: %sN) rr rstripr r.r/rPrx) code_partsr expanded_codes codes_to_adders @rrz'ConfigurationParser._expand_error_codesqsM13344 1" 4 4zz||    %*    $K+ %%l3333! 4" 1 1 1&q))q 0 1sAB B'B""B'cn||}||j}||||S)z6Extract the codes needed to be checked from `options`.)rDEFAULT_CONVENTIONr)rrKrs rrz'ConfigurationParser._get_checked_errorssA66w??  2M ]G444rc tj|jdD]P\}}t||r;t||r+t jd||dSQ|jra|jtvrSt jd|jd tj dSdS)zValidate 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: {}, T) itertools permutationsBASE_ERROR_SELECTION_OPTIONSrr errorrrcrrrJ)rrKopt1opt2s rrwz%ConfigurationParser._validate_optionss$0  ,a    JD$w%% ''4*@*@  **0&t*<*<uu   '"4K"G"G ICJJ& +2B2D2D(E(E    5trcDtfd|jDS)z>Return `True` iff one or more exclusive options were selected.c4g|]}t|duSr\rrs rrz=ConfigurationParser._has_exclusive_option..s8   %%T1   r)anyr )rrKs `rrz)ConfigurationParser._has_exclusive_options@    ;      rcd}d}fd}|D].}t||}|t||||/|D]G}t||}|d}t|ts ||}t|||H|S)z9Alter the set options from None/strings to sets in place.)rerd)r r ct|tr|d}d|Ddhz S)zSplit `value_str` by the delimiter `,` and return a set. Removes empty values ('') and strips whitespace. Also expands error code prefixes, to avoid doing this for every file. rc6h|]}|Sr)r)rxs rrzIConfigurationParser._fix_set_options.._get_set..s ...q...rrg)r'r(r?r) value_strrs r_get_setz6ConfigurationParser._fix_set_options.._get_setsX)S)) 1%OOC00 **..I..."5 rNrg)rrr'r)rrKoptional_set_optionsmandatory_set_optionsr,rrSs` rrz$ConfigurationParser._fix_set_optionss 4 <     ( 7 7CGS))E hhuoo666( ) )CGS))E}eS)) (  GS% ( ( ( (rc ddlm}m}|td}|j}|ddddd |d d ddd |ddddd |ddddd |dddd |dddd|||dd||dd}|j}|dd dd!|d"d dd#|d$d%dd&d't|d(d dd)|d*d dd+|d,ddd-.|||d/d0dd1|j |d2d0dd3|j |d4d5dd6|j |d7d8dd9|j |S):z...])versionusagez-ez --explainrFzshow explanation of each error)rrhelpz-sz--sourcezshow source for each errorz-dz--debugzprint debug informationz-vz --verbosezprint status informationz--countz&print total number of errors to stdoutz--configzNz2use given config file and disable config discovery)metavarrr4NotezWhen using --match, --match-dir or --ignore-decorators consider whether you should use a single quote (') or a double quote ("), depending on your OS, Shell, etc.zError Check OptionsaOnly 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--selectzzchoose 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--ignorezchoose 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 --conventionzzgchoose the basic list of checked errors by specifying an existing convention. Possible conventions: {}.rz --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--ignore-self-only-initz5ignore __init__ methods which only have a self param.)rrr4z--matchz zcheck only files that exactly match regular expression; default is --match='{}' which matches files that don't start with 'test_' but end with '.py'z --match-dirzsearch only dirs that exactly match regular expression; default is --match-dir='{}', which matches all dirs that don't start with a dotz--ignore-decoratorsz zignore any functions or methods that are decorated by a function with a name fitting the regular expression; default is --ignore-decorators='{}' which does not ignore any decorated functions.z--property-decoratorszzconsider 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='{}') optparser0r1r add_optionadd_option_grouprrrDEFAULT_MATCH_REDEFAULT_MATCH_DIR_REDEFAULT_IGNORE_DECORATORS_REDEFAULT_PROPERTY_DECORATORS)rr0r1rrQ check_group add_checks rrnz)ConfigurationParser._create_option_parsers 76666666?    "   1        -        *        +       9      E       K4     "k  ! =    *   ,       ,   @@F +&&AA                     %H       ,,,  fS)**   fS-..   !"BCI&4CC   #+017311  r)NN)T)*r]r^r_r`rr r:r;r<r=rrirDEFAULT_IGNORE_SELF_ONLY_INITrrr$rtr{rr}rrr staticmethodrrrrqrr classmethodryrrrrrrrwrrrnrrrrbrbs##J $F )%#% < %+$)! 6444000 '''&BBBL(((TEEENFF\F 7'7'7'r,,,>9999 **\*,,,[,:[!![!$,,[, EE[E \8[[4  [ ""["Hvv[vvvrrbr)rrfrrrrceZdZdZdS)rxz(An exception for illegal configurations.N)r]r^r_r`rrrrxrxs22Drrxr)explainsourcerverboserrz)$r`rrr=r*sys collectionsrcollections.abcr configparserrrr functoolsrrr _versionr utilsr violationsr r version_infor-tomli ImportErrorrr rbr ExceptionrxrrrrrSs//  """"""GGGGGGGGGG!!!!!!22222222wNNNN d4d4d4d4d4d4d4d4NM M M M M M M M b Z       9   :@sA##A-,A-