Skip to content

refactor: improve code quality and separation of concerns across modules - #236

Merged
chottokun merged 2 commits into
mainfrom
refactor-code-quality-and-separation-10307311410427335263
Oct 15, 2026
Merged

chottokun merged 2 commits into
mainfrom
refactor-code-quality-and-separation-10307311410427335263

Conversation

@chottokun

Copy link
Copy Markdown
Owner

各ステップでの変更内容 (Changes in Each Step)

  1. Step 1: ベースライン確認 (Baseline Verification)

    • uv run --extra test pytest を実行し、既存テストスイートの動作状態を確認(395件成功、3件環境スキップ)。
  2. 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 functions
  3. Step 3: 型定義の修正 (Config Type Annotations)

    • src/docling_lib/config.py 内の DOCLING_ARTIFACTS_PATH: Path | None に明示的な型注釈を追加し、mypy 型チェックのエラーを解消。
    • コミット: refactor: fix config type annotations
  4. Step 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.py
  5. Step 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 logic
  6. Step 6 & 7: プレコミット・最終検証 & クリーンアップ

    • プレコミット手順に従い、フルテストスイートを実行。
    • コードレビュー要求を実施(結果: #Correct#)。
    • 学習記憶(Memory Recording)を更新。

リファクタリング前後の設計比較 (Design Comparison Before/After Refactoring)

  • src/docling_lib/config.py:

    • Refactor前: DOCLING_ARTIFACTS_PATH の初期代入で型が Path と型推論され、後続の None 代入時に mypy エラーが発生していた。
    • Refactor後: DOCLING_ARTIFACTS_PATH: Path | None の明示的型アノテーションにより、型安全性を確保。
  • src/docling_lib/utils.py (extract_excel_images):

    • Refactor前: 単一の巨大な関数内でOpenXMLワークブック関係性、シート関係性、ドローイング関係性、アンカー要素の解析を多重ネストのループで直接処理していた。
    • Refactor後: 各XMLスキーマ構造の解析ロジックを責務ごとに4つの小さなヘルパー関数に抽出し、可読性・メンテナビリティ・単体テスト性を向上。
  • src/docling_lib/converter.py (PDFConverter):

    • Refactor前: __init__ 内でパイプライン設定とアクセラレータ設定をベタ書きし、_enrich_excel_pictures 内で画像ハッシュ生成を行い、_save_images 内でクロージャによる画像保存を実行していた。
    • Refactor後: それぞれ _configure_pipeline_options、_hash_existing_pictures、_process_and_save_single_image に抽出し、メソッドの独立性と凝集度を高めた。

テスト実行結果 (Test Execution Results)

  • Ruff Linter: 0 warnings (All checks passed!)
  • Mypy Static Analysis: 0 errors (Success: no issues found in 9 source files)
  • Pytest Suite: 401 passed, 3 skipped in ~119s (100% Green)

PR created automatically by Jules for task 10307311410427335263 started by @chottokun

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@chottokun
chottokun merged commit a7d76f7 into main Oct 15, 2026
1 check passed
@chottokun
chottokun deleted the refactor-code-quality-and-separation-10307311410427335263 branch October 15, 2026 13:51
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.

1 participant