Handlers Module
Handlers package for ModuFlow.
This package provides handlers for working with files, sections, and YAML configurations.
File Handler
File operations for ModuFlow.
This module provides utilities for working with files in a ModuFlow project.
- class moduflow.handlers.file_handler.FileHandler(project_root: str | None = None)[source]
Bases:
objectHandler for file operations.
- copy_file(source: Path, destination: Path) None[source]
Copy a file.
- Parameters:
source – Path to the source file.
destination – Path to the destination file.
- Raises:
FileNotFoundError – If the source file doesn’t exist.
- copy_files(files: List[str], source_dir: Path, dest_dir: Path, skip_missing: bool = True) List[str][source]
Copy multiple files.
- Parameters:
files – List of file paths relative to source_dir.
source_dir – Source directory.
dest_dir – Destination directory.
skip_missing – If True, skip missing files. If False, raise FileNotFoundError.
- Returns:
List of files that were copied.
- Raises:
FileNotFoundError – If skip_missing is False and a file doesn’t exist.
- ensure_directory(directory: Path) None[source]
Ensure a directory exists.
- Parameters:
directory – Path to the directory.
- find_files_by_extension(directory: Path, extensions: List[str]) List[Path][source]
Find files with specific extensions.
- Parameters:
directory – Directory to search in.
extensions – List of file extensions (without the dot).
- Returns:
List of file paths.
- list_files(directory: Path, pattern: str = '*') List[Path][source]
List files in a directory.
- Parameters:
directory – Directory to list files from.
pattern – Glob pattern to match files.
- Returns:
List of file paths.
Section Handler
Section management for ModuFlow.
This module provides functionality for working with sections, including creating, updating, and compiling sections.
- class moduflow.handlers.section_handler.SectionHandler(project_root: str | None = None)[source]
Bases:
objectHandler for section operations.
- add_files_to_section(name: str, files: List[str]) None[source]
Add files to an existing section.
- Parameters:
name – Name of the section.
files – List of files to add.
- compile_section(name: str) None[source]
Compile a section to the output directory.
- Parameters:
name – Name of the section to compile.
YAML Handler
YAML handling for ModuFlow.
This module provides utilities for working with YAML files.
- class moduflow.handlers.yaml_handler.YamlHandler[source]
Bases:
objectHandler for YAML operations.
- static load_yaml(file_path: Path) Dict[str, Any][source]
Load a YAML file.
- Parameters:
file_path – Path to the YAML file.
- Returns:
Dictionary containing the YAML data.
- Raises:
FileNotFoundError – If the file doesn’t exist.
yaml.YAMLError – If the YAML is invalid.
- static merge_yaml(base: Dict[str, Any], override: Dict[str, Any]) Dict[str, Any][source]
Merge two YAML dictionaries.
- Parameters:
base – Base dictionary.
override – Dictionary to merge on top of base.
- Returns:
Merged dictionary.
- static save_yaml(data: Dict[str, Any], file_path: Path) None[source]
Save data to a YAML file.
- Parameters:
data – Dictionary to save.
file_path – Path to the YAML file.
- Raises:
yaml.YAMLError – If the data cannot be serialized to YAML.