Add TOML configuration file support for server settings (#248)#261
Add TOML configuration file support for server settings (#248)#261
Conversation
|
@claude Review this PR. |
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
902d46d to
10bd1f7
Compare
|
@claude Review the code. |
|
Claude finished @from2001's task in 2m 6s —— View job Code Review Complete ✅I've completed a thorough review of the TOML configuration file support implementation. Overall, this is a well-designed and well-tested feature with strong architecture. Here are my findings: ✅ Strengths1. Excellent Architecture
2. Comprehensive Test Coverage
3. User Experience
4. Code Quality
🔍 Issues FoundCritical IssuesNone identified - the implementation is solid. Medium Priority1. Using
|
|
@claude Explain about the TOML configuration based on the latest code. |
|
Claude finished @from2001's task in 1m 58s —— View job TOML Configuration ExplanationThis PR adds comprehensive TOML-based configuration file support for the STYLY NetSync Server. Below is a complete explanation of the feature based on the latest code. 📋 OverviewThe TOML configuration feature allows you to customize server settings using configuration files instead of only relying on CLI arguments. This makes it easier to manage different server deployments and maintain consistent configurations across environments. Key Features:
🎯 Configuration PriorityThe configuration system uses a three-layer priority model: Example:
This allows you to:
📁 Configuration File StructureConfiguration files use TOML format with five main sections: 1.
|
| File | Type | Description |
|---|---|---|
src/styly_netsync/config.py |
NEW | Configuration management module (434 lines) |
src/styly_netsync/default.toml |
NEW | Default configuration (bundled with package) |
examples/config.toml |
NEW | Example user configuration with documentation |
tests/test_config.py |
NEW | Comprehensive test suite (811 lines, 47 tests) |
src/styly_netsync/server.py |
MODIFIED | Integration with config system |
src/styly_netsync/binary_serializer.py |
MODIFIED | Configurable max_virtual_transforms |
pyproject.toml |
MODIFIED | Added tomli-w dev dependency for testing |
🎓 Key Design Decisions
- Uses Python 3.11+ built-in
tomllib- No external dependencies for TOML parsing - Dataclass-based config - Type-safe with IDE autocomplete support
- Immutable updates - Uses
dataclass_replace()instead of mutation - Bundled defaults -
default.tomlshipped with package viaimportlib.resources - Validation before startup - Catches errors early with helpful messages
- Unknown key detection - Warns about typos without failing
- Backward compatible - Works without config files (all defaults provided)
✨ Summary
The TOML configuration feature provides a robust, flexible, and user-friendly way to configure the STYLY NetSync Server. It balances ease-of-use (sensible defaults) with flexibility (full customization) while maintaining backward compatibility and providing excellent error messages.
Benefits:
- 📝 Easy to read and edit configuration files
- 🔧 Fine-grained control over all server settings
- 🎯 Clear precedence rules (CLI > User Config > Defaults)
- ✅ Comprehensive validation with helpful errors
- 🔍 Typo detection for unknown keys
- 🧪 Excellent test coverage (93%)
- 📦 Zero external dependencies (uses stdlib tomllib)
Branch: feature/248-config-file-support
Introduce configuration file support for STYLY NetSync Server. This commit adds: - New config.py module with ServerConfig dataclass - --config CLI option to specify TOML configuration file - Network settings: dealer_port, pub_port, server_discovery_port, server_name, enable_server_discovery - Configuration validation and CLI argument merging - Comprehensive unit tests for configuration module Configuration priority: CLI args > config file > defaults 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Extend configuration file support with timing and performance settings: - base_broadcast_interval, idle_broadcast_interval, dirty_threshold - client_timeout, cleanup_interval, device_id_expiry_time - status_log_interval, main_loop_sleep, poll_timeout NetSyncServer now accepts a ServerConfig object and uses timing values from configuration instead of class constants. Backward compatibility is maintained when config is not provided. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Extend configuration with NetworkVariable limit and monitoring settings: - max_global_vars, max_client_vars: Variable count limits - max_var_name_length, max_var_value_length: Size limits - nv_flush_interval: Flush cadence configuration - nv_monitor_window_size, nv_monitor_threshold: Monitoring settings NetSyncServer now reads NV limits and monitoring parameters from config. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Extend configuration with internal system limits: - max_virtual_transforms: Maximum virtual transforms per client - pub_queue_maxsize: Publisher queue size limit - delta_ring_size: NV sync delta ring buffer size Add set/get_max_virtual_transforms() functions to binary_serializer.py for dynamic configuration of the virtual transform limit. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add logging section to TOML configuration with: - log_dir: Directory for log files (None = console only) - log_level_console: Console log level (default: INFO) - log_json_console: Enable JSON console output - log_rotation: Custom rotation rule (None = use internal default) - log_retention: Custom retention rule (None = use internal default) - Add validation for log_level_console (must be valid log level) - Add CLI args merging for logging settings - Refactor main() to configure logging after config loading so that config file settings can be applied - Add comprehensive tests for logging configuration 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add examples/config.toml with all configurable settings - Include comprehensive comments explaining each setting - Show default values and usage examples - Document configuration priority: CLI args > config file > defaults Usage: styly-netsync-server --config examples/config.toml 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Change argparse default from "INFO" to None so that CLI args only override config file values when explicitly specified by the user. Previously, argparse default="INFO" meant args.log_level_console was never None, so merge_cli_args always overwrote the config file value. Add regression test to verify None CLI values preserve config settings. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Replace SystemExit(1) with typed ConfigurationError exception that stores the list of validation errors. This allows main() to catch validation errors specifically and print user-friendly messages. - Add ConfigurationError class with errors attribute - Update create_config_from_args to raise ConfigurationError - Update main() to catch ConfigurationError and print each error - Add tests for ConfigurationError behavior 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add get_unknown_keys() function to detect unknown sections and keys in TOML configuration files. This helps catch typos like "log_levl_console" that would otherwise be silently ignored. - Add get_unknown_keys() function to detect unknown sections/keys - Warn about unknown keys in create_config_from_args (using print() since logging is not yet configured at that point) - Add comprehensive tests for unknown key detection 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Log the "Loaded configuration from" message after configure_logging() is called, ensuring the log output uses the properly configured logging settings rather than loguru's defaults. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add bundled default.toml with all default configuration values - Remove hardcoded defaults from ServerConfig dataclass - Remove DEFAULT_* global constants from server.py - Remove _DEFAULT_* class constants from NetSyncServer - NetSyncServer now loads default.toml when config is not provided - Implement layered config: CLI args > user.toml > default.toml - Rename --config to --user-config for clarity - Add DefaultConfigError for fatal config loading failures - Exit with error if default.toml cannot be loaded Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Simplify configuration files by removing [network], [timing], [network_variables], [limits], and [logging] sections. All config keys are now at the top level, making the format simpler to read and edit. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
10bd1f7 to
48db2cd
Compare
|
@claude Review the latest code. |
|
Claude finished @from2001's task in 2m 36s —— View job Code Review Complete ✅I've reviewed the latest code in this PR. The implementation has significantly improved since the last review with several architectural refinements. 📊 Summary of Changes Since Last ReviewThe PR has undergone major improvements based on the commit history:
✅ What's Excellent1. Simplified Architecture (Flat Config)The switch from nested TOML sections to a flat structure is a great design decision:
This is simpler, cleaner, and easier to maintain. The code in 2. Robust Error Handling# config.py:19-38
class ConfigurationError(Exception):
"""Raised when configuration validation fails."""
def __init__(self, errors: list[str]) -> None:
self.errors = errors
super().__init__(f"Configuration validation failed: {'; '.join(errors)}")
class DefaultConfigError(Exception):
"""Raised when default configuration cannot be loaded."""Clear exception hierarchy with helpful error messages. The server gracefully handles missing/invalid config files. 3. Unknown Key Detection# config.py:191-206, 384-389
unknown = get_unknown_keys(toml_data)
if unknown:
print(f"WARNING: Unknown keys in {user_config_path}:")
for key in unknown:
print(f" - {key}")This catches typos early! If a user writes 4. Comprehensive Test Coverage
5. Proper Configuration Layering# config.py:376-405
config = load_default_config() # Step 1: Defaults
config = apply_user_overrides(config) # Step 2: User config
config = merge_cli_args(config, args) # Step 3: CLI args
validate_config(config) # Step 4: ValidateClean implementation with clear precedence: CLI > User Config > Defaults 6. Configurable max_virtual_transforms# binary_serializer.py:20-40
_max_virtual_transforms = 50
def set_max_virtual_transforms(value: int) -> None:
global _max_virtual_transforms, MAX_VIRTUAL_TRANSFORMS
if value <= 0:
raise ValueError("max_virtual_transforms must be positive")
_max_virtual_transforms = value
MAX_VIRTUAL_TRANSFORMS = valueGood integration with existing code. The limit is now configurable via TOML. 🔍 Issues FoundMedium Priority1. Using
|
|
@copilot Review the latest code. |
|
I made following changes.
|
Summary
--configCLI option to specify TOML configuration filetomllibfor TOML parsingChanges
src/styly_netsync/config.py- Configuration management module with ServerConfig dataclasstests/test_config.py- 47 tests for configuration functionality (93% coverage)examples/config.toml- Sample configuration file with all settings documentedsrc/styly_netsync/server.py- Integrate config file supportsrc/styly_netsync/binary_serializer.py- Add configurable max_virtual_transformsConfiguration Sections
[network][timing][network_variables][limits][logging]Usage
Test plan
Closes #248
🤖 Generated with Claude Code