Skip to content

feat(serialize): add env/dotenv format to FileFormat and serialization layer#17

Merged
EspenAlbert merged 6 commits into
mainfrom
env-parse-support
May 15, 2026
Merged

feat(serialize): add env/dotenv format to FileFormat and serialization layer#17
EspenAlbert merged 6 commits into
mainfrom
env-parse-support

Conversation

@EspenAlbert
Copy link
Copy Markdown
Owner

@EspenAlbert EspenAlbert commented May 12, 2026

Summary

Add .env (dotenv) format support to model_lib, making it a first-class format alongside json, yaml, and toml.

  • Add FileFormat.env to the FileFormat StrEnum.
  • New serialize/env_serialize.py with parse_env_str (via python-dotenv's dotenv_values) and dump_env_str for flat dict output.
  • Register the parser in _format_parsers and .env in _file_format_to_raw_format.
  • Fix _parse_path to handle dotfiles: Path(".env").suffix is "", so the path dispatcher now falls back to payload.name when suffix is empty.
  • Add python-dotenv>=1.0 as a direct dependency (already transitive via pydantic-settings).

Changes

File What
model_lib/constants.py Add env = "env" to FileFormat
model_lib/serialize/env_serialize.py New: parse_env_str, dump_env_str
model_lib/serialize/parse.py Register env parser; fix dotfile suffix detection in _parse_path
model_lib/serialize/dump.py Register dump_env_str in _payload_dumpers
model_lib/readme_example_test.py Add "env" to expected_dump_formats guard
model_lib/serialize/env_serialize_test.py New: 5 tests covering parse, dump, and Path dispatch
pyproject.toml Add python-dotenv>=1.0 to dependencies

Design decisions

  • dump_env_str only accepts flat dicts: dotenv format is inherently flat (KEY=VALUE). Nested structures will raise TypeError. This is intentional — env format is load-oriented.
  • # no cov on 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.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 12, 2026

Codecov Report

❌ Patch coverage is 46.15385% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 32.87%. Comparing base (12cfa50) to head (c9633f6).
⚠️ Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
model_lib/serialize/env_serialize.py 50.00% 5 Missing ⚠️
model_lib/serialize/dump.py 0.00% 1 Missing ⚠️
model_lib/serialize/parse.py 50.00% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@EspenAlbert EspenAlbert changed the title todo update me with the PR title for branch env-parse-support feat(serialize): add env/dotenv format to FileFormat and serialization layer May 12, 2026
@EspenAlbert EspenAlbert marked this pull request as ready for review May 12, 2026 20:10
Comment thread model_lib/serialize/dump.py Outdated
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
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not use #no cov, instead make sure it is covered by tests

@EspenAlbert EspenAlbert enabled auto-merge May 15, 2026 13:36
@EspenAlbert EspenAlbert merged commit 073be84 into main May 15, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants