Fix to_yaml module and enhance converter with auto-detection and unified path handling (#566)#581
Fix to_yaml module and enhance converter with auto-detection and unified path handling (#566)#581
Conversation
- Added missing import of to_yaml function in supy.cmd.__init__.py - Added suews-to-yaml console script entry point in pyproject.toml - Implemented lazy imports in to_yaml.py to avoid circular import issues - Note: python -m supy.cmd.to_yaml requires full supy installation This fix ensures the documented command works correctly after installation, and provides an alternative console script entry point.
Co-authored-by: sunt05 <1802656+sunt05@users.noreply.github.com>
|
🤖 I've automatically formatted the code in this PR using:
Please pull the latest changes before making further edits. |
|
already fixed in #582 |
|
@MatthewPaskin - this is what I mentioned in #583 |
not working - needs further work |
|
Thanks @sunt05, this seems to be working for me! I can access the command within python now. |
|
Great @MatthewPaskin – I’ll finalise this shortly by adding some tests, then ask you for a review. |
|
There are some further issues once using the to_yaml function depending on the version provided. Should we tackle these in this PR or with a new issue and new PR? |
|
Let's do that in this PR – I'll tag you for testing once it's in shape @MatthewPaskin |
- Remove redundant 'yaml' option since 2025+ only supports YAML - Automatically determine conversion type based on target version: - Pre-2025: table-to-table conversion - 2025+: convert to YAML format - Fix all conversion issues preventing supy-to-yaml from working: - Handle empty DataFrame when STEBBS disabled - Add graceful handling of missing columns in legacy format - Fix water surface soilstore validation (allow 0 for water) - Provide defaults for missing config/description columns - Update all documentation to reflect simplified interface - Update tests to match new command structure Fixes #581
Co-authored-by: sunt05 <1802656+sunt05@users.noreply.github.com>
- Remove duplicate suews_convert_guide.rst - Update existing input_converter.rst with YAML conversion info - Consolidate all converter documentation in one place
- Replace deprecated delim_whitespace=True with sep=r'\s+' - Replace invalid quotechar=' ' with quoting=3 (QUOTE_NONE) - Fixes CI failures on Python 3.13 Linux builds
Co-authored-by: sunt05 <1802656+sunt05@users.noreply.github.com>
…interface Simplify suews-convert interface and fix remaining YAML conversion issues (builds on #581)
- Removed commented code with conflicting delimiter settings (quotechar and sep both as space) - Added comprehensive delimiter handling tests to prevent CSV parsing issues - Ensures table conversion maintains consistent space-separated format - Tests verify no quote/delimiter conflicts in output files
The issue was only in commented-out code with bad delimiter settings. No need for extensive tests since the active code already works correctly.
- Keep test/fixtures/legacy_format for legacy input files (not sample_data/Input) - Use sample_data for only essential runtime files (config.yml and forcing data) - Keep lazy imports in to_yaml.py to avoid circular dependencies - Integrate CRU temperature data from master - Update meson.build to include ext_data files
- Introduced new input files for the 2024 and 2025 legacy formats, including RunControl, InitialConditions, and various SUEWS-related data files. - These additions support ongoing development and testing of the legacy input handling in the system. - Ensured consistency in file structure and naming conventions across the new input files.
- Fixed debug directory (-d) option in suews-convert command - Debug directory is now properly created and preserved - Intermediate conversion steps are saved for debugging - Added snapshot functionality to track each conversion step - Fixed legacy footer lines issue - Removed code that adds -9 footer lines during conversion - Footer lines with -999 values were being incorrectly parsed as data - Partially fixed non-existent profile references - Updated some conversion rules to use profile 999 (placeholder) instead of non-existent codes - Changed profile codes 801-805, 44, 45, etc. to 999 in rules.csv - Added .gitignore entries for debug files Remaining issue: More comprehensive fix needed for all profile references in conversion rules 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
- Created ProfileManager class to handle missing profile references - Integrated automatic profile creation during conversion - Added --no-profile-validation flag for control - Improved placeholder file creation for BiogenCO2 and ESTM files - Added comprehensive tests for profile management - Enhanced debug mode to preserve intermediate conversion steps - Fixed missing profile references (codes 31, 999, etc.) This addresses issues where conversion rules reference profile codes that don't exist, preventing successful conversion from legacy formats.
- Add explicit encoding='utf-8' to all file open operations - Replace bare except clauses with specific Exception handling - Fix variable shadowing in loops (renamed line to raw_line) - Remove duplicate f90nml import (already imported at module level) - Fix ambiguous variable names (l,r,c renamed to src,dst,weight) - Add 'from e' to exception re-raising for proper error context - Use augmented assignment operator (|=) where appropriate - Fix unused function parameters with underscore prefix - Auto-fix import sorting and formatting issues - Remove unnecessary list comprehensions and redundant code All critical linting issues resolved. Remaining warnings are complexity metrics (too many branches/statements/variables) that would require significant refactoring.
- Extract helper functions from detect_table_version(): - _check_required_files() - _check_specific_files() - _check_columns_in_file() - _check_columns() - _check_negative_columns() - _check_nml_parameters() - Refactor clean_legacy_table() with helpers: - _should_skip_line() - _process_line() - _ensure_consistent_columns() - Refactor SUEWS_Converter_single() with helpers: - _copy_and_clean_files() - _handle_same_version_copy() - _build_file_list() This reduces ruff complexity warnings from 17 to 9, making the code more maintainable while preserving all functionality. All tests pass.
- Move table.py, profile_manager.py, and rules.csv into table/ subdirectory - Create table/__init__.py to maintain backward compatibility - Update import paths to reflect new directory structure - Update meson.build to include new file locations This reorganization groups related table conversion functionality together while maintaining all existing functionality. All 19 tests pass. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Remove temporary markdown documentation and test YAML files that were created during development but are no longer needed. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add missing resample_output import to _supy_module.py - Fix exception chaining with 'from e' in yaml.py - Remove unused variable 'writeoutoption' - Refactor convert_to_yaml() to reduce complexity: - Extract _prepare_processing_dir() helper function - Extract _configure_forcing_and_output() helper function - Reduce local variables from 18 to under 15 - Reduce statements from 52 to under 50 - Fix docstring formatting and remove trailing whitespace - Apply ruff formatting for consistent code style All tests pass after refactoring.
- Remove special case handling for 2016a version - All versions now read file paths from RunControl.nml - Support both absolute and relative paths in RunControl.nml - Update detection functions to use RunControl.nml paths - Maintain backward compatibility with fallback to root/Input dirs This ensures consistent path handling across all SUEWS versions and respects user-specified paths in RunControl.nml instead of hardcoding directory structures.
- Move converter docs from tables/ to inputs/ directory (more appropriate location) - Update documentation to accurately reflect converter capabilities: - Auto-detection of source version - Support for 'latest' target version - Debug directory option - Profile validation control - Add specific examples for all conversion scenarios - Clarify what 'same-version conversion' does (reformatting) - Fix path handling documentation to match actual behaviour - Update all cross-references to new converter location - Use British English spelling throughout
Co-authored-by: sunt05 <1802656+sunt05@users.noreply.github.com>
|
🤖 I've automatically formatted the code in this PR using:
Please pull the latest changes before making further edits. |
- Merged test_2016a_to_latest_yaml and test_2024a_to_latest_yaml into single comprehensive test - Renamed test_benchmark_versions_to_yaml to test_all_versions_to_yaml_with_auto_detection - Simplified test_messy_file_cleaning to test_same_version_cleaning - Updated test to include all versions (2024a and 2025a added to parameterized test) - Improved docstrings to clearly describe what each test covers - Removed unused legacy_2024a_dir fixture - Fixed Site object validation to be more flexible with data model changes
Co-authored-by: sunt05 <1802656+sunt05@users.noreply.github.com>
|
🤖 I've automatically formatted the code in this PR using:
Please pull the latest changes before making further edits. |
- Updated the test command in the Makefile to include the `--durations=10` option for both `uv` and Python pytest executions. - This change allows for better performance insights by reporting the duration of the slowest 10 tests, aiding in identifying potential bottlenecks.
…to fix/566-to-yaml-module
|
Hi @MatthewPaskin, please try this version. I've also added a feature to auto-detect file versions for conversion and tested it with several previous files. The documentation has been updated to reflect these enhancements—please double-check in case I missed anything. |
- Keep only Kc_2012_data_60.txt in 2025a directory for tests - Remove all other Kc forcing data files (36 files) - Remove associated Kc output format files - Reduces test fixture size from ~200MB to ~2MB - All tests pass successfully with minimal fixtures
…kflow - Removed 5 stale UMEP HTML files from docs/source/images/ - Fixed outdated YAML API comment in workflow.rst (it's fully functional) - Added reference to issue #581 for pending table-to-YAML conversion - Removed deprecated warning from README.md developer section - Improved error handling in generate_datamodel_rst.py with helpful messages - Added setup-doc-env.sh for minimal documentation environment setup - Added check_rst_staleness.py for incremental RST generation - Updated Makefile with generate-rst-if-needed target for efficient builds These changes improve documentation maintainability and developer experience while removing outdated content that could confuse users.
- Removed 5 stale UMEP HTML files from docs/source/images/ - Fixed outdated YAML API comment in workflow.rst (fully functional, not in development) - Added reference to issue #581 for pending table-to-YAML conversion - Removed deprecated warning from README.md developer section
MatthewPaskin
left a comment
There was a problem hiding this comment.
Looks good to me, and I have tested for my case that was failing before. thanks for this!
Resolved conflicts: - docs/source/tutorials/python/tutorial.rst: Use master's suews-convert to-yaml format - docs/source/workflow.rst: Use master's suews-convert to-yaml format
Fix missing to_yaml module and comprehensive converter improvements (#566)
Summary
What started as a simple fix for
ModuleNotFoundErrorwhen runningpython -m supy.cmd.to_yamlevolved into a comprehensive improvement of the SUEWS table converter, including refactoring, extensive testing, and documentation updates.Key Improvements
1. Fixed Missing Module Error
src/supy/cmd/__init__.pysuews-to-yamlconsole script entry point2. Table Converter Refactoring
RunControl.nmlpaths3. Comprehensive Test Suite
4. Documentation Reorganisation
tables/toinputs/directory (better reflects dual table/YAML purpose)Changes Made
Code Changes
src/supy/cmd/__init__.py- Added missing importsrc/supy/cmd/to_yaml.py- Implemented lazy loadingsrc/supy/util/converter/table/- Refactored for consistent path handlingtest/core/test_cmd_to_yaml.py- New comprehensive test suitepyproject.toml- Added console script entry pointsrc/supy/meson.build- Updated build configurationDocumentation Changes
docs/source/inputs/converter.rst- Comprehensive converter documentation (moved from tables/)docs/source/inputs/transition_guide.rst- Updated with accurate examplesdocs/source/inputs/tables/input_converter.rst- Removed (content moved)Testing Coverage
Migration Path for Users
This PR ensures a smooth migration path for all SUEWS users:
Test Plan
suews-to-yaml --helpworks after installationBreaking Changes
None - all changes are backwards compatible.
Notes for Reviewers
Fixes #566