feat(cli): hint when no models.py is found#18
Conversation
`scan --path <dir>` (and describe/hover/list/er, which share the same _load_index) silently printed an empty apps list when zero models were found, giving new users no signal whether the tool actually ran or the --path was wrong. _load_index now prints a stderr-only hint when idx.total_models() == 0 AND no models.py/models/*.py file was walked at all (re-checked via parser._iter_python_files against the same root + excludes used for the scan) — a models.py that was seen but simply defines zero Django model classes does NOT trigger the hint, since that's a different, already self-explanatory situation. Exit code stays 0 and stdout is untouched, so piping still works. Adds --quiet/-q to _add_scan_flags, scoped identically to the existing --path/--exclude flags across every subcommand that calls _load_index, to suppress the hint. Closes FROWNINGdev#12 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
Warning Review limit reached
Next review available in: 49 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the 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 configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
What
django-orm-lens scan --path /some/dir(anddescribe/hover/list/er,which all share
_load_index) silently printed an empty apps list when zeromodels were found. New users had no way to tell whether the tool actually
ran or the
--pathwas wrong.Change
_load_indexincli/django_orm_lens/cli.pynow prints a hint to stderrwhen
idx.total_models() == 0and nomodels.py/models/*.pyfile waswalked at all under
--path:error, and stdout stays clean for piping.
total_models() == 0alone can't distinguish "nothing under this path at all" from "a real
models.pywas found but defines zero Django model classes" — those aredifferent situations from the user's point of view, and only the first
should show the hint.
WorkspaceIndex/scan_workspacedon't currentlyexpose a "files walked" count, and extending them felt like scope creep
for a hint feature, so
_load_indexre-checks with the existingparser._iter_python_files(root, excludes)walker (same root + excludesused for the actual scan) to determine whether any
models.py-shaped filewas present. Verified both branches manually:
models.pycontaining zero Django model classes→ hint does not fire (a test covers this too)
--quiet/-qflag suppresses the hint. Registered in_add_scan_flags, so it's scoped identically to the existing--path/--excludeflags across every subcommand that goes through_load_index(scan,describe,hover,list,er).CHANGELOG.mdgets an[Unreleased]entry, following the existingprecedent of individual PRs adding to
Unreleasedahead of a releasecommit bumping the version.
Tests
Added
cli/tests/test_cli_hint.py(3 cases, invokingcli.main()directlyand capturing stdout/stderr via
contextlib.redirect_stdout/stderr):{"apps": []}JSON, exit code is 0.--quietsuppresses the hint entirely (stderr empty).models.pythat was walked but defines zero Django model classes doesnot trigger the hint (models.py was "seen").
Gates (run from
cli/).venv/bin/pytest -q→ 47 passed (44 pre-existing + 3 new), all green..venv/bin/ruff check django_orm_lens/cli.py tests/test_cli_hint.py→the new test file is clean.
cli.pyreports 7 pre-existing findings(
UP035/UP045/UP006/SIM105on code this PR didn't touch or onunrelated pre-existing lines); confirmed identical (same messages, just
shifted line numbers) by running ruff against the unmodified file via
git stash— this PR introduces zero new lint findings.Scope
Touches only
cli/django_orm_lens/cli.py,cli/tests/test_cli_hint.py(new), and
CHANGELOG.md. No changes to the VS Code extension,.github/,or any other file.
Closes #12
Prepared with AI assistance (Claude Sonnet 5), human-reviewed before submission.