Skip to content

ENH: worktree creation now avoids nested venv#61

Merged
aylward merged 2 commits into
Project-MONAI:mainfrom
aylward:worktreefix
May 27, 2026
Merged

ENH: worktree creation now avoids nested venv#61
aylward merged 2 commits into
Project-MONAI:mainfrom
aylward:worktreefix

Conversation

@aylward
Copy link
Copy Markdown
Collaborator

@aylward aylward commented May 26, 2026

Summary by CodeRabbit

  • New Features

    • Prevents running the worktree setup script while a Python virtual environment is active; prints clear deactivation instructions and exits.
  • Documentation

    • Regenerated API documentation map: removed several experiment entries and updated the worktree-setup section to reflect new source references.
    • Ignore the generated API map from docs source control.

Copilot AI review requested due to automatic review settings May 26, 2026 18:36
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 26, 2026

Warning

Review limit reached

@aylward, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 56 minutes and 47 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

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.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1d72fbad-4723-4c32-b36b-d3f04053819b

📥 Commits

Reviewing files that changed from the base of the PR and between a180c4a and 76464fd.

📒 Files selected for processing (3)
  • docs/.gitignore
  • docs/API_MAP.md
  • utils/setup_feature_worktree.py

Walkthrough

Added a virtual environment activation guard to utils/setup_feature_worktree.py that aborts when a venv is active; regenerated API documentation entries for the setup script and removed LongitudinalRegistration experiment entries from the generated API map. Added API_MAP.md to docs/.gitignore.

Changes

Virtual environment guard and API documentation update

Layer / File(s) Summary
Virtual environment activation guard
utils/setup_feature_worktree.py
Adds os import and new require_no_active_venv() which inspects VIRTUAL_ENV/interpreter prefix and exits non‑zero with deactivation instructions when a venv is active. check_prerequisites() now calls this before validating git/py tool paths.
API documentation map refresh
docs/API_MAP.md, docs/.gitignore
Removes generated API entries for experiments/LongitudinalRegistration/*. Regenerates the utils/setup_feature_worktree.py API-map section to reflect updated source line numbers. Adds API_MAP.md to docs/.gitignore.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly describes the main enhancement: preventing nested virtual environment issues during worktree creation by checking for active venvs.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
utils/setup_feature_worktree.py (1)

118-124: ⚡ Quick win

Avoid print() in new code; use logging calls.

The new guard path adds direct print() usage. Please switch these new lines to logger-based output to match repo standards.

As per coding guidelines "Use logging module instead of print statements in Python code".

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@utils/setup_feature_worktree.py` around lines 118 - 124, Replace the direct
print() calls that report an active virtualenv with logger calls: use the module
logger (e.g., logger.error / logger.info as appropriate) to emit the same
messages (include the {location} value), keep the blank line and the
PowerShell/cmd instructions as separate logger messages or one multi-line
message, and then call sys.exit(1) as before; update the lines that print the
environment notice and the deactivation instructions to use logger instead of
print so output follows the repository logging convention.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@utils/setup_feature_worktree.py`:
- Around line 121-124: The recovery hint currently hardcodes a Windows
deactivate path ("venv\\Scripts\\deactivate.bat") after the prints and before
sys.exit(1); update the three print lines so both PowerShell and cmd.exe advice
use the generic "deactivate" command (i.e., print "PowerShell : deactivate" and
"cmd.exe    : deactivate") in utils/setup_feature_worktree.py where the script
currently prints the deactivate guidance and calls sys.exit(1).

---

Nitpick comments:
In `@utils/setup_feature_worktree.py`:
- Around line 118-124: Replace the direct print() calls that report an active
virtualenv with logger calls: use the module logger (e.g., logger.error /
logger.info as appropriate) to emit the same messages (include the {location}
value), keep the blank line and the PowerShell/cmd instructions as separate
logger messages or one multi-line message, and then call sys.exit(1) as before;
update the lines that print the environment notice and the deactivation
instructions to use logger instead of print so output follows the repository
logging convention.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8945d6d8-b59a-4431-8ddf-b8582ee7cba0

📥 Commits

Reviewing files that changed from the base of the PR and between 36d752a and 128ba66.

📒 Files selected for processing (2)
  • docs/API_MAP.md
  • utils/setup_feature_worktree.py

Comment on lines +121 to +124
print(" Deactivate it before running this script, then re-run.")
print(" PowerShell : deactivate")
print(" cmd.exe : venv\\Scripts\\deactivate.bat")
sys.exit(1)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Use a generic deactivate command in the recovery hint.

cmd.exe guidance is hardcoded to venv\\Scripts\\deactivate.bat, which is wrong when the active env has a different name/path. Prefer deactivate for both shells.

Suggested fix
-        print("        PowerShell : deactivate")
-        print("        cmd.exe    : venv\\Scripts\\deactivate.bat")
+        print("        PowerShell : deactivate")
+        print("        cmd.exe    : deactivate")
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@utils/setup_feature_worktree.py` around lines 121 - 124, The recovery hint
currently hardcodes a Windows deactivate path ("venv\\Scripts\\deactivate.bat")
after the prints and before sys.exit(1); update the three print lines so both
PowerShell and cmd.exe advice use the generic "deactivate" command (i.e., print
"PowerShell : deactivate" and "cmd.exe    : deactivate") in
utils/setup_feature_worktree.py where the script currently prints the deactivate
guidance and calls sys.exit(1).

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves the Windows feature worktree setup utility by preventing dependency installation from being hijacked by an already-active outer virtual environment, and updates the generated API reference accordingly.

Changes:

  • Add a prerequisite check that aborts worktree creation when an active venv is detected (via VIRTUAL_ENV and sys.prefix vs sys.base_prefix).
  • Update the API map to reflect the new public function and to remove some outdated entries.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
utils/setup_feature_worktree.py Adds require_no_active_venv() and calls it from check_prerequisites() to avoid nested/outer-venv interference with uv pip install.
docs/API_MAP.md Regenerates/updates the public API index to include the new helper and remove some entries.
Comments suppressed due to low confidence (1)

docs/API_MAP.md:36

  • docs/API_MAP.md still lists modules under experiments/LongitudinalRegistration/uniGradICON/..., but that directory does not exist in the repository checkout. Since this file is marked as generated, these stale entries suggest the API map was not fully regenerated (or the generator input root differs). Please re-run py utils/generate_api_map.py from the repo root (or adjust generation inputs) so the map only includes files that actually exist.
## experiments/LongitudinalRegistration/uniGradICON/scripts/prepare_l2r_datasets.py

- `def generate_oasis_json(data_dir, output_dir)` (line 31): Generate JSON for OASIS brain MRI (unpaired, with segmentations).
- `def generate_lungct_json(data_dir, output_dir)` (line 57): Generate JSON for LungCT (paired).
- `def generate_abdomenmrct_json(data_dir, output_dir)` (line 89): Generate JSON for AbdomenMRCT cross-modality dataset (unpaired, with segmentations).
- `def main()` (line 122)

## experiments/LongitudinalRegistration/uniGradICON/src/unigradicon/__init__.py

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +118 to +123
print("[ERROR] A Python virtual environment is currently active:")
print(f" {location}")
print()
print(" Deactivate it before running this script, then re-run.")
print(" PowerShell : deactivate")
print(" cmd.exe : venv\\Scripts\\deactivate.bat")
@codecov
Copy link
Copy Markdown

codecov Bot commented May 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 32.60%. Comparing base (be25dcc) to head (76464fd).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #61      +/-   ##
==========================================
+ Coverage   32.58%   32.60%   +0.01%     
==========================================
  Files          52       52              
  Lines        7156     7156              
==========================================
+ Hits         2332     2333       +1     
+ Misses       4824     4823       -1     
Flag Coverage Δ
integration-tests 32.49% <ø> (?)
unittests 32.58% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI review requested due to automatic review settings May 27, 2026 13:20
@aylward aylward merged commit d1c4c95 into Project-MONAI:main May 27, 2026
6 of 7 checks passed
@aylward aylward deleted the worktreefix branch May 27, 2026 13:21
@aylward aylward review requested due to automatic review settings May 27, 2026 13:43
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.

2 participants