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

Config realize bugfix #525

Merged
merged 13 commits into from
Jul 11, 2024

Conversation

maddenp-noaa
Copy link
Contributor

@maddenp-noaa maddenp-noaa commented Jul 9, 2024

Synopsis

Consider the following reasonable thing you might want to do via the uwtools API (in particular, this might be useful in a loop to apply multiple updates to a base config initially represented as a dict, after which a YAMLConfig, NMLConfig, etc. might be instantiated with this built-up dict to write the final config to disk in the desired format):

import uwtools.api.config as config
cfgdict = config.realize_to_dict(input_config={"a": "apple"}, update_config={"b": "banana"})

Currently, this is the result:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/maddenp/git/uwtools/src/uwtools/api/config.py", line 162, in realize_to_dict
    return _realize(**{**locals(), "output_file": Path(os.devnull), "output_format": None})
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: realize_config() got an unexpected keyword argument 'stdin_ok'

This is due to a bug in how realize_to_dict() is implemented. While fixing the proximate bug, however, I discovered a few other updates needed to support operations on in-memory dict objects, which I think will be a natural thing for API users to want to do. These are annotated via inline PR comments. After the updates:

>>> import uwtools.api.config as config
>>> cfgdict = config.realize_to_dict(input_config={"a": "apple"}, update_config={"b": "banana"})
>>> cfgdict
{'a': 'apple', 'b': 'banana'}

Type

  • Bug fix (corrects a known issue)

Impact

  • This is a non-breaking change (existing functionality continues to work as expected)

Checklist

  • I have added myself and any co-authors to the PR's Assignees list.
  • I have reviewed the documentation and have made any updates necessitated by this change.

@maddenp-noaa maddenp-noaa self-assigned this Jul 9, 2024
src/uwtools/api/config.py Show resolved Hide resolved
src/uwtools/api/config.py Show resolved Hide resolved
src/uwtools/api/config.py Show resolved Hide resolved
src/uwtools/api/config.py Show resolved Hide resolved
src/uwtools/api/config.py Show resolved Hide resolved
src/uwtools/config/tools.py Show resolved Hide resolved
src/uwtools/config/tools.py Show resolved Hide resolved
src/uwtools/tests/config/test_tools.py Show resolved Hide resolved
src/uwtools/tests/utils/test_api.py Show resolved Hide resolved
src/uwtools/utils/api.py Show resolved Hide resolved
src/uwtools/tests/config/test_tools.py Outdated Show resolved Hide resolved
src/uwtools/tests/config/test_tools.py Outdated Show resolved Hide resolved
src/uwtools/utils/api.py Show resolved Hide resolved
@maddenp-noaa maddenp-noaa merged commit 1835fe6 into ufs-community:main Jul 11, 2024
2 checks passed
@maddenp-noaa maddenp-noaa deleted the config-realize-bugfix branch July 11, 2024 14:30
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.

5 participants