Skip to content

Check Environment Script - #9038

Open
ericspod wants to merge 12 commits into
Project-MONAI:devfrom
ericspod:check_env
Open

Check Environment Script#9038
ericspod wants to merge 12 commits into
Project-MONAI:devfrom
ericspod:check_env

Conversation

@ericspod

@ericspod ericspod commented Aug 1, 2026

Copy link
Copy Markdown
Member

Fixes # .

Description

This adds a script to check the environment for installed libraries, if PyTorch works, if MONAI works, and print platform information. This script is meant to be useable without anything being installed other than Python itself, so it can be used to inspect an environment before attempting to install MONAI or produce diagnostic information when some environmental failure occurs. The script can be run remotely with curl as it only relies on the standard library. Minor tweaks are made to the CI action to use this script rather than the copy-pasted short Python lines.

Types of changes

  • Non-breaking change (fix or new feature that would not break existing functionality).
  • Breaking change (fix or new feature that would cause existing functionality to change).
  • New tests added to cover the changes.
  • Integration tests passed locally by running ./runtests.sh -f -u --net --coverage.
  • Quick tests passed locally by running ./runtests.sh --quick --unittests --disttests.
  • In-line docstrings updated.
  • Documentation updated, tested make html command in the docs/ folder.

ericspod added 5 commits July 30, 2026 13:28
Signed-off-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com>
Signed-off-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com>
Signed-off-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com>
Signed-off-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com>
Signed-off-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 25d3a78f-48c1-4ed7-a5d4-94f5568856c9

📥 Commits

Reviewing files that changed from the base of the PR and between d8b3ffd and 4460d44.

📒 Files selected for processing (2)
  • monai/config/__main__.py
  • monai/config/check_env.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • monai/config/main.py
  • monai/config/check_env.py

📝 Walkthrough

Walkthrough

The change adds a standalone environment diagnostic script with platform, package, PyTorch, CUDA, and MONAI checks. Configuration output now uses anonymized, flushed printing, and the deprecated IgniteInfo export is removed. Module execution and package manifest support are added. CI uses the new diagnostics for test and distribution validation.

Estimated code review effort: 3 (Moderate) | ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: adding an environment-checking script.
Description check ✅ Passed The description explains the script, its standard-library-only design, CI updates, and claimed test coverage; the issue placeholder remains unresolved.
Docstring Coverage ✅ Passed Docstring coverage is 86.67% 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.
✨ 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.

Signed-off-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com>
Signed-off-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com>
Signed-off-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com>
Signed-off-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (2)
monai/config/check_env.py (1)

57-150: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Complete the new utility docstrings.

  • monai/config/check_env.py#L57-L150: Document *args and **kwargs for fprint. Add Returns sections for Boolean diagnostic checks.
  • monai/config/deviceconfig.py#L54-L61: Document *args, **kwargs, and the None return value for fprint.

As per path instructions, “Docstrings should be present for all definition which describe each variable, return value, and raised exception in the appropriate section of the Google-style of docstrings.”

🤖 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 `@monai/config/check_env.py` around lines 57 - 150, Complete the Google-style
docstrings for fprint, print_environment, check_torch, check_torch_cuda, and
check_monai in monai/config/check_env.py: document fprint’s *args and **kwargs,
and add Returns sections describing the Boolean diagnostic results for each
check function. Also update fprint in monai/config/deviceconfig.py to document
*args, **kwargs, and its None return value; make no other behavioral changes.

Source: Path instructions

tests/config/test_print_info.py (1)

22-25: 🔒 Security & Privacy | 🔵 Trivial | ⚡ Quick win

Test the anonymization contract.

out.tell() only confirms that output exists. Call fprint with patched USER and HOST, then assert that raw values are absent and placeholders are present.

As per path instructions, “Ensure new or modified definitions will be covered by existing or new unit tests.”

🤖 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 `@tests/config/test_print_info.py` around lines 22 - 25, Update test_print_info
to patch USER and HOST with known raw values before calling print_debug_info,
then assert the output excludes those values and includes the anonymization
placeholders. Replace the output-length-only assertion while preserving coverage
of the print_debug_info path.

Source: Path instructions

🤖 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 `@monai/config/check_env.py`:
- Around line 163-167: Update the environment-reporting conditional around
print_environment_vars() and print_environment() to enter when either args.env
or args.envvars is set, while keeping variable output gated by args.envvars. Add
a CLI regression test covering --envvars without --env and ensure the modified
behavior is covered.
- Around line 102-150: Update check_torch and check_monai to catch runtime
exceptions from their diagnostic operations, report them with efprint, and
return False while preserving the existing ImportError handling. Move the full
check_torch_cuda workflow, including torch.cuda.device_count() and related
reporting, inside exception handling so pre-device CUDA failures are also
reported via efprint and return False.

---

Nitpick comments:
In `@monai/config/check_env.py`:
- Around line 57-150: Complete the Google-style docstrings for fprint,
print_environment, check_torch, check_torch_cuda, and check_monai in
monai/config/check_env.py: document fprint’s *args and **kwargs, and add Returns
sections describing the Boolean diagnostic results for each check function. Also
update fprint in monai/config/deviceconfig.py to document *args, **kwargs, and
its None return value; make no other behavioral changes.

In `@tests/config/test_print_info.py`:
- Around line 22-25: Update test_print_info to patch USER and HOST with known
raw values before calling print_debug_info, then assert the output excludes
those values and includes the anonymization placeholders. Replace the
output-length-only assertion while preserving coverage of the print_debug_info
path.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 4ac837b2-74f0-41bc-9115-8d129c94eb8d

📥 Commits

Reviewing files that changed from the base of the PR and between 8690ae7 and d8b3ffd.

📒 Files selected for processing (7)
  • .github/workflows/cicd_tests.yml
  • MANIFEST.in
  • monai/config/__init__.py
  • monai/config/__main__.py
  • monai/config/check_env.py
  • monai/config/deviceconfig.py
  • tests/config/test_print_info.py
💤 Files with no reviewable changes (1)
  • monai/config/init.py

Comment thread monai/config/check_env.py
Comment thread monai/config/check_env.py
Signed-off-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com>
Signed-off-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com>
@ericspod
ericspod marked this pull request as ready for review August 2, 2026 19:07
@ericspod
ericspod requested review from KumoLiu and Nic-Ma as code owners August 2, 2026 19:07
Comment thread monai/config/check_env.py
Print all environment variables other than a few known pointless ones.
"""
fprint("Environment:")
for k, v in os.environ.items():

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This prints every environment variable except LS_COLORS/PS1/PS2. Since the module docstring recommends "python check_env.py --env --envvars --monai" as the full-diagnostics command and the script is meant to be run and shared for remote troubleshooting (including the curl-pipe-to-python usage), this risks a user pasting secrets (API keys, tokens, credentials) that happen to be set in their shell into a shared diagnostic dump. Consider redacting values for keys matching common secret patterns (TOKEN, KEY, SECRET, PASSWORD, AUTH, etc.) before printing, or adding a warning when --envvars is used.

Comment thread monai/config/check_env.py
"""
import torch

dcount = torch.cuda.device_count()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

dcount = torch.cuda.device_count() is called before the try block starts. If this call itself raises (e.g. a broken or mismatched CUDA driver -- exactly the kind of environment problem this script exists to diagnose), the script will crash with a raw traceback instead of producing the intended graceful "PyTorch encountered CUDA error" message. Consider moving the device_count() call inside the try block below it.

@garciadias garciadias left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The PR checklist claims "New tests added to cover the changes," but the new check_env.py script (argument parsing, check_torch, check_torch_cuda, print_environment, print_environment_vars) has no test coverage at all. The only test change updates the pre-existing print_debug_info test to capture output via StringIO. Since this script is also now invoked directly from CI (cicd_tests.yml), consider adding tests/config/test_check_env.py covering at least the CLI flags and the anonymization behavior of fprint.

@garciadias garciadias left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Two Major findings worth addressing before merge: a potential secret-leak via --envvars, and no test coverage for the new check_env.py script despite the checklist claim. Details in inline/PR comments. Everything else looks solid.

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