pydantic-settings-helper 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of pydantic-settings-helper might be problematic. Click here for more details.

@@ -0,0 +1,47 @@
1
+ from pydantic import Field, ValidationError
2
+ from pydantic_settings import BaseSettings
3
+
4
+
5
+ class PydanticSettingsSetupError(RuntimeError):
6
+ """Custom exception for Pydantic settings setup errors."""
7
+
8
+ def __init__(self, message: str, original_exception: ValidationError | None = None):
9
+ super().__init__(message)
10
+ self.message = message
11
+ self.original_exception = original_exception
12
+
13
+
14
+ def load_settings[SettingsClass: type[BaseSettings]](
15
+ settings_class: SettingsClass,
16
+ ) -> SettingsClass:
17
+ model_config = settings_class.model_config
18
+ env_prefix = model_config.get("env_prefix")
19
+ cli_prefix = model_config.get("cli_prefix")
20
+ try:
21
+ return settings_class()
22
+ except ValidationError as exc:
23
+ lines = ["\nConfiguration error — missing values:\n"]
24
+ for err in exc.errors():
25
+ error_location: tuple[int | str, ...] = err["loc"]
26
+ full_error_location = ".".join(
27
+ str(error_location_part) for error_location_part in error_location
28
+ )
29
+ env_var = f"{env_prefix}{full_error_location.replace('.', '_').upper()}"
30
+ cli_flag = f"--{cli_prefix}{full_error_location.replace('.', '-')}"
31
+ lines.append(
32
+ f" • `{full_error_location}` → set via ${env_var!r} or `{cli_flag}`"
33
+ )
34
+ raise PydanticSettingsSetupError("\n".join(lines), exc)
35
+
36
+
37
+ def SettingsSubModel(
38
+ *args,
39
+ **kwargs,
40
+ ):
41
+ """A wrapper for Field to create a settings sub-model."""
42
+ return Field(
43
+ *args,
44
+ default_factory=dict,
45
+ validate_default=True,
46
+ **kwargs,
47
+ )
@@ -0,0 +1,13 @@
1
+ Metadata-Version: 2.4
2
+ Name: pydantic-settings-helper
3
+ Version: 0.1.0
4
+ Summary: Add your description here
5
+ Author-email: Sygmei <3835355+Sygmei@users.noreply.github.com>
6
+ License-File: LICENSE
7
+ Requires-Python: >=3.12
8
+ Requires-Dist: pydantic-settings>=2.9.1
9
+ Requires-Dist: pydantic>=2.11.3
10
+ Description-Content-Type: text/markdown
11
+
12
+ # pydantic-settings-helper
13
+ Little helper for pydantic-settings to improve error message and nesting
@@ -0,0 +1,6 @@
1
+ pydantic_settings_helper/__init__.py,sha256=GogD46WliYH73XshssfALNme2zxzPbeZx4ycKj8mDec,1629
2
+ pydantic_settings_helper-0.1.0.dist-info/METADATA,sha256=uprhtOqNMeJDbJ_U78wef8BcU0NYbln--PMwSMPSCP4,425
3
+ pydantic_settings_helper-0.1.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
4
+ pydantic_settings_helper-0.1.0.dist-info/entry_points.txt,sha256=Ml0SXc-npTX_UMQoafN57CyOxgXof26kOe9kYwXDKKI,75
5
+ pydantic_settings_helper-0.1.0.dist-info/licenses/LICENSE,sha256=rJuVDmpsbuFanqGEGWPHTuiLeH7vSw_UGZRuqju20HE,1084
6
+ pydantic_settings_helper-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.27.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ pydantic-settings-helper = pydantic_settings_helper:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Sygmei
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.