Skip to content

feat: add an actionable optional-import guard with install hints - #241

Draft
hasansezertasan wants to merge 3 commits into
mainfrom
feature/172-optional-import-guard
Draft

feat: add an actionable optional-import guard with install hints#241
hasansezertasan wants to merge 3 commits into
mainfrom
feature/172-optional-import-guard

Conversation

@hasansezertasan

Copy link
Copy Markdown
Owner

Summary

  • Adds core/_imports.require(module, *, feature, extra=None): imports an optional/lazy dependency or raises a ModuleNotFoundError naming the actually-missing module (via the original exception's name) and the exact pip install command, instead of a bare traceback.
  • Wires it into the CLI root's lazy-imported, non-primary component subcommands (interactive/web/mcp/worker, both the Typer and argparse variants, plus the minimal launcher's default callback) and the corresponding component of the default() callback used when include_cli is off. The GUI subcommand is left unguarded since it only depends on stdlib tkinter.
  • Documents the helper in docs/template-architecture.md under the core/ package.

Closes #172

Test plan

  • Regenerated a project with preset=full (copier copy --data-file .example-input.yml --data preset=full --defaults --trust . /tmp/test-172)
  • uv run --locked tox run -e style passes (ruff, mypy, basedpyright, ty, pyrefly, zuban, pylint, slotscheck, import-linter, taplo, typos, editorconfig-checker, sphinx-lint, deadfixtures)
  • uv run --locked tox run passes across all Python envs
  • coverage report shows 100% (gate is fail_under = 99)

Bare imports of lazily-loaded component modules (web/tui/mcp/worker) in the
CLI launcher surfaced a raw ModuleNotFoundError with no hint about how to
fix it, whether from a library user missing an optional accelerator or a
downstream project that toggled a component on via `copier update` without
re-syncing. `core/_imports.require()` reports the actually-missing module
and the exact install command instead.
@coderabbitai

coderabbitai Bot commented Aug 15, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@hasansezertasan, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 48 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: bb53da1f-c7ff-43a0-80e2-624c16f48d52

📥 Commits

Reviewing files that changed from the base of the PR and between 825f420 and d8d5bea.

📒 Files selected for processing (6)
  • docs/template-architecture.md
  • template/src/{{github_repo_name}}/core/_imports.py.jinja
  • template/src/{{github_repo_name}}/{% if include_console_root %}cli{% endif %}/app.py.jinja
  • template/src/{{github_repo_name}}/{% if include_tui %}tui{% endif %}/app.py.jinja
  • template/src/{{github_repo_name}}/{% if include_web %}web{% endif %}/app.py.jinja
  • template/tests/core/test_imports.py.jinja

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.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c97698a9a7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread template/src/{{github_repo_name}}/core/_imports.py.jinja Outdated
@hasansezertasan
hasansezertasan marked this pull request as draft August 15, 2026 17:00
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.

feat: actionable optional-import guard with install hints

1 participant