-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
Migrate to Ruff & use pydantic-settings for config #28
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ChrisLovering
force-pushed
the
ruff-pydantic-settings
branch
from
September 12, 2023 21:20
c085435
to
4a05273
Compare
ChrisLovering
force-pushed
the
ruff-pydantic-settings
branch
from
September 12, 2023 22:19
4a05273
to
ab4b3d6
Compare
ChrisLovering
force-pushed
the
ruff-pydantic-settings
branch
from
September 12, 2023 22:28
ab4b3d6
to
b15aeef
Compare
ChrisLovering
force-pushed
the
ruff-pydantic-settings
branch
from
September 12, 2023 22:29
b15aeef
to
59b0485
Compare
ChrisLovering
force-pushed
the
ruff-pydantic-settings
branch
from
September 12, 2023 22:40
f67343f
to
19bf5b1
Compare
ChrisLovering
force-pushed
the
ruff-pydantic-settings
branch
from
September 12, 2023 23:20
f2fdbcd
to
1561d04
Compare
jb3
reviewed
Sep 12, 2023
Comment on lines
+11
to
+49
def custom_decode_complex_value( | ||
__: str, | ||
___: fields.FieldInfo, | ||
value: t.Any, | ||
) -> t.Any: | ||
"""Parse complex values as CSV if they cannot be parsed as JSON.""" | ||
try: | ||
return json.loads(value) | ||
except ValueError: | ||
return value.split(",") | ||
|
||
|
||
class EnvConfig( | ||
BaseSettings, | ||
env_file=".env", | ||
env_file_encoding="utf-8", | ||
env_nested_delimiter="__", | ||
extra="ignore", | ||
): | ||
"""Our default configuration for models that should load from .env files.""" | ||
|
||
@classmethod | ||
def settings_customise_sources( | ||
cls, | ||
settings_cls: type[BaseSettings], | ||
init_settings: PydanticBaseSettingsSource, | ||
env_settings: PydanticBaseSettingsSource, | ||
dotenv_settings: PydanticBaseSettingsSource, | ||
file_secret_settings: PydanticBaseSettingsSource, | ||
) -> tuple[PydanticBaseSettingsSource, ...]: | ||
"""Monkey patch default sources to have the custom CSV parser fallback.""" | ||
dotenv_settings.decode_complex_value = custom_decode_complex_value | ||
env_settings.decode_complex_value = custom_decode_complex_value | ||
return ( | ||
init_settings, | ||
env_settings, | ||
dotenv_settings, | ||
file_secret_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.
jb3
approved these changes
Sep 12, 2023
ChrisLovering
temporarily deployed
to
github-pages
September 12, 2023 23:25
— with
GitHub Pages
Inactive
ChrisLovering
had a problem deploying
to
development
September 12, 2023 23:26
— with
GitHub Actions
Failure
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This will require changes to the deployment.yaml, and secrets added to production before merging.