Skip to content

Comprehensive Package Enhancement and Tooling Migration with new modules, improved validation, and modernized CI/CD workflows#36

Merged
chrimaho merged 28 commits into
mainfrom
updates
Jul 13, 2025
Merged

Comprehensive Package Enhancement and Tooling Migration with new modules, improved validation, and modernized CI/CD workflows#36
chrimaho merged 28 commits into
mainfrom
updates

Conversation

@chrimaho

Copy link
Copy Markdown
Contributor

📋 Overview

This comprehensive pull request introduces significant enhancements to the toolbox-python package, including a new generators module, expanded validation capabilities, improved docstring standards, and modernized CI/CD workflows. The changes span 24 commits and touch multiple areas of the codebase to improve functionality, maintainability, and developer experience.

🆕 New Modules and Functions

Generators Module

  • New module: toolbox_python.generators - Provides functions for computing data on-the-fly based on input parameters rather than storing it in databases or files
  • New function: generate_group_cutoffs() - Divides a total number of items into specified groups, returning start and end indices for each group with proper validation and error handling
  • Documentation: Added comprehensive documentation with examples and test coverage

Enhanced Checkers Module

  • New constant: OPERATORS dictionary - Defines comparison operations for value validation
  • New function: is_valid_value() - Checks if a value is valid based on a specified operator and target value
  • New function: assert_is_valid_value() - Assert version of the validation function with proper error handling
  • Enhanced aliases: Added is_valid and assert_is_valid function aliases for consistency

Enhanced Strings Module

  • New function: str_to_list() - Converts strings to single-element lists while preserving other data types unchanged
  • Type safety: Includes comprehensive overloads and type hints for better development experience

🔧 Function Enhancements and Type Safety

Improved Type Hints

  • Enhanced overloads: Added @overload decorators for better type hints in:
    • toolbox_python.checkers.is_value_of_type() - Now properly handles both single types and tuple of types
    • toolbox_python.output.list_columns() - Distinguishes between print and return modes
    • toolbox_python.retry.retry() - Better handling of different parameter combinations
  • Type validation: Enhanced parameter validation across multiple functions using assertion functions

Improved Function Robustness

  • Parameter validation: Added comprehensive input validation using assert_is_valid functions
  • Error handling: Improved exception handling for the retry() function with better logging initialization
  • Code structure: Better organization with descriptive comments separating validation, preparation, processing, and output phases

📜 Package Scripts and Automation

New Utility Scripts

  • Script module: src/utils/scripts.py - Comprehensive collection of utility functions for:
    • Syncing: uv_sync() for dependency management
    • Linting: run_black(), run_isort(), run_pycln(), run_pyupgrade(), etc.
    • Checking: check_black(), check_mypy(), check_pytest(), etc.
    • Git operations: add_git_credentials(), git_refresh_current_branch(), etc.
    • Documentation: docs_build_static(), docs_serve_versioned(), etc.

Project Scripts Configuration

  • Package scripts: Added extensive [project.scripts] table in pyproject.toml with organized sections:
    • Syncing: sync
    • Linting: run-black, run-isort, lint, etc.
    • Checking: check-black, check-mypy, check, etc.
    • Git: add-git-credentials, git-switch-to-main-branch, etc.
    • Docs: docs-serve-static, build-versioned-docs, etc.

📚 Docstring Standards and Validation

Comprehensive Docstring Validation System

  • Validation functions: Implemented automated docstring checking with strict formatting requirements:
    • FunctionAndClassDetails() - Named tuple for tracking function and class details
    • check_docstrings_file() - Validates docstrings in individual files
    • _check_single_docstring() - Validates individual function/class docstrings
    • _check_section_order() - Ensures proper section ordering
    • _validate_section_formats() - Validates specific section formats
    • check_docstrings_cli(), check_docstrings_all(), check_docstrings_dir() - Various checking interfaces

Enhanced Docstring Standards

  • Mandatory sections: Summary, Params, Returns/Yields, and Examples sections now required
  • Format consistency: Fixed typos across all docstrings from !!! summary "Summary" to !!! note "Summary"
  • Examples improvements: Updated all code examples to use pycon syntax for better clarity
  • Type information: Enhanced Raises statements with proper exception types and descriptions

🚀 CI/CD Workflow Modernization

Migration to UV Commands

  • CI workflow: Replaced all make commands with uv run commands in .github/workflows/ci.yml for improved consistency and performance
  • CD workflow: Comprehensive refactoring of .github/workflows/cd.yml:
    • Replaced make commands with uv run commands throughout
    • Added environment variables for UV configuration
    • Improved git operations and version management
    • Fixed tag reference issues to ensure correct version numbers in releases

Pre-commit Integration

  • Hook updates: Updated pre-commit hook versions and added new validation:
    • Updated mypy from v1.15.0 to v1.16.1
    • Updated pyupgrade from v3.19.1 to v3.20.0
    • Updated uv-pre-commit from 0.6.12 to 0.7.20
    • Added check-docstrings hook for continuous validation
  • Configuration: Added --allow-redefinition flag to mypy configuration

⚙️ Configuration and Build System Updates

Project Configuration

  • MyPy configuration: Updated pyproject.toml to include no-redef in disable_error_code list
  • Build system: Migrated from hatchling to uv_build for better integration with UV toolchain
  • Dependencies: Added uv to the development dependency group for better toolchain integration

Documentation Configuration

  • MkDocs updates:
    • Added new generators module to navigation structure
    • Fixed repository icon from material/gitlab to material/github
    • Updated navigation to include comprehensive module coverage

Git Management

  • Git utilities: Enhanced git operations with new utility functions for:
    • Credential management for automated workflows
    • Branch switching and updating
    • Coverage report management
    • Version bumping and tag management

🧪 Testing and Quality Assurance

Enhanced Test Coverage

  • New test modules: Added comprehensive test coverage for new modules:
    • src/tests/test_generators.py - Tests for the generators module
    • Enhanced src/tests/test_strings.py - Tests for new string functions
    • Expanded src/tests/test_checkers.py - Tests for new validation functions

Quality Improvements

  • Validation robustness: Enhanced function robustness through comprehensive parameter validation
  • Error handling: Improved error capture and reporting in docstring checking
  • Type safety: Better type hints and validation across the codebase

🎯 Impact and Benefits

This release significantly enhances the toolbox-python package by:

  • Expanding core functionality with new modules and utility that provide valuable data processing capabilities
  • Improving developer experience through better type hints and validation, standardized tooling and automated quality checks
  • Enhancing code quality with comprehensive validation systems and consistent documentation standards and formatting
  • Modernizing CI/CD with migration to UV-based tooling for better reliability and performance
  • Enhancing maintainability through comprehensive testing and quality assurance
  • Strengthening type safety with enhanced type hints and validation functions

The changes maintain backward compatibility while providing substantial improvements to functionality, developer experience, and project maintenance workflows.

chrimaho added 24 commits July 9, 2025 22:54
- Added `OPERATORS` constant dictionary to define comparison operations.
- Introduced `is_valid_value` and `assert_is_valid_value` functions for value validation based on operators.
- Updated documentation in `checkers.md` to include new functions and constants.
- Enhanced test coverage in `test_checkers.py` for the new validation functions.
- Improved docstrings across all functions
…clarity, and refine the `Raises` statements
… to better enhance type hints in the `output` and `retry` modules
- Introduces a new utility function that converts strings to single-element lists while preserving other data types unchanged.
- This enhancement provides a convenient way to normalize string inputs for functions that expect list-like objects, improving code flexibility when handling mixed input types.
- Includes comprehensive test coverage with parameterized tests for various input scenarios including strings, lists, tuples, sets, dictionaries, and numeric types.
…cture with better comments

- Enhances function robustness by adding comprehensive parameter validation using assertion functions to ensure type safety and value constraints.
- Improves code readability through better organization with descriptive comments that clearly separate validation, preparation, processing, and output phases.
- Simplifies column width logic by replacing conditional assignment with `min()` function for cleaner code.
…ng initialization

- Normalizes exceptions parameter to always be a tuple for consistent handling regardless of input type.
- Moves log variable initialization outside conditional block to improve code clarity and ensure proper variable scope.
- Introduces a new generators module that provides functions for computing data on-the-fly based on input parameters rather than storing it in databases or files.
- Includes new `generate_group_cutoffs()` function that divides a total number of items into specified groups, returning start and end indices for each group with proper validation and error handling.
- Updates documentation to include the new module in the main index with comprehensive description and examples.
- Implements automated docstring checking with strict formatting requirements including mandatory Summary, Params, Returns/Yields, and Examples sections.
- Add custom `pre-commit` hook integration for continuous validation during development workflow.
- Update existing docstrings to comply with new validation standards and fixes inconsistent section formatting across multiple modules.
-> From `!!! summary "Summary"`
-> To `!!! note "Summary"`
- Change from `cli.scripts:...` to `utils:scripts:...`
- Reorder in to sections: `Syncing`, `Linting`, `Checking`
- Add new sections: `Git`, `Docs`
…mands for improved consistency and performance
@chrimaho chrimaho requested a review from Copilot July 13, 2025 01:20
@chrimaho chrimaho self-assigned this Jul 13, 2025

This comment was marked as outdated.

@chrimaho chrimaho requested a review from Copilot July 13, 2025 01:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This PR expands the toolbox-python package with new generation utilities, enhanced validation and type safety, and modernizes development workflows.

  • Introduces a new generators module with generate_group_cutoffs and input assertions
  • Enhances core modules (checkers, retry, output) with overloads, assertion-based validation, and improved docstring formatting
  • Migrates CLI scripts, pre-commit hooks, and GitHub CI/CD from Make and Hatch to the UV toolchain

Reviewed Changes

Copilot reviewed 30 out of 31 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/utils/scripts.py Added UV-based CLI utility scripts for syncing, linting, checking, docs, and Git operations
src/utils/bump_version.py Extracted configuration and update logic into get_config/update_files, exposed main
src/toolbox_python/generators.py New generate_group_cutoffs function with type-checked input validation
src/toolbox_python/retry.py Refactored retry decorator with overloads, assertions for parameters, and precise returns
src/toolbox_python/output.py Added overloads for list_columns, input assertions, and streamlined spacing calculations
src/toolbox_python/checkers.py Introduced OPERATORS, is_valid_value/assert_is_valid_value, and consolidated checks
pyproject.toml Migrated project scripts to uv run commands, updated build backend to uv_build
.github/workflows/ci.yml & cd.yml Replaced all make commands with uv run commands and added UV environment variables
Comments suppressed due to low confidence (1)

src/utils/scripts.py:1

  • [nitpick] The new utility scripts in src/utils/scripts.py currently have no dedicated tests. Consider adding tests to verify key commands and improve maintainability.
## --------------------------------------------------------------------------- #

Comment thread src/toolbox_python/retry.py Outdated
Comment thread src/toolbox_python/generators.py Outdated
Comment thread src/utils/bump_version.py
Comment thread src/tests/test_retry.py
chrimaho and others added 2 commits July 13, 2025 11:46
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@chrimaho chrimaho merged commit 9f32bcc into main Jul 13, 2025
20 checks passed
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.

2 participants