Commit ead67d7
Modernize API with
* Remove CLI module in favor of manual parsing pattern
Remove the built-in CLI parsing utilities (`Config.from_cli()`, `parse_override()`, `parse_overrides()`) to simplify the library and encourage users to handle their own argument parsing with standard libraries like argparse, click, typer, or fire.
**Why:**
- Reduces library complexity and maintenance burden
- Users have full control over CLI behavior and flags
- Works better with diverse CLI frameworks
- The recommended pattern is simple: just 3 lines of code for basic CLI override parsing
**Migration path:**
```python
# Old way
config = Config.from_cli("config.yaml", sys.argv[1:])
# New way (3 lines)
config = Config()
config.update("config.yaml")
for arg in sys.argv[1:]:
if "=" in arg:
key, value = arg.split("=", 1)
try:
value = ast.literal_eval(value)
except (ValueError, SyntaxError):
pass
config.set(key, value)
```
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
* Add type coercion system for schema validation
Introduce automatic type coercion to convert compatible types during validation, making configs more flexible and user-friendly.
**Features:**
- String to numeric conversion (`"123"` → `123`, `"3.14"` → `3.14`)
- Numeric type conversion (`1` → `1.0` for float fields)
- String to bool parsing (`"true"`, `"yes"`, `"1"` → `True`)
- List/tuple interconversion
- Dict to dataclass conversion (nested structures)
- Preserves None values and handles Optional types correctly
**Example:**
```python
@DataClass
class Config:
port: int
rate: float
config = Config()
config.update({"port": "8080", "rate": "0.5"}) # Strings coerced!
config.validate(Config) # ✓ Works! port=8080, rate=0.5
```
**Implementation:**
- `coerce_value()`: Core coercion logic with recursive support
- Smart type detection and conversion with fallback to original value
- Integration with `_validate_field()` in schema.py
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
* Enhance config API with freeze/unfreeze and MISSING support
Add advanced configuration features for better control and partial config support.
**New Features:**
1. **Frozen Configs** - Prevent mutations after initialization:
```python
config.freeze() # Lock config
config.set("key", "value") # Raises FrozenConfigError
config.unfreeze() # Allow mutations again
```
2. **MISSING Sentinel** - Support partial configs with required-but-not-yet-set values:
```python
config = Config(allow_missing=True)
config.update({"api_key": MISSING}) # Placeholder for later
config.set("api_key", os.getenv("API_KEY")) # Fill in
config.validate(schema) # Ensure complete (allow_missing=False by default)
```
3. **Continuous Validation** - Validate on every mutation when schema provided:
```python
config = Config(schema=MySchema) # Enable continuous validation
config.update(data) # Validates immediately!
config.set("port", "invalid") # Raises ValidationError
```
**API Changes:**
- Add `freeze()`, `unfreeze()`, `is_frozen()` methods
- Add `MISSING` sentinel constant
- Add `allow_missing` parameter to `Config()` and `validate()`
- Integrate type coercion into validation pipeline
- Enhanced error messages with field paths
**Tests:**
- Comprehensive test coverage for freeze/unfreeze behavior
- MISSING sentinel edge cases
- Continuous validation scenarios
- Updated existing tests for new API patterns
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
* Comprehensive documentation updates for v0.0.5
Update all documentation to reflect the new API design, removed CLI module, and new features (type coercion, freeze/unfreeze, MISSING sentinel).
**Major Changes:**
1. **Installation Guide** (`installation.md`):
- Simplified just installation instructions (use package managers)
- Removed optional dependencies section (minimal deps by design)
- Cleaner setup instructions
2. **Quickstart Guide** (`quickstart.md`):
- Update to new API: `Config()` + `.update()` pattern (no more `.load()`)
- Show manual CLI override parsing (3-line pattern with ast.literal_eval)
- Method chaining examples for cleaner code
3. **CLI Overrides** (`cli.md` - major rewrite):
- Remove `Config.from_cli()`, `parse_override()` references
- Show auto-detection pattern: `.update()` handles both files and overrides
- Examples for argparse, Click, Typer, Fire
- Manual override parsing with `parse_overrides()` for advanced use
- Simplified mental model: just loop over args!
4. **Core User Guides**:
- `basics.md`: Update all examples to `Config().update()` pattern
- `operators.md`: Add composition decision flow diagram
- `advanced.md`: Add frozen configs and MISSING sentinel sections
- `schema-validation.md`: Document continuous validation and type coercion
- `references.md`: Update API references
5. **Index Page** (`index.md`):
- Update feature descriptions (continuous validation)
- Modernize all code examples
- Show new patterns throughout
6. **Examples Cleanup**:
- Delete outdated examples: `simple.md`, `deep-learning.md`, `custom-classes.md`
- Add new `quick-reference.md` with concise API overview
7. **MkDocs Config** (`mkdocs.yml`):
- Remove examples section from navigation
- Add quick-reference to user guide
- Update structure for clearer organization
**Documentation Philosophy:**
- Show the simplest pattern first (Config().update())
- Encourage users to use their preferred CLI library
- Emphasize composition-by-default with explicit operators
- Highlight continuous validation benefits
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
* Add schema suffix to schema dataclasses in docs examples
* Improve github workflows
* Fix GitHub Actions workflows and type checking errors
Workflow Fixes:
- Fix YAML syntax in check_pull_request_title.yml
- Remove problematic types parameter (not needed with custom subjectPattern)
Type Checking Fixes (66 errors resolved):
- Keep strict mypy flags enabled (disallow_any_generics, warn_unreachable)
- Add explicit type parameters throughout (dict[str, Any], list[Any], set[Any])
- Add type annotations to helper functions (_is_union_type, etc.)
- Fix PathLike type parameter (Union[str, os.PathLike[str]])
- Add proper type hints to levenshtein_distance and ensure_tuple
- Add type assertions for dataclass field types
- Handle false positive unreachable warnings with targeted type ignores
Files modified:
- schema.py, coercion.py: Type annotations and assertions
- config.py, loader.py, items.py: Dict/list/set type parameters
- preprocessor.py, operators.py, resolver.py: Type parameters
- utils/types.py, utils/misc.py, utils/module.py: Type fixes
- errors/suggestions.py: Levenshtein distance types
All 24 source files pass strict type checking.
* Fix false mypy flag
* Add codecov.yml. Fix more mypy.
---------
Co-authored-by: Claude <[email protected]>.update(), freeze/MISSING, and type coercion (#3)1 parent c95f7e6 commit ead67d7
File tree
49 files changed
+2721
-1698
lines changed- .github
- actions/setup
- scripts
- workflows
- docs
- examples
- getting-started
- user-guide
- src/sparkwheel
- errors
- utils
- tests
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
49 files changed
+2721
-1698
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
6 | 16 | | |
7 | 17 | | |
8 | 18 | | |
| 19 | + | |
9 | 20 | | |
10 | 21 | | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
16 | 25 | | |
| 26 | + | |
17 | 27 | | |
18 | 28 | | |
19 | | - | |
20 | | - | |
21 | | - | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
22 | 32 | | |
23 | 33 | | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
0 commit comments