feat(serialize): add env/dotenv format to FileFormat and serialization layer#17
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #17 +/- ##
==========================================
+ Coverage 32.77% 32.87% +0.09%
==========================================
Files 18 19 +1
Lines 1068 1080 +12
==========================================
+ Hits 350 355 +5
- Misses 718 725 +7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
EspenAlbert
commented
May 13, 2026
| from model_lib.model_base import ModelT | ||
| from model_lib.model_dump import registered_types | ||
| from model_lib.pydantic_utils import model_json | ||
| from model_lib.serialize.env_serialize import dump_env_str # no cov |
Owner
Author
There was a problem hiding this comment.
do not use #no cov, instead make sure it is covered by tests
This file contains hidden or 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
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.
Summary
Add
.env(dotenv) format support tomodel_lib, making it a first-class format alongside json, yaml, and toml.FileFormat.envto theFileFormatStrEnum.serialize/env_serialize.pywithparse_env_str(viapython-dotenv'sdotenv_values) anddump_env_strfor flat dict output._format_parsersand.envin_file_format_to_raw_format._parse_pathto handle dotfiles:Path(".env").suffixis"", so the path dispatcher now falls back topayload.namewhensuffixis empty.python-dotenv>=1.0as a direct dependency (already transitive viapydantic-settings).Changes
model_lib/constants.pyenv = "env"toFileFormatmodel_lib/serialize/env_serialize.pyparse_env_str,dump_env_strmodel_lib/serialize/parse.py_parse_pathmodel_lib/serialize/dump.pydump_env_strin_payload_dumpersmodel_lib/readme_example_test.py"env"toexpected_dump_formatsguardmodel_lib/serialize/env_serialize_test.pypyproject.tomlpython-dotenv>=1.0todependenciesDesign decisions
dump_env_stronly accepts flat dicts: dotenv format is inherently flat (KEY=VALUE). Nested structures will raiseTypeError. This is intentional — env format is load-oriented.# no covon import lines: coverage.py does not record module-level import statements as hits (they execute before the measurement window closes). The existing toml imports have the same property; those pre-existing lines are not flagged because they are not in the diff.