XjddlmZddlZddlZddlZddlZddlZddlm Z ddl m Z ddl m Z ddlmZmZmZmZmZmZddlmZddlmZdd lmZdd lmZmZdd lmZdd l m!Z!d dl"m#Z#d dl$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6d dl7m8Z8edZ9GddedZ:ee;e:jxj{zZGdde!Z>GddZ?y)) annotationsN) Namespace)Mapping)SimpleNamespace)AnyClassVarLiteralTextIOTypeVarcast) ConfigDict) config_keys)_field_name_for_signature) deep_updateis_model_class)is_pydantic_dataclass) BaseModel) SettingsError)ENV_FILE_SENTINELCliSettingsSourceDefaultSettingsSourceDotenvFilteringDotEnvSettingsSource DotenvTypeEnvPrefixTargetEnvSettingsSourceInitSettingsSourceJsonConfigSettingsSourcePathTypePydanticBaseSettingsSource PydanticModel!PyprojectTomlConfigSettingsSourceSecretsSettingsSourceTomlConfigSettingsSourceYamlConfigSettingsSourceget_subcommand)_get_alias_namesTc|eZdZUded<ded<ded<ded<d ed <d ed <d ed<ded<d ed<ded<d ed<ded<d ed<ded<d ed<ded<ded<ded<ded<ded<ded<ded<d ed!<ded"<d#ed$<d%ed&<d'ed(<d'ed)<d ed*<d'ed+<d ed,<d ed-< d.ed/< d0ed1< d'ed2<ded3<y4)5SettingsConfigDictboolcase_sensitive bool | None#nested_model_default_partial_updatestr env_prefixrenv_prefix_targetDotenvType | Noneenv_file str | Noneenv_file_encodingzDotenvFiltering | Nonedotenv_filteringenv_ignore_emptyenv_nested_delimiter int | Noneenv_nested_max_splitenv_parse_none_strenv_parse_enums cli_prog_name)bool | list[str] | tuple[str, ...] | Nonecli_parse_argscli_parse_none_strcli_hide_none_typecli_avoid_jsoncli_enforce_requiredcli_use_class_docs_for_groupscli_exit_on_error cli_prefixcli_flag_prefix_char'bool | Literal['dual', 'toggle'] | Nonecli_implicit_flagscli_ignore_unknown_args(bool | Literal['all', 'no_enums'] | Nonecli_kebab_case$Mapping[str, str | list[str]] | None cli_shortcutsPathType | None secrets_dir json_filejson_file_encoding yaml_fileyaml_file_encodingyaml_config_sectionintpyproject_toml_depthtuple[str, ...]pyproject_toml_table_header toml_fileenable_decodingN)__name__ __module__ __qualname____annotations__j/mnt/ssd/data/Dropbox/adrian/vault-secondbrain/venv/lib/python3.12/site-packages/pydantic_settings/main.pyr+r+.s)44O&&!!,,$$$$""  ==""#''O??((<<77  """"##"10 rbr+F)totalceZdZUdZddddedddddddddddddddddddddddf d7fd Ze d8dZeddddedddddddddddddddddddddddf d9dZe d:dZ e d;dZ e d BaseSettingsa Base class for settings, allowing values to be overridden by environment variables. This is useful in production for secrets you do not wish to save in code, it plays nicely with docker(-compose), Heroku and any 12 factor app design. All the below attributes can be set via `model_config`. Args: _case_sensitive: Whether environment and CLI variable names should be read with case-sensitivity. Defaults to `None`. _nested_model_default_partial_update: Whether to allow partial updates on nested model default object fields. Defaults to `False`. _env_prefix: Prefix for all environment variables. Defaults to `None`. _env_prefix_target: Targets to which `_env_prefix` is applied. Default: `variable`. _env_file: The env file(s) to load settings values from. Defaults to `Path('')`, which means that the value from `model_config['env_file']` should be used. You can also pass `None` to indicate that environment variables should not be loaded from an env file. _env_file_encoding: The env file encoding, e.g. `'latin-1'`. Defaults to `None`. _env_ignore_empty: Ignore environment variables where the value is an empty string. Default to `False`. _env_nested_delimiter: The nested env values delimiter. Defaults to `None`. _env_nested_max_split: The nested env values maximum nesting. Defaults to `None`, which means no limit. _env_parse_none_str: The env string value that should be parsed (e.g. "null", "void", "None", etc.) into `None` type(None). Defaults to `None` type(None), which means no parsing should occur. _env_parse_enums: Parse enum field names to values. Defaults to `None.`, which means no parsing should occur. _cli_prog_name: The CLI program name to display in help text. Defaults to `None` if _cli_parse_args is `None`. Otherwise, defaults to sys.argv[0]. _cli_parse_args: The list of CLI arguments to parse. Defaults to None. If set to `True`, defaults to sys.argv[1:]. _cli_settings_source: Override the default CLI settings source with a user defined instance. Defaults to None. _cli_parse_none_str: The CLI string value that should be parsed (e.g. "null", "void", "None", etc.) into `None` type(None). Defaults to _env_parse_none_str value if set. Otherwise, defaults to "null" if _cli_avoid_json is `False`, and "None" if _cli_avoid_json is `True`. _cli_hide_none_type: Hide `None` values in CLI help text. Defaults to `False`. _cli_avoid_json: Avoid complex JSON objects in CLI help text. Defaults to `False`. _cli_enforce_required: Enforce required fields at the CLI. Defaults to `False`. _cli_use_class_docs_for_groups: Use class docstrings in CLI group help text instead of field descriptions. Defaults to `False`. _cli_exit_on_error: Determines whether or not the internal parser exits with error info when an error occurs. Defaults to `True`. _cli_prefix: The root parser command line arguments prefix. Defaults to "". _cli_flag_prefix_char: The flag prefix character to use for CLI optional arguments. Defaults to '-'. _cli_implicit_flags: Controls how `bool` fields are exposed as CLI flags. - False (default): no implicit flags are generated; booleans must be set explicitly (e.g. --flag=true). - True / 'dual': optional boolean fields generate both positive and negative forms (--flag and --no-flag). - 'toggle': required boolean fields remain in 'dual' mode, while optional boolean fields generate a single flag aligned with the default value (if default=False, expose --flag; if default=True, expose --no-flag). _cli_ignore_unknown_args: Whether to ignore unknown CLI args and parse only known ones. Defaults to `False`. _cli_kebab_case: CLI args use kebab case. Defaults to `False`. _cli_shortcuts: Mapping of target field name to alias names. Defaults to `None`. _secrets_dir: The secret files directory or a sequence of directories. Defaults to `None`. _build_sources: Pre-initialized sources and init kwargs to use for building instantiation values. Defaults to `None`. Nc ||n6|jj||||||||| | | | | |||||||||||||||\}}t | di|jj ||y)N)_case_sensitive$_nested_model_default_partial_update _env_prefix_env_prefix_target _env_file_env_file_encoding_env_ignore_empty_env_nested_delimiter_env_nested_max_split_env_parse_none_str_env_parse_enums_cli_prog_name_cli_parse_args_cli_settings_source_cli_parse_none_str_cli_hide_none_type_cli_avoid_json_cli_enforce_required_cli_use_class_docs_for_groups_cli_exit_on_error _cli_prefix_cli_flag_prefix_char_cli_implicit_flags_cli_ignore_unknown_args_cli_kebab_case_cli_shortcuts _secrets_dir _init_kwargsra) __class___settings_init_sourcessuper__init___settings_build_values)!__pydantic_self__rhrirjrkrlrmrnrorprqrrrsrtrurvrwrxryrzr{r|r}r~rrrr_build_sourcesvaluessources init_kwargsrs! rcrzBaseSettings.__init__sD) ",,CC /5Y'#5##5"3&;&;$7!1- /%9$7$7 /&;/M#5'&;$7)A /-)#9D F d,66MMgWbcdrbc||||fS)a Define the sources and their order for loading the settings values. Args: settings_cls: The Settings class. init_settings: The `InitSettingsSource` instance. env_settings: The `EnvSettingsSource` instance. dotenv_settings: The `DotEnvSettingsSource` instance. file_secret_settings: The `SecretsSettingsSource` instance. Returns: A tuple containing the sources and their order for loading the settings values. ra)cls settings_cls init_settings env_settingsdotenv_settingsfile_secret_settingss rcsettings_customise_sourcesz'BaseSettings.settings_customise_sourcess,lO=QQQrbc||n|jjd}||n|jjd}||n|jjd}||n|jjd} |tk7r|n|jjd}!||n|jjd}"||n|jjd}#||n|jjd}$| | n|jjd }%| | n|jjd }&| | n|jjd }'| | n|jjd }(| | n|jjd })||n|jjd}*||n|jjd}+|&s|+n|&}+||n|jjd},||n|jjd}-||n|jjd}.||n|jjd}/||n|jjd}0||n|jjd}1||n|jjd}2||n|jjd}3||n|jjd}4||n|jjd}5||n|jjd}6||n|jjd}7t|| }8t |||ni| }9t |||||$|%|#|&|' }:t ||!|"||||$|%|#|&|' };t||7||| }<|j||9|:|;|cgc]}>t|>ts|>}?}>t|?sAt|*tr|*f|=z}=nI|)Gtt|f|(|)|+|,|-|.|/|0|1|2|3|4|5|6|d"}@|@f|=z}=n|)d#vr|?d$js |?d$|)%|j|=|j|=||fSifScc}>w)&Nr-r1r2r/r4r6r8r9r;r<r=r>r@cli_settings_sourcerArBrCrDrErFrGrHrJrKrMrOrQ)r/)rr/)r-r1r2r9r;r8r<r=) r4r6r-r1r2r9r;r8r<r=)rQr-r1r2)rrrr)r>r@rArBrCrDrErFrGrHrJrKrMrOr-NFrargs) model_configgetrrrrrr$r isinstanceranyrenv_vars!_settings_warn_unused_config_keys)Arrhrirjrkrlrmrnrorprqrrrsrtrurvrwrxryrzr{r|r}r~rrrrrr-r1r2r/r4r6r8r9r;r<r=r>r@rrArBrCrDrErFrGrHrJrKrMrOrQdefault_settingsrrrrrsourcecustom_cli_sources cli_settingssA rcrz#BaseSettings._settings_init_sourcesspB-<,GSM]M]MaMabrMs$/$;[AQAQAUAUVbAc "4"@ cFVFVFZFZ[nFo  4? 1!!%%&KL , !*-> >9CDTDTDXDXYcDd"4"@ cFVFVFZFZ[nFo "3!> CDTDTDXDXYkDl &;%F !CL\L\L`L`awLx &;%F !CL\L\L`L`awLx $7#B HXHXH\H\]qHr /?.J*PSP`P`PdPdevPw*8*D#JZJZJ^J^_nJo ,;,GSM]M]MaMabrMs$8$D #JZJZJ^J^_tJu $7#B HXHXH\H\]qHr 8J/Oa#6#B HXHXH\H\]qHr -<,GSM]M]MaMabrMs%:%F !CL\L\L`L`awLx  .9 +!!%%&EF & #5"@ cFVFVFZFZ[nFo %0$;[AQAQAUAUVbAc %:%F !CL\L\L`L`awLx $7#B HXHXH\H\]qHr  (3 %!!%%&?@ -<,GSM]M]MaMabrMs*8*D#JZJZJ^J^_nJo &2&>lCDTDTDXDXYfDg 1 5X + (4(@ b0S ) )!/!5!5-1+  / /)!/!5!5-1+   5 #)!/  00 '%+!5 1    4;djQb>cfdd%&-/@A.07:+05 "/#1'9'9#1)=2O&7))='9,C#1"/#1!  $(/G3 = 09KA9N9W9W ! q !~ 6 --gs7G7GH (@ HHbHH=es Q6 Q6c|ri}i}i}|D]}t|tr"|j||j|t |dr |j nt |j }|}t|tr|}|||<t||}|jD cic]\} } | |vs || | k7s| | }} } |j||||SiScc} } w)Nr]) rr!_set_current_state_set_settings_sources_datahasattrr]typerritems"_settings_restore_init_kwarg_names) rrrstatedefaultsstatesr source_name source_statekeyvals rcrz#BaseSettings._settings_build_valuess $&E')H02F! 9f&@A--e455f=181LfooRVW]R^RgRg %x f&;<+H&2{##L%8 9/4kkmk(#ss(?RV^_bVcgjVjS#XkEk  2 23 U KLIls ,C C c|rC|r?t|j}t|j}|jjD]\}}t ||^}}t|} |j j ddxs|j j dd} | r| j||| z} || z} | sy| s|tt| } d}|D] }|| vs|}n||| vr|ntt| }|j|}| |hz D]}|j|d||| <yyy)z Restore the init_kwarg key names to the final merged state dictionary. This function renames keys in state to match the original init_kwargs key names, preserving the merged values from the source priority order. populate_by_nameFvalidate_by_nameN) setkeys model_fieldsrr(rraddnextiterpop)rrrstate_kwarg_namesinit_kwarg_names field_name field_info alias_names_matchable_names include_nameinit_kwarg_namestate_kwarg_name target_key source_keyaliasvaluers rcrz/BaseSettings._settings_restore_init_kwarg_namesss 5 #EJJL 1 ";#3#3#56 *6*C*C*I*I*K .& J"2:z"J a"%k"2+88<<&  N!..223EuM #'' 3"2_"D#4#F "'7"&d?&;!- #t,-(-E*%; .!;rbrc~dfd }|td|td|td|tdy)a Warns if any values in model_config were set but the corresponding settings source has not been initialised. The list alternative sources and their config keys can be found here: https://docs.pydantic.dev/latest/concepts/pydantic_settings/#other-settings-source Args: sources: The tuple of configured sources model_config: The model config to check for unused config keys c tfdDsT|D]N}j|tjd|djdjdt dPyy)Nc36K|]}t|ywN)r).0r source_types rc z[BaseSettings._settings_warn_unused_config_keys..warn_if_not_used.."sM6z&+6Msz Config key `z8` is set in model_config but will be ignored because no z5 source is configured. To use this config key, add a zH source to the settings sources via the settings_customise_sources hook.) stacklevel)rrwarningswarnr] UserWarning)rrrrrs` rcwarn_if_not_usedzHBaseSettings._settings_warn_unused_config_keys..warn_if_not_used!szMWMM C#'',8 *3%/g*3344i*3345??('(  Nrb)rRrS)rXrZ)r[)rTrUrVN)rz type[PydanticBaseSettingsSource]rrYreturnNone)rr#r%r&)rrrs`` rcrz.BaseSettings._settings_warn_unused_config_keyss9  13VW:B13mnrbextraforbidarbitrary_types_allowedTvalidate_defaultr-Fr1r2variabler/r4r6r8r9r;r<r=r>r@rArBrCrDrErFrGrH-rJrKrMrOrRrSrTrUrVr[rQprotected_namespaces)model_validate model_dumprr\zClassVar[SettingsConfigDict])B*.+/'+-16:*."&,0GK04DH?C(,_c;Ce$Ce/:Ce Ce 3 Ce % Ce'Ce'Ce *Ce *Ce(Ce&Ce#CeCCe<Ce (!Ce")#Ce$%%Ce& +'Ce()4)Ce*(+Ce, -Ce. */Ce0E1Ce2#.3Ce4B5Ce6=7Ce8&9Ce:];Ce<=Ce> ?CeJR(R2R1 R 4 R 9 R 0RR.(,<@"&59'8)-)-,0,0*.(,%)EI>B*.+/'+-16:*."&,0GK04DH?C(,.2;tI$tI/:tI tI 3 tI % tI'tI'tI *tI *tI(tI&tI#tICtI<tI (!tI")#tI$%%tI& +'tI()4)tI*(+tI, -tI. */tI0E1tI2#.3tI4B5tI6=7tI8&9tI:,;tI< G=tItIl<KY >).().7E).N\). ).).Voo<2D&2&2 $&2&2 &2  &2 % &2-2&2&2&2&2"&2"&2 &2&2&2 !&2" #&2$!%&2&'&2(#)&2*',+&2,-&2./&20!1&22!3&24!&5&267&289&2:;&2< =&2>?&2@ A&2B!C&2DE&2FG&2H\I&2JK&2L.&rbrfcJeZdZUdZiZded<ejdZded<e ddZ e ddZ e d dd Z e d dd Z e d dd Ze d dd Ze d ddZy )CliAppz A utility class for running Pydantic `BaseSettings`, `BaseModel`, or `pydantic.dataclasses.dataclass` as CLI applications. z.CliAppBaseSettingsT)r/r-rBrCrDrJrMN)r]r^r_rr+r) model_clssrcCliAppBaseSettingsrjs-''G-48##'#%)#'#Lrbr) issubclassrf)rrs` rc_get_base_settings_clszCliApp._get_base_settings_clses) i .  y "!rbctt|d)|r%tdtjd|dSt j r t j}|rW|jrGgdfd }tj|}|j|jr dt jSS#t$rd}YwxYw)NError: z class is missing z entrypointc tjy#t$r}j|Yd}~yd}~wwxYwr)asynciorun Exceptionappend)ecommandexception_containermodels rcrun_coroz%CliApp._run_cli_cmd..run_coros96 GEN3$6+221556s A>A)targetr)rr)getattrrrr]inspectiscoroutinefunctionrget_running_loop RuntimeError is_running threadingThreadstartjoinr)rcli_cmd_method_name is_requiredlooprthreadrrs` @@rc _run_cli_cmdzCliApp._run_cli_cmdxs$u+':DA ?#gd5k.B.B-CCUViUjju$vwwL  & &w / //1)')#6#)):  &-a00 GEN+   EN 9   sC// C=<C=Nc t|s$t|std|jdd}|dn|}|/t |t t tfr ||}n0||}n&t |t t tfr tdt|tstj|}|j||||\} } |di|j| | } i}|jjD]\} } t!| | |t#| | < |di|}n#|j||||\} } || | f }d }| Dcgc]}t |t$s|c}d }||j&|ftj(t+|< tj-||d }tj(t+|=|Scc}w#tj(t+|=wxYw)a Runs a Pydantic `BaseSettings`, `BaseModel`, or `pydantic.dataclasses.dataclass` as a CLI application. Running a model as a CLI application requires the `cli_cmd` method to be defined in the model class. Args: model_cls: The model class to run as a CLI application. cli_args: The list of CLI arguments to parse. If `cli_settings_source` is specified, this may also be a namespace or dictionary of pre-parsed CLI arguments. Defaults to `sys.argv[1:]`. cli_settings_source: Override the default CLI settings source with a user defined instance. Defaults to `None`. cli_exit_on_error: Determines whether this function exits on error. If model is subclass of `BaseSettings`, defaults to BaseSettings `cli_exit_on_error` value. Otherwise, defaults to `True`. cli_cmd_method_name: The CLI command method name to run. Defaults to "cli_cmd". model_init_data: The model init data. Returns: The ran instance of model. Raises: SettingsError: If model_cls is not subclass of `BaseModel` or `pydantic.dataclasses.dataclass`. SettingsError: If model_cls does not have a `cli_cmd` entrypoint defined. rz? is not subclass of BaseModel or pydantic.dataclasses.dataclassNT) parsed_argsrzRError: `cli_args` must be list[str] or None when `cli_settings_source` is not used)rtr{rur)r :subcommandrFrra)rrrr]rrrdictrrfrrrrrrrrr root_parserridr)rcli_argsrrFrmodel_init_datarr@base_settings_clsrrrrrrsubcommand_destr data_models rcrz CliApp.runsB&i0N94M),,--lm  !)!1x  *.9ot*LM2~N 2G OT(J K tu u)\2 & = =i H #4#K#K .#4%1, $L$ G[ &g(9(P(PQXZe(fgE O*;*H*H*N*N*P p& JU\]bdnUo 9*j QR p2/2G#,#C#C .#4%1, $D$ G[  /EFG'4;e&z&Rc?dvefgh1DFYFeFegv0w  G- 6,,W6IW\,]J((G5 f ((G5sG)GGG2c^t|tjvr!tjt|\}}}n*114GIZ\k3l  J0 9,,Z9LZ^,_J((J8((J8s FF,ctjt|}tt|j ||||}tj ||S)a Serializes the CLI arguments for a Pydantic data model. Args: model: The data model to serialize. list_style: Controls how list-valued fields are serialized on the command line. - 'json' (default): Lists are encoded as a single JSON array. Example: `--tags '["a","b","c"]'` - 'argparse': Each list element becomes its own repeated flag, following typical `argparse` conventions. Example: `--tags a --tags b --tags c` - 'lazy': Lists are emitted as a single comma-separated string without JSON quoting or escaping. Example: `--tags a,b,c` dict_style: Controls how dictionary-valued fields are serialized. - 'json' (default): The entire dictionary is emitted as a single JSON object. Example: `--config '{"host": "localhost", "port": 5432}'` - 'env': The dictionary is flattened into multiple CLI flags using environment-variable-style assignement. Example: `--config host=localhost --config port=5432` positionals_first: Controls whether positional arguments should be serialized first compared to optional arguments. Defaults to `False`. Returns: The serialized CLI arguments for the data model. ) list_style dict_stylepositionals_first)rrrrr_serialized_args_flatten_serialized_args)rr2r3r4rserialized_argss rc serializezCliApp.serialize+s]R#99$u+F+C01BCTT !!/ U  !99/K\]]rbct|tr|n t|}|ht|ts:t|tjvrtjt|^}}nt tj |}|j|j}|s|Stjjd|S)a Return a string containing a help message for a Pydantic model. Args: model: The model or model class. cli_settings_source: Override the default CLI settings source with a user defined instance. Defaults to `None`. strip_ansi_color: Strips ANSI color codes from the help message when set to `True`. Returns: The help message string for the model. r) rrrrrrrr%rrsub)rrstrip_ansi_colorrr help_messages rc format_helpzCliApp.format_help]s$(t4E$u+  &eT*r%yFB!&b&b:bb bb4>B"!&  & :       rbr)@ __future__r _annotationsrrrEr rargparsercollections.abcrtypesrtypingrrr r r r pydanticr pydantic._internal._configrpydantic._internal._signaturerpydantic._internal._utilsrrpydantic.dataclassesr pydantic.mainr exceptionsrrrrrrrrrrrrr r!r"r#r$r%r&r' sources.utilsr(r)r+rr`rrfrrarbrcrUs2 #!@@2CA6#%(, CL>5>N s%55::<== a9aHt t rb