7.5 KiB
Final Plan for Updating documentation.txt with Debugging Details
This document outlines the final plan for enhancing documentation.txt with detailed internal information crucial for debugging the Asset Processor Tool. This plan incorporates analysis of asset_processor.py, configuration.py, main.py, and gui/processing_handler.py.
Task Objective
Analyze relevant source code (asset_processor.py, configuration.py, main.py, gui/processing_handler.py) to gather specific details about internal logic, state management, error handling, data structures, concurrency, resource management, and limitations. Integrate this information into the existing documentation.txt to aid developers in debugging.
Analysis Steps Completed
- Read and analyzed
readme.md. - Listed code definitions in the root directory (
.). - Listed code definitions in the
gui/directory. - Read and analyzed
asset_processor.py. - Read and analyzed
configuration.py. - Read and analyzed
main.py. - Read and analyzed
gui/processing_handler.py.
Final Integration Plan (Merged Structure)
-
Add New Top-Level Section:
- Append the following section header to the end of
documentation.txt:================================ Internal Details for Debugging ================================
- Append the following section header to the end of
-
Create Subsections:
- Under the new "Internal Details" section, create the following subsections (renumbering from 7 onwards):
7. Internal Logic & Algorithms8. State Management9. Error Handling & Propagation10. Key Data Structures11. Concurrency Models (CLI & GUI)12. Resource Management13. Known Limitations & Edge Cases
- Under the new "Internal Details" section, create the following subsections (renumbering from 7 onwards):
-
Populate Subsections with Specific Details:
-
7. Internal Logic & Algorithms:
- Configuration Preparation (
Configurationclass): Detail the__init__process: loadingconfig.pyand preset JSON, validating structure (_validate_configs), compiling regex (_compile_regex_patternsusing_fnmatch_to_regex). Mention compiled patterns storage. - CLI Argument Parsing (
main.py:setup_arg_parser): Briefly describeargparseusage and key flags influencing execution. - Output Directory Resolution (
main.py:main): Explain how the final output path is determined and resolved. - Asset Processing (
AssetProcessorclass):- Classification (
_inventory_and_classify_files): Describe multi-pass approach using compiled regex fromConfiguration. Detail variant sorting criteria. - Map Processing (
_process_maps): Detail image loading, Gloss->Rough inversion, resizing, format determination (usingConfigurationrules), bit depth conversion, stats calculation, aspect ratio logic, save fallback. - Merging (
_merge_maps): Detail common resolution finding, input loading, channel merging (usingConfigurationrules), output determination, save fallback. - Metadata (
_determine_base_metadata, etc.): Summarize base name extraction, category/archetype determination (usingConfigurationrules),metadata.jsonpopulation.
- Classification (
- Blender Integration (
main.py:run_blender_script,gui/processing_handler.py:_run_blender_script_subprocess): Explain subprocess execution, command construction (-b,--python,--), argument passing (asset_root_dir).
- Configuration Preparation (
-
8. State Management:
Configurationobject: Holds loaded config state and compiled regex. Instantiated per worker.AssetProcessor: Primarily stateless betweenprocess()calls. Internal state withinprocess()managed by local variables (e.g.,current_asset_metadata).self.classified_filespopulated once and filtered per asset.main.py: Tracks overall CLI run counts (processed, skipped, failed).gui/processing_handler.py: Manages GUI processing run state via flags (_is_running,_cancel_requested) and storesFutureobjects (_futures).
-
9. Error Handling & Propagation:
- Custom Exceptions:
AssetProcessingError,ConfigurationError. Configuration: RaisesConfigurationErroron load/validation failure. Logs regex compilation warnings.AssetProcessor: Catches exceptions within per-asset loop, logs error, marks asset "failed", continues loop. Handles specific save fallbacks (EXR->PNG). RaisesAssetProcessingErrorfor critical setup failures.- Worker Wrapper (
main.py:process_single_asset_wrapper): Catches exceptions fromConfiguration/AssetProcessor, logs, returns "failed" status tuple. - Process Pool (
main.py,gui/processing_handler.py):try...exceptaround executor block catches pool-level errors. - GUI Communication (
ProcessingHandler): Catches errors during future result retrieval, emits failure status via signals. - Blender Scripts: Checks subprocess return code, logs stderr. Catches
FileNotFoundError.
- Custom Exceptions:
-
10. Key Data Structures:
Configurationattributes:compiled_map_keyword_regex,compiled_extra_regex, etc. (compiledre.Patternobjects).AssetProcessorstructures:self.classified_files(dict[str, list[dict]]),processed_maps_details_asset(dict[str, dict[str, dict]]),file_to_base_name_map(dict[Path, Optional[str]]).- Return values: Status dictionary from
AssetProcessor.process(), status tuple fromprocess_single_asset_wrapper. ProcessingHandler._futures: dict[Future, str].
-
11. Concurrency Models (CLI & GUI):
- Common Core: Both use
concurrent.futures.ProcessPoolExecutorrunningmain.process_single_asset_wrapper.ConfigurationandAssetProcessorinstantiated within each worker process for isolation. - CLI Orchestration (
main.py:run_processing): Direct executor usage,as_completedgathers results synchronously. - GUI Orchestration (
gui/processing_handler.py):ProcessingHandler(QObject) runs executor logic in aQThread. Results processed in handler thread, communicated asynchronously to UI thread via Qt signals (progress_updated,file_status_updated,processing_finished). - Cancellation (
gui/processing_handler.py:request_cancel): Sets flag, attemptsexecutor.shutdown(wait=False), tries cancelling pending futures. Limitation: Does not stop already running workers.
- Common Core: Both use
-
12. Resource Management:
Configuration: Useswith openfor preset files.AssetProcessor: Manages temporary workspace (tempfile.mkdtemp,shutil.rmtreeinfinally). Useswith openfor metadata JSON.ProcessPoolExecutor: Lifecycle managed viawithstatement inmain.pyandgui/processing_handler.py.
-
13. Known Limitations & Edge Cases:
- Configuration: Basic structural validation only; regex compilation errors are warnings;
_fnmatch_to_regexhelper is basic. - AssetProcessor: Relies heavily on filename patterns; high memory potential for large images; limited intra-asset error recovery; simplified prediction logic.
- CLI: Basic preset file existence check only before starting workers; Blender executable finding logic order (config > PATH).
- GUI Concurrency: Cancellation doesn't stop currently executing worker processes.
- Configuration: Basic structural validation only; regex compilation errors are warnings;
-
-
Switch Mode: Request switching to Code mode to apply these changes by appending to
documentation.txt.