-
-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add PyprojectTomlConfigSettingsSource
#255
Conversation
Thanks @ITProKyle for this PR. I still haven't looked at it in detail.
Isn't it better to have a
Let's have a default header. something like |
I changed
The rationale behind supporting discovery is to mirror the behavior of most tools (I have used) that use However, I feel that Here are a few references for the discovery behavior:
black and ruff's discovery behavior can both be checked within this project by |
👍
Can we have the same behavior here as well?(I still haven't checked the code. So, if you implemented like this it would be fine) |
ya, that's there. explicitly provided when instantiating the source class ( By default, discovery is set to a depth of |
return (PyprojectTomlConfigSettingsSource(settings_cls),) | ||
|
||
|
||
class RootSettings(Settings): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you define the RootSettings
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like I forgot to update the example code after adding a default. This is to show how to load from different locations. Updating this in an incoming commit plus adding a third example to show another use case.
Settings
for using the default tableSomeTableSettings
replaces whatSettings
was doing before, providing apyproject_toml_table_header
config value with a different table headerRootSettings
updated to work as I had it before setting a default header, loading from the root of pyproject.toml
docs/index.md
Outdated
model_config = SettingsConfigDict(extra='ignore') | ||
``` | ||
|
||
This will be able to read the following "pyproject.toml" file, located in your working directory, resulting in `Settings(field='some-table')` & `RootSettings(field='root')`: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RootSettings
also will be RootSettings(field='some-table')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as previous comment, I overlooked updating this. A fix is prepped in an incoming commit.
@@ -0,0 +1,99 @@ | |||
"""Test pydantic_settings.sources.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest moving the important tests here to the test_settings
file as a complete test case.
for example:
- Test for a custom
pyproject.toml
file - Test for different depth
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added some tests to test_settings.py
for additional coverage. However, I added these test to test_sources.py
to make assertions at the source level that arn't possible (from what I can tell) at the BaseSettings
subclass level (e.g. asserting that the correct file path is chosen). This can be inferred from the settings level by doing things like only creating a single file with the expected value but it's not quite as precise.
I'll leave this file in place for now with the additional tests added to test_settings.py
. If you feel they are still not necessary, feel free to delete the file or LMK and I can do it alongside any additional changes requested.
Thanks @ITProKyle for updating the PR. Overall LGTM. I left a couple of comments. Please update |
this scopes the setting to the class that uses it. leaves room for the TOML source class to support `toml_table_header` with a different value (global settings) in the future if desired
Thanks @ITProKyle |
Change Summary
PyprojectTomlConfigSettingsSource
source classpyproject.toml
file to fill variablesSettingsConfigDict.pyproject_toml_depth
(only used byPyprojectTomlConfigSettingsSource
)pyproject.toml
if not found in the current working directory0
is usedSettingsConfigDict.pyproject_toml_table_header
(only used byPyprojectTomlConfigSettingsSource
)Related issue number
resolves #253
Checklist