Skip to content

Add audeer.load_configuration()#195

Open
hagenw wants to merge 11 commits into
mainfrom
config-handling-helper
Open

Add audeer.load_configuration()#195
hagenw wants to merge 11 commits into
mainfrom
config-handling-helper

Conversation

@hagenw

@hagenw hagenw commented Jul 8, 2026

Copy link
Copy Markdown
Member

Add audeer.load_configuration() to provide a unified way for handling configuration files, including providing a default config file, supporting overriding by user config files and by environment variables.

The new function can then be reused inside audb and audmodel and will solve audeering/audb#485.

We need pyaml to read the configuration files, but to not add a new default dependency we add it as optonal dependency that you need to enable with audeer[yaml] in order to use audeer.load_configuration().

I also update the unrelated tests/test_install.py as it used pyyaml before in the tests. As this is now a dependency of audeer, I switched to python-dotenv.

image image

@sourcery-ai

sourcery-ai Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Introduce audeer.load_configuration() as a unified configuration loader with YAML file + environment variable merging, wire it into the top-level package API, add tests and optional YAML dependency, and adjust install tests to use wrapt instead of PyYAML.

Flow diagram for audeer.load_configuration() merging logic

flowchart TD
    A[Call load_configuration] --> B[Load default_config_file via _load_configuration_file]
    B --> C{user_config_files provided?}
    C -- no --> D{env_prefix provided?}
    C -- yes --> E[Iterate user_config_files and merge with _load_configuration_file]
    E --> D
    D -- no --> G{validate callable provided?}
    D -- yes --> F[Override values with environment via _override_with_environment]
    F --> G
    G -- yes --> H[Call validate on merged config]
    G -- no --> I[Return merged config]
    H --> I

    subgraph File_loading
        B
        E
    end

    subgraph Environment_override
        F --> J[For each config key, read env var and parse via _parse_environment_value]
    end
Loading

File-Level Changes

Change Details Files
Add unified configuration loading helper that merges default, user, and environment-based settings with type-aware casting.
  • Implement load_configuration() to load a default YAML config file, apply one or more user config files in order, optionally override values from environment variables, and call an optional validator on the merged config.
  • Add _load_configuration_file() to lazily import pyyaml, read a YAML file if it exists, and return an empty dict for missing or empty files.
  • Add _override_with_environment() to update a config dict in place based on env_prefix_UPPERCASED_KEY variables only for existing keys.
  • Add _parse_environment_value() to convert environment strings to bool, int, float, list, or dict, using JSON parsing for list/dict types.
audeer/core/config.py
Expose the new configuration loader in the public API and document/install its YAML dependency properly.
  • Export load_configuration from the audeer package’s init to make it part of the public API.
  • Declare an optional 'yaml' extra in pyproject.toml that installs pyyaml and add pyyaml to the dev dependencies for tests and docs.
  • Add/load API docs stub entry for the updated audeer API (if applicable in the docs tree).
audeer/__init__.py
pyproject.toml
docs/api-src/audeer.rst
Extend test coverage for configuration loading behavior and adjust install tests to avoid depending on PyYAML itself as the test package.
  • Add tests for load_configuration covering missing and empty files, default vs user configs, multiple user files, environment overrides with type casting, boolean false handling, and validator execution/raising.
  • Change tests that exercise audeer.install_package() to use the 'wrapt' package instead of 'PyYaml', updating version constraints accordingly.
tests/test_config.py
tests/test_install.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codecov

codecov Bot commented Jul 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.0%. Comparing base (409724c) to head (82b4902).

Additional details and impacted files
Files with missing lines Coverage Δ
audeer/__init__.py 100.0% <100.0%> (ø)
audeer/core/config.py 100.0% <100.0%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

sourcery-ai[bot]

This comment was marked as resolved.

@hagenw hagenw self-assigned this Jul 8, 2026
@hagenw hagenw requested a review from frankenjoe July 9, 2026 10:53
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.

1 participant