Skip to content

Redesign config validation#412

Open
swpenninga wants to merge 4 commits into
openh-rffrom
redesign-config-schema-clean
Open

Redesign config validation#412
swpenninga wants to merge 4 commits into
openh-rffrom
redesign-config-schema-clean

Conversation

@swpenninga
Copy link
Copy Markdown
Contributor

Regarding #407 , #408 had broken through merge, new PR.

Redesign Config validation as dataclass-based Specs

Replaces the schema-library validation layer with dataclass-based Specs, aligning Config validation with the ProbeSpec/ScanSpec pattern used elsewhere in the codebase. The parameters section is now open/extensible by design rather than via the interim ignore_extra_keys=True workaround.

What changed

zea/internal/config/validation.py — full rewrite:

  • New ConfigSpec base class (dataclass + __post_init__ validation + from_dict/to_dict + introspection helpers field_names/required_fields/all_field_paths), mirroring the Spec style but for config values rather than numpy arrays.
  • Section specs DataConfig, PlotConfig, PipelineConfig, ParametersConfig, and top-level ConfigSchema, with every field/default/validator ported 1:1.
  • Small validator helpers (enum, regex, any_of, optional, numeric/range checks) replacing Or/And/Regex.
  • The parameters section and the top-level config are open by design (ALLOW_EXTRA = True) — arbitrary keys are stored and re-emitted unchanged, mirroring zea.Parameters._custom_params. This replaces the ignore_extra_keys=True workaround, which is gone.
  • Deprecated postprocess_schema removed (no consumers).
  • New validate_config(dict) -> dict entry point.

zea/config.pycheck_config now calls validate_config instead of config_schema.validate.

zea/internal/config/create.py — interactive creator rewritten to traverse the specs via introspection; input coerced with yaml.safe_load + validators. Also fixed its already-broken check_config import (now from zea.config).

docs/source/parameters_doc.pyflatten_schema_keys replaced by ConfigSchema.all_field_paths(); deprecated scan alias tolerated via a DEPRECATED_KEYS set.

Tests — new tests/test_config_validation.py (defaults, required-field errors, enum/range/regex rejection, valid devices, parameters & top-level pass-through, idempotency, scan→parameters migration, freeze behavior); tests/test_configs.py updated to drop the schema import.

Note on the schema dependency

schema >=0.7 is left in pyproject.toml: it's still used by zea/data/convert/verasonics.py (unrelated to config), so removing it isn't safe. Nothing under zea/, docs/, or tests/ imports schema for config purposes anymore.

@swpenninga swpenninga requested a review from tristan-deep June 4, 2026 09:15
@swpenninga swpenninga added the data format Related to the zea data format saving and loading label Jun 4, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 4, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 55e48b6f-4b3d-4f8f-a8ca-de5e89a2092a

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch redesign-config-schema-clean

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@swpenninga swpenninga mentioned this pull request Jun 4, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 4, 2026

Codecov Report

❌ Patch coverage is 69.13580% with 75 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
zea/internal/config/validation.py 73.07% 39 Missing and 17 partials ⚠️
zea/data/convert/verasonics.py 26.92% 11 Missing and 8 partials ⚠️

📢 Thoughts on this report? Let us know!

Comment thread zea/internal/config/validation.py Outdated
(consistent with :class:`zea.Parameters`).
"""

xlims: Any = None
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

ParametersConfig is now really defined in here, while we can also inherit that in some way from ProbeSpec + ConfigSpec. Kind of what is being done in the zea.Parameters class now already. That way there is a signal source of truth that defines which parameters are in the spec.

import sys
from pathlib import Path

from schema import And, Optional, Or, Schema
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

TODO: we can probably remove the schema package from dep list as well in our toml

- Strip DataConfig to path/local/indices/user; remove dtype, dynamic_range,
  resolution, apodization, to_dtype, input_range, output_range
- Consolidate dataset_folder + file_path into a single path field (supports hf://)
- Rename frame_no → indices in DataConfig and all YAML configs
- ParametersConfig becomes a pure open pass-through (no predefined fields)
- Remove PlotConfig; keep DataConfig for path management in setup_zea
- Delete zea/interface.py and tests/test_interface.py (Interface class was outdated)
- Replace schema library dependency with inline _validate_convert_config()
- Rewrite config.rst as a hand-authored paradigm doc with explicit key reference tables
- Redesign parameters_doc.py (no RST generation, workspace path fix)
- Fix docs build: remove interface refs from __init__.py, autosummary, cli.rst
- Add Config() TypeError when a path string is passed instead of a dict
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

data format Related to the zea data format saving and loading

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants