Skip to content

fix: devcontainer内のPython環境とhookifyプラグインのモジュールエラーを修正 - #203

Merged
keito4 merged 1 commit into
mainfrom
fix/devcontainer-python-hookify
Dec 30, 2025
Merged

fix: devcontainer内のPython環境とhookifyプラグインのモジュールエラーを修正#203
keito4 merged 1 commit into
mainfrom
fix/devcontainer-python-hookify

Conversation

@keito4

@keito4 keito4 commented Dec 30, 2025

Copy link
Copy Markdown
Owner

Summary

  • devcontainer起動時にhookifyプラグインでModuleNotFoundError: No module named 'json'エラーが発生する問題を修正
  • Python環境を完全にインストールし、hookifyプラグインのshebangを正しく設定

Changes

.devcontainer/Dockerfile

  • python3-venvを追加: 仮想環境サポート
  • python3-devを追加: 開発用ヘッダーファイルとツール
  • Ubuntuの最小構成python3に標準ライブラリの完全なサポートを提供

script/setup-claude.sh

  • hookifyパッチを両方のマーケットプレイス(claude-code-plugins/claude-plugins-official)に対応
  • hooks/ディレクトリ内の全Pythonスクリプトのshebangを#!/usr/bin/env python3に統一
  • shebangがない場合は自動追加し、実行権限を付与

Test Plan

  • devcontainerを再ビルド
  • hookifyプラグインのPre/PostToolUseフックエラーが解消されることを確認
  • Python環境でimport jsonが正常に動作することを確認
  • CI/CDパイプラインがパスすることを確認

Related Issues

Fixes https://github.com/keito4/ohana/issues/138

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • Chores
    • Enhanced development environment configuration by adding essential Python development packages.
    • Improved setup script with expanded plugin source support, refined error handling, and enhanced logging for setup operations.
    • Optimized Python script execution configuration and initialized package structures for better initialization reliability.

✏️ Tip: You can customize this high-level summary in your review settings.

- Dockerfileにpython3-venv/python3-devを追加してPython環境を完全に
- setup-claude.shのhookifyパッチを強化してshebangを修正
- 両方のマーケットプレイス(claude-code-plugins/claude-plugins-official)に対応

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Dec 30, 2025

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

The pull request adds Python development packages (python3-venv and python3-dev) to the Docker development container and extends the Claude plugin setup script to handle two hookify directories with enhanced patch application, shebang correction, and Python package initialization.

Changes

Cohort / File(s) Summary
Docker Python Environment
\.devcontainer/Dockerfile``
Adds python3-venv and python3-dev packages to the apt-get installation list for Python development tooling.
Plugin Setup Script Enhancement
\script/setup-claude.sh``
Extends patch application logic to support two hookify directories (HOOKIFY_MARKETPLACE and HOOKIFY_OFFICIAL). Introduces per-directory patch logging, adds shebang line correction for Python scripts under hooks/* (ensures #!/usr/bin/env python3 and sets executable permissions), creates __init__.py files in each directory if missing, and updates control flow to skip gracefully when both directories are absent.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Poem

🐰 Two hookify homes need tending today,
With patches and shebangs and __init__ to lay,
Python venv blooms in the container's bright light,
Setup scripts dance gracefully left and right,
Now Claude's plugins flourish—hooray, hooray! 🌱

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR addresses Python environment and hookify plugin issues (PR #203/Issue #138 context), but the code changes focus on fixing ModuleNotFoundError and shebang configuration, not on the TypeScript 'as unknown as' removals specified in Issue #138. Verify that the actual linked issue for this PR matches the changes. The current changes address Python/hookify problems, not the TypeScript type casting issue described in Issue #138.
Out of Scope Changes check ⚠️ Warning The PR objectives describe fixing Python/hookify issues, but Issue #138 requires removing 34 instances of 'as unknown as' TypeScript casts. The code changes do not implement TypeScript type safety improvements as required by the linked issue. Either link the correct issue related to Python/hookify fixes, or implement the TypeScript type casting removals required by Issue #138.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title clearly describes the main changes: fixing Python environment and hookify plugin module errors in devcontainer.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
script/setup-claude.sh (2)

194-196: Consider removing error suppression for better observability.

The 2>/dev/null on line 196 silently suppresses errors during the import patch application. If there are permission issues, syntax errors in the Perl regex, or other problems, they won't be visible in the logs.

Consider either removing the redirection or redirecting to a log file for debugging purposes.

🔎 Optional improvement
-        find "$HOOKIFY_DIR" -name "*.py" -type f -exec perl -i -pe \
-            's/from hookify\.core/from core/g; s/from hookify\.utils/from utils/g; s/from hookify\.matchers/from matchers/g;' \
-            {} \; 2>/dev/null
+        if ! find "$HOOKIFY_DIR" -name "*.py" -type f -exec perl -i -pe \
+            's/from hookify\.core/from core/g; s/from hookify\.utils/from utils/g; s/from hookify\.matchers/from matchers/g;' \
+            {} \; 2>&1; then
+            log_warn "  インポートパッチの適用中に警告が発生しました"
+        fi

199-217: This is the actual fix for the json module error - well implemented.

The shebang normalization to #!/usr/bin/env python3 ensures that hookify scripts use the correct Python interpreter, which resolves the ModuleNotFoundError: No module named 'json'. The logic properly handles both existing shebangs (replace) and missing shebangs (add).

The use of mktemp at line 208 is safe since TMPDIR is set to ${CLAUDE_DIR}/tmp at line 45, ensuring the temp file is on the same filesystem for the mv operation.

🔎 Optional: Add error handling for mv command
                     else
                         # shebangがない場合は追加
                         tmp_file=$(mktemp)
                         echo '#!/usr/bin/env python3' > "$tmp_file"
                         cat "$py_file" >> "$tmp_file"
-                        mv "$tmp_file" "$py_file"
+                        if ! mv "$tmp_file" "$py_file"; then
+                            log_warn "  ${py_file}へのshebang追加に失敗しました"
+                            rm -f "$tmp_file"
+                            continue
+                        fi
                     fi
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4fd3007 and 0a813fd.

📒 Files selected for processing (2)
  • .devcontainer/Dockerfile
  • script/setup-claude.sh
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-12-01T03:45:17.253Z
Learnt from: CR
Repo: keito4/config PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-01T03:45:17.253Z
Learning: Applies to .github/workflows/docker-image.yml : Build DevContainer images automatically with semantic versioning and multi-platform support in .github/workflows/docker-image.yml

Applied to files:

  • .devcontainer/Dockerfile
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: claude-review
🔇 Additional comments (4)
.devcontainer/Dockerfile (1)

20-21: Note: These packages don't directly fix the json module error.

The json module is part of Python's standard library and is included with the base python3 package already installed on line 18. The ModuleNotFoundError: No module named 'json' is actually resolved by the shebang corrections in script/setup-claude.sh (lines 199-217), which ensure scripts use the correct Python interpreter via #!/usr/bin/env python3.

That said, adding python3-venv and python3-dev is still beneficial for Python development work in the container (virtual environments, building native extensions, etc.).

script/setup-claude.sh (3)

187-188: LGTM: Clean addition of second hookify marketplace path.

The variable naming is consistent with the existing HOOKIFY_MARKETPLACE pattern.


219-230: LGTM: Proper Python package initialization.

Creating __init__.py with a docstring and version follows Python packaging best practices. The use of a quoted heredoc delimiter ('INIT_EOF') correctly prevents variable expansion in the content.


234-238: LGTM: Proper handling of missing directories and clear completion message.

The condition at line 234 correctly checks for the absence of both hookify directories before skipping, and the final success message provides clear feedback.

@claude

claude Bot commented Dec 30, 2025

Copy link
Copy Markdown
Contributor

プルリクエストレビュー

このPRは、devcontainerでのPython環境とhookifyプラグインのModuleNotFoundError問題を修正する重要な改善です。全体的に適切な実装ですが、いくつかの改善提案があります。

✅ コード品質

良い点:

  • Python環境の完全性を確保するためpython3-venvとpython3-devを追加 - 適切な対応
  • shebangの自動修正により、Pythonスクリプトの実行環境を明示的に指定
  • 両方のマーケットプレイス(claude-code-pluginsとclaude-plugins-official)に対応 - 堅牢性が向上
  • エラーハンドリングとログ出力が適切

🔍 潜在的な問題

1. セキュリティ: 一時ファイルの安全性

場所: script/setup-claude.sh:208-211

問題点: mktempで作成された一時ファイルはデフォルトで/tmpに作成される可能性があり、クロスデバイスリンクエラーが発生する恐れがあります。

推奨: 明示的に一時ファイルの場所を指定してTMPDIRを使用

2. エラーハンドリング: ファイル操作の原子性

場所: script/setup-claude.sh:208-211

mvコマンドが失敗した場合、元のファイルは失われます。エラーハンドリングの追加を推奨します。

3. パフォーマンス: 不要なfindコマンド

場所: script/setup-claude.sh:194-196

findコマンドが全てのPythonファイルに対してperlを実行していますが、hooks/ディレクトリ内のファイルは200-215行目で再度処理されています。hooks/ディレクトリを明示的に除外することでパフォーマンスが改善されます。

🎯 テストカバレッジ

懸念事項:

  • このPRには自動テストが含まれていません
  • setup-claude.shのshebang修正ロジックのユニットテストがあると良い
  • Dockerfileの変更に対するコンテナビルドテストが推奨される

📋 総評

項目 評価
コード品質 ⭐⭐⭐⭐ (4/5)
セキュリティ ⭐⭐⭐⭐ (4/5)
テストカバレッジ ⭐⭐ (2/5) - 手動テストのみ
パフォーマンス ⭐⭐⭐⭐ (4/5)
ドキュメント ⭐⭐⭐⭐⭐ (5/5) - PRの説明が詳細

🚀 マージ推奨度

条件付き承認 - 以下の対応後にマージを推奨:

  1. ⚠️ 必須: 一時ファイル作成時のエラーハンドリング改善
  2. 推奨: mktempの-pオプション使用
  3. 推奨: hooks/除外によるパフォーマンス改善
  4. 推奨: 手動テストプランの実行と結果の記録

コミットメッセージはConventional Commitsに準拠しており、fix:タイプを使用しているため、semantic-releaseによる自動リリースがトリガーされます。これはCLAUDE.mdの要件に合致しています。


レビュー者: Claude Sonnet 4.5
レビュー日時: 2025-12-30
参照: CLAUDE.md開発品質基準

@keito4
keito4 merged commit 2ed3951 into main Dec 30, 2025
5 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 1.24.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@github-actions github-actions Bot added the released リリース済み label Dec 30, 2025
@keito4
keito4 deleted the fix/devcontainer-python-hookify branch January 29, 2026 00:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released リリース済み

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant