Skip to content
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 public config_file attribute to Config classes #679

Merged
merged 4 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/uwtools/config/formats/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,13 @@ def compare_config(
log.info(diffline.rstrip())
return False

@property
def config_file(self) -> Optional[Path]:
"""
Return the path to the config file from which this object was instantiated, if applicable.
"""
return self._config_file

def dereference(self, context: Optional[dict] = None) -> None:
"""
Render as much Jinja2 syntax as possible.
Expand Down
5 changes: 5 additions & 0 deletions src/uwtools/tests/config/formats/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ def test_compare_config_ini(caplog, salad_base):
assert not logged(caplog, line)


def test_config_file(config):
assert config.config_file.name == "config.yaml"
assert config.config_file.is_file()


def test_dereference(tmp_path):
# Test demonstrates that:
# - Config dereferencing ignores environment variables.
Expand Down
Loading