feat: adding json, yaml and toml sources#211
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #211 +/- ##
==========================================
+ Coverage 97.61% 97.63% +0.01%
==========================================
Files 5 5
Lines 336 423 +87
Branches 71 89 +18
==========================================
+ Hits 328 413 +85
- Misses 6 7 +1
- Partials 2 3 +1 ☔ View full report in Codecov by Sentry. |
|
I think you mean toml, not JSON - please update the title. |
|
in fact it have the three of them :D. please review |
|
Thanks @Smixi for the PR 🙏 A couple of things to address:
|
| from pydantic_settings.utils import path_type_label | ||
|
|
||
| if TYPE_CHECKING: | ||
| if sys.version_info.minor >= 11: |
There was a problem hiding this comment.
| if sys.version_info.minor >= 11: | |
| if sys.version_info >= (3, 11): |
If they are default loaded, it means the default settings class is in |
|
Here is the source settings priority right now:
So, if we add new sources at the end there shouldn't be a breaking change and there will be new sources that users can use by defining the file path and encoding in config. It means that releasing the new |
|
My concerns is more about user having their own custom orders. They will need to reimplement the |
That's a good point. didn't think about this. |
ba9fc69 to
d848544
Compare
|
@hramezani That should be good. I just don't know how to deal with the coverage. |
| return {} | ||
| if isinstance(files, (str, os.PathLike)): | ||
| files = [files] | ||
| vars: dict[str, Any | None] = {} |
There was a problem hiding this comment.
| vars: dict[str, Any | None] = {} | |
| vars: dict[str, Any] = {} |
| return vars | ||
|
|
||
| @abstractmethod | ||
| def _read_file(self, path: Path) -> dict[str, Any | None]: |
There was a problem hiding this comment.
| def _read_file(self, path: Path) -> dict[str, Any | None]: | |
| def _read_file(self, path: Path) -> dict[str, Any]: |
|
|
||
|
|
||
| class ConfigFileSourceMixin(ABC): | ||
| def _read_files(self, files: PathType | None) -> dict[str, Any | None]: |
There was a problem hiding this comment.
| def _read_files(self, files: PathType | None) -> dict[str, Any | None]: | |
| def _read_files(self, files: PathType | None) -> dict[str, Any]: |
There was a problem hiding this comment.
As in env settings, I think this is allowed in config files to have null values, as it's defined in json and in yaml specs ?
Or is this because None is included in any ?
Changed
|
|
||
| def _read_file(self, file_path: Path) -> dict[str, Any | None]: | ||
| with open(file_path, encoding=self.yaml_file_encoding) as yaml_file: | ||
| import_yaml() |
There was a problem hiding this comment.
Isn't it better to move import_yaml out of the block to check the import before opening the file?
I think it can be tested like the old dotenv test in Pydantic V1 and then you can add a new step to the CI to uninstall deps and run the tests to run the above tests |
|
LGTM. Thanks @Smixi. @samuelcolvin I will keep this PR open. please take a look if you want. |
|
Hi @Smixi, I have a question: |
|
@korolkevich This PR is only a loader for variables. |
samuelcolvin
left a comment
There was a problem hiding this comment.
otherwise LGTM.
Thank you so much.
| foobar = "Hello" | ||
| [nested] | ||
| nested_field = "world!" | ||
| """ |
There was a problem hiding this comment.
I don't understand what this is?
|
Thanks @Smixi |
feat: #210
Selected Reviewer: @samuelcolvin