Repository navigation
refactor: improve code quality and separation of concerns across modules - #236
Conversation
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
… coordinate parsing
各ステップでの変更内容 (Changes in Each Step)
Step 1: ベースライン確認 (Baseline Verification)
uv run --extra test pytestを実行し、既存テストスイートの動作状態を確認(395件成功、3件環境スキップ)。Step 2: 仕様固定のためのテスト補強 (Characterization Tests)
tests/test_refactor_characterization.pyを追加し、Excel画像抽出の境界条件、generate_doc_slug、generate_image_filename、get_picture_page_no、PDFConverterの設定処理に対する仕様固定用キャラクタリゼーションテストを追加・確定。test: add characterization tests for refactoring target functionsStep 3: 型定義の修正 (Config Type Annotations)
src/docling_lib/config.py内のDOCLING_ARTIFACTS_PATH: Path | Noneに明示的な型注釈を追加し、mypy 型チェックのエラーを解消。refactor: fix config type annotationsStep 4: Excel画像抽出ロジックの関数分割 (Refactor Excel Image Extraction)
src/docling_lib/utils.pyのextract_excel_images(約150行・多重ループ)を単一責任を持つモジュール化ヘルパー関数群(_parse_workbook_relationships,_parse_sheet_relationships,_parse_drawing_relationships,_extract_anchors_from_drawing)へ分割・再構築。refactor: extract helper functions for Excel image extraction in utils.pyStep 5:
PDFConverterメソッドの責務分離 (Decompose PDFConverter Methods)src/docling_lib/converter.pyのPDFConverter内で、パイプラインオプション設定(_configure_pipeline_options)、既存画像ハッシュ計算(_hash_existing_pictures)、単一画像保存処理(_process_and_save_single_image)を独立したヘルパーメソッドへ分離。refactor: decompose PDFConverter initialization and picture saving logicStep 6 & 7: プレコミット・最終検証 & クリーンアップ
#Correct#)。リファクタリング前後の設計比較 (Design Comparison Before/After Refactoring)
src/docling_lib/config.py:DOCLING_ARTIFACTS_PATHの初期代入で型がPathと型推論され、後続のNone代入時に mypy エラーが発生していた。DOCLING_ARTIFACTS_PATH: Path | Noneの明示的型アノテーションにより、型安全性を確保。src/docling_lib/utils.py(extract_excel_images):src/docling_lib/converter.py(PDFConverter):__init__内でパイプライン設定とアクセラレータ設定をベタ書きし、_enrich_excel_pictures内で画像ハッシュ生成を行い、_save_images内でクロージャによる画像保存を実行していた。_configure_pipeline_options、_hash_existing_pictures、_process_and_save_single_imageに抽出し、メソッドの独立性と凝集度を高めた。テスト実行結果 (Test Execution Results)
0 warnings(All checks passed!)0 errors(Success: no issues found in 9 source files)401 passed, 3 skipped in ~119s(100% Green)PR created automatically by Jules for task 10307311410427335263 started by @chottokun