Skip to content

Modernising Build Process#9010

Open
ericspod wants to merge 23 commits into
Project-MONAI:devfrom
ericspod:build_update
Open

Modernising Build Process#9010
ericspod wants to merge 23 commits into
Project-MONAI:devfrom
ericspod:build_update

Conversation

@ericspod

Copy link
Copy Markdown
Member

Fixes #8980.

Description

This updates the way MONAI is built to be more modern, relying on pip for everything with all information consolidated into the pyproject.toml file. This is still in progress and requires more testing, and needs to be double checked that the optional dependencies are correct. Highlights:

  • Move everything build related into pyproject.toml.
  • Remove the requirements file and the setup.cfg file.
  • Add a script to recreate the requirements files if needed.
  • Update the version of Versioneer used.
  • Update actions to use the new installation process in a uniform manner.
  • Update the Docker files to use the process.
  • Update installation docs to reflect these changes and clarify some parts.

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 10 commits July 17, 2026 14:40
Signed-off-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com>
…requirements

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>
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 Jul 23, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The project centralizes package and build metadata in pyproject.toml, adds dependency extraction, and updates CI, Docker, Conda, local test, and documentation installation flows to use package extras. Versioneer is updated to 0.29 with TOML configuration support and extensive type annotations. Docker builds and C++ extension source handling are revised. requirements-dev.txt, requirements-min.txt, and setup.cfg are emptied or removed from active configuration.

Estimated code review effort: 5 (Critical) | ~120 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 76.92% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately reflects the main change: modernizing the build process.
Description check ✅ Passed The description follows the template and covers the required sections, including fixes, summary, and change types.
Linked Issues check ✅ Passed The changes align with #8980 by moving build config to pyproject.toml, updating actions, replacing requirements files, and refreshing install docs.
Out of Scope Changes check ✅ Passed No clear out-of-scope changes stand out; the touched files all support the build-process modernization.
✨ 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.

@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: 9

🧹 Nitpick comments (3)
monai/_version.py (1)

47-640: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚖️ Poor tradeoff

Make generated definitions conform durably.

These modified definitions lack the required Google-style argument/return/exception documentation. Update the Versioneer template or exempt generated monai/_version.py; hand edits will be overwritten. As per path instructions, definitions require Google-style variable, return, and exception documentation.

🤖 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/_version.py` around lines 47 - 640, The generated Versioneer
definitions lack the required Google-style variable, return, and exception
documentation. Update the Versioneer template that generates symbols such as
get_config, run_command, git_pieces_from_vcs, render, and get_versions, or add
the generated monai/_version.py path to the documentation exemption; do not
hand-edit the generated file because regeneration will overwrite it.

Source: Path instructions

runtests.sh (1)

139-146: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Quote $REQ and clean up the temp file.

Unquoted $REQ (Lines 145-146) is unsafe if TMPDIR contains spaces/glob chars, and the temp requirements file is never removed after use.

🧹 Proposed fix
     REQ=$(mktemp --tmpdir XXX.txt)
-    ${cmdPrefix}"${PY_EXE}" monai/config/print_dependencies.py all testing > $REQ
-    ${cmdPrefix}"${PY_EXE}" -m pip install -r $REQ
+    ${cmdPrefix}"${PY_EXE}" monai/config/print_dependencies.py all testing > "$REQ"
+    ${cmdPrefix}"${PY_EXE}" -m pip install -r "$REQ"
+    rm -f "$REQ"
 }
🤖 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 `@runtests.sh` around lines 139 - 146, Update install_deps to quote "$REQ"
wherever the temporary requirements file is passed to pip, and remove the
temporary file after installation completes. Keep the existing
dependency-generation and installation flow unchanged.

Source: Linters/SAST tools

docs/source/installation.md (1)

54-56: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Add a language to the fenced code block.

Markdownlint flags this block for missing a fence language (MD040).

🤖 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 `@docs/source/installation.md` around lines 54 - 56, Add a language identifier
to the fenced code block containing the dependency list in the installation
documentation, using an appropriate plain-text language such as text; leave the
dependency contents unchanged.

Source: Linters/SAST tools

🤖 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 @.github/workflows/cicd_tests.yml:
- Around line 277-282: Update the dependency installation steps in the workflow
to install only `.[all,testing]`, then explicitly install `omegaconf` and
`nvsubquadratic>=0.1.1` with `--no-deps`. Remove the separate `python -m pip
install -e .[hyena]` step and keep the existing isolation strategy.

In @.github/workflows/cron.yml:
- Line 189: Update the artifact-install step in the workflow to install the
built package by its package name variable, using the extras all and testing,
instead of installing the current directory. Remove the python -m pip install
.[all,testing] command and the obsolete requirements*.txt copy from this step.
- Line 242: Update the dependency installation steps in the workflow to complete
the pip-only migration: replace both the existing pip install and BUILD_MONAI
setup.py develop commands with BUILD_MONAI=1 python -m pip install -e
.[all,testing].

In @.github/workflows/integration.yml:
- Line 40: Update the container image used by both integration jobs in
.github/workflows/integration.yml at lines 40-40 and 115-115 to the same image
providing Python 3.10 or newer, before the python -m pip install steps; no other
workflow behavior needs to change.

In `@Dockerfile.slim`:
- Around line 49-56: Update the editable install command after the BUILD_MONAI
and FORCE_CUDA environment settings to include pip’s --no-build-isolation
option, matching the established Dockerfile installation pattern and ensuring
extensions build against the preinstalled runtime dependencies.

In `@docs/source/installation.md`:
- Around line 52-58: Update the corresponding packages list in the installation
documentation by adding cucim-cu12 and cucim-cu13 immediately after clearml and
before cupy, preserving the extras list order so cucim has a 1:1 mapping with
its Pip dependencies.

In `@monai/__init__.py`:
- Around line 65-66: Update the __revision_id__ assignment to preserve an absent
full-revisionid as an empty string instead of converting None to "None", while
leaving the existing version fallback unchanged.

In `@monai/config/print_dependencies.py`:
- Around line 29-57: The parse_dependencies function mutates the caller-owned
sections collection via sections.remove and uses a mutable default. Change
sections to default to None, create a local set from the provided sections, and
perform BUILD_SYSTEM_KEY removal and subsequent membership/iteration operations
on that local copy.

In `@pyproject.toml`:
- Around line 72-73: Update the MetricsReloaded dependency entries for both the
all and metrics_reloaded extras to use the same immutable commit reference
instead of the differing mutable branches. Remove the branch-based URLs and
ensure both entries resolve to that identical pinned commit.

---

Nitpick comments:
In `@docs/source/installation.md`:
- Around line 54-56: Add a language identifier to the fenced code block
containing the dependency list in the installation documentation, using an
appropriate plain-text language such as text; leave the dependency contents
unchanged.

In `@monai/_version.py`:
- Around line 47-640: The generated Versioneer definitions lack the required
Google-style variable, return, and exception documentation. Update the
Versioneer template that generates symbols such as get_config, run_command,
git_pieces_from_vcs, render, and get_versions, or add the generated
monai/_version.py path to the documentation exemption; do not hand-edit the
generated file because regeneration will overwrite it.

In `@runtests.sh`:
- Around line 139-146: Update install_deps to quote "$REQ" wherever the
temporary requirements file is passed to pip, and remove the temporary file
after installation completes. Keep the existing dependency-generation and
installation flow unchanged.
🪄 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: 27887d1b-aeae-4dea-b5b2-726433564b42

📥 Commits

Reviewing files that changed from the base of the PR and between a3d5160 and bbdb0bc.

📒 Files selected for processing (27)
  • .github/workflows/build_docs.yml
  • .github/workflows/cicd_tests.yml
  • .github/workflows/codeql-analysis.yml
  • .github/workflows/cron-ngc-bundle.yml
  • .github/workflows/cron.yml
  • .github/workflows/docker.yml
  • .github/workflows/integration.yml
  • .github/workflows/pythonapp-gpu.yml
  • .github/workflows/pythonapp-hyena-gpu.yml
  • .github/workflows/release.yml
  • .github/workflows/weekly-preview.yml
  • Dockerfile
  • Dockerfile.slim
  • docs/requirements.txt
  • docs/source/installation.md
  • environment-dev.yml
  • monai/__init__.py
  • monai/_version.py
  • monai/config/print_dependencies.py
  • pyproject.toml
  • requirements-dev.txt
  • requirements-min.txt
  • requirements.txt
  • runtests.sh
  • setup.cfg
  • setup.py
  • versioneer.py
💤 Files with no reviewable changes (6)
  • requirements-dev.txt
  • setup.cfg
  • .github/workflows/docker.yml
  • requirements-min.txt
  • requirements.txt
  • .github/workflows/release.yml

Comment thread .github/workflows/cicd_tests.yml Outdated
Comment thread .github/workflows/cron.yml Outdated
Comment thread .github/workflows/cron.yml Outdated
Comment thread .github/workflows/integration.yml Outdated
Comment thread Dockerfile.slim
Comment thread docs/source/installation.md Outdated
Comment thread monai/__init__.py Outdated
Comment thread monai/config/print_dependencies.py Outdated
Comment thread pyproject.toml
@ericspod
ericspod requested a review from garciadias July 23, 2026 22:50
Comment thread monai/config/print_dependencies.py
ericspod and others added 4 commits July 25, 2026 21:45
Signed-off-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com>
Signed-off-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com>
@ericspod

Copy link
Copy Markdown
Member Author

@coderabbitai review again.

@coderabbitai

coderabbitai Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

@ericspod Reviewing the latest changes.

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@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: 5

♻️ Duplicate comments (1)
pyproject.toml (1)

74-75: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

MetricsReloaded still pinned to two different forks/branches.

all uses git+https://github.com/ericspod/MetricsReloaded@monai-support-fix while metrics_reloaded uses git+https://github.com/Project-MONAI/MetricsReloaded@monai-support — different repos and branches for the same package. Installing both extras together (or comparing environments built from each) yields divergent, unpinned dependency states. Unify on one immutable commit reference for both extras.

Also applies to: 131-131

🤖 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 `@pyproject.toml` around lines 74 - 75, Unify the MetricsReloaded dependency
declarations in the all and metrics_reloaded extras to use the same repository
and immutable commit reference. Update both entries consistently, replacing the
differing fork/branch URLs while preserving the existing package specification
structure.
🧹 Nitpick comments (1)
monai/config/print_dependencies.py (1)

1-68: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

No unit tests for this new dependency-parsing utility.

This script now drives dependency installation across CI, Docker, and runtests.sh; a parsing regression would break every build path. Consider adding a test that exercises parse_dependencies against a small sample toml (core, build-system, and optional-dependency sections).

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 `@monai/config/print_dependencies.py` around lines 1 - 68, Add unit coverage
for parse_dependencies using a temporary minimal pyproject.toml containing
project dependencies, build-system.requires, and multiple optional-dependencies.
Assert core dependencies are always returned, build-system entries are included
only for the build-system section, selected optional sections and "*" behave
correctly, and results are deduplicated and sorted.

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 @.github/workflows/cicd_tests.yml:
- Around line 143-147: Update the min-dep job’s installation commands to include
the generated minimum constraints from requirements-min.txt, especially for the
all path, while retaining the existing testing extras and build-system
dependency installation. Ensure this matrix continues validating against the
pinned minimum dependency versions rather than an unconstrained pandas release.

In `@Dockerfile.slim`:
- Around line 49-56: The editable install command using `pip install` still
enables build isolation, allowing compiled extensions to use build dependencies
that may not match the installed PyTorch ABI. Update the `BUILD_MONAI=1
FORCE_CUDA=1` installation step to disable build isolation, matching the
safeguard used by `Dockerfile`, while preserving the existing extras and
editable-install options.

In `@docs/source/installation.md`:
- Line 54: Update the fenced code block in the installation documentation to
specify the text language identifier by using a text-labeled fence instead of a
bare fence, satisfying Markdownlint MD040.

In `@monai/config/print_dependencies.py`:
- Around line 29-60: Add a Google-style docstring to parse_dependencies
describing the filename and sections parameters, the sorted dependency-list
return value, and KeyError behavior when the TOML data is malformed or required
keys are missing.

In `@runtests.sh`:
- Around line 144-146: Quote the temporary-file variable REQ in both the
print_dependencies.py output redirection and the pip install command to prevent
word splitting and glob expansion. Keep the existing command behavior unchanged.

---

Duplicate comments:
In `@pyproject.toml`:
- Around line 74-75: Unify the MetricsReloaded dependency declarations in the
all and metrics_reloaded extras to use the same repository and immutable commit
reference. Update both entries consistently, replacing the differing fork/branch
URLs while preserving the existing package specification structure.

---

Nitpick comments:
In `@monai/config/print_dependencies.py`:
- Around line 1-68: Add unit coverage for parse_dependencies using a temporary
minimal pyproject.toml containing project dependencies, build-system.requires,
and multiple optional-dependencies. Assert core dependencies are always
returned, build-system entries are included only for the build-system section,
selected optional sections and "*" behave correctly, and results are
deduplicated and sorted.
🪄 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: 0cbe0862-f439-43e7-a08a-928df0db6d74

📥 Commits

Reviewing files that changed from the base of the PR and between 3ee058b and 6df3abe.

📒 Files selected for processing (27)
  • .github/workflows/build_docs.yml
  • .github/workflows/cicd_tests.yml
  • .github/workflows/codeql-analysis.yml
  • .github/workflows/cron-ngc-bundle.yml
  • .github/workflows/cron.yml
  • .github/workflows/docker.yml
  • .github/workflows/integration.yml
  • .github/workflows/pythonapp-gpu.yml
  • .github/workflows/pythonapp-hyena-gpu.yml
  • .github/workflows/release.yml
  • .github/workflows/weekly-preview.yml
  • Dockerfile
  • Dockerfile.slim
  • docs/requirements.txt
  • docs/source/installation.md
  • environment-dev.yml
  • monai/__init__.py
  • monai/_version.py
  • monai/config/print_dependencies.py
  • pyproject.toml
  • requirements-dev.txt
  • requirements-min.txt
  • requirements.txt
  • runtests.sh
  • setup.cfg
  • setup.py
  • versioneer.py
💤 Files with no reviewable changes (6)
  • requirements-dev.txt
  • setup.cfg
  • requirements.txt
  • .github/workflows/docker.yml
  • requirements-min.txt
  • .github/workflows/release.yml

Comment thread .github/workflows/cicd_tests.yml
Comment thread Dockerfile.slim
Comment thread docs/source/installation.md Outdated
Comment thread monai/config/print_dependencies.py Outdated
Comment thread runtests.sh Outdated
ericspod and others added 5 commits July 25, 2026 22:15
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>
@ericspod
ericspod marked this pull request as ready for review July 25, 2026 23:55
@ericspod
ericspod requested review from KumoLiu and Nic-Ma as code owners July 25, 2026 23:55

@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: 1

🤖 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 `@runtests.sh`:
- Around line 144-146: Update the dependency installation flow in runtests.sh
around the REQ temporary file to always remove it after pip installation,
including when installation fails; use cleanup that executes before returning or
propagating the installation error.
🪄 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: bdb85aa0-f637-4d2b-8912-a6aae35b34f5

📥 Commits

Reviewing files that changed from the base of the PR and between 6df3abe and 95bbd24.

📒 Files selected for processing (6)
  • .github/workflows/cicd_tests.yml
  • docs/source/installation.md
  • environment-dev.yml
  • monai/config/print_dependencies.py
  • pyproject.toml
  • runtests.sh
💤 Files with no reviewable changes (1)
  • pyproject.toml
🚧 Files skipped from review as they are similar to previous changes (4)
  • environment-dev.yml
  • monai/config/print_dependencies.py
  • docs/source/installation.md
  • .github/workflows/cicd_tests.yml

Comment thread runtests.sh
Comment on lines +144 to +146
REQ=$(mktemp --tmpdir XXX.txt)
${cmdPrefix}"${PY_EXE}" monai/config/print_dependencies.py all testing > "$REQ"
${cmdPrefix}"${PY_EXE}" -m pip install -r "$REQ"

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.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Remove the temporary requirements file after use.

mktemp creates a persistent file, but this function never deletes it. Clean it up on both successful and failed dependency installation paths to avoid accumulating temporary files across repeated runs.

🔧 Proposed fix
     REQ=$(mktemp --tmpdir XXX.txt)
-    ${cmdPrefix}"${PY_EXE}" monai/config/print_dependencies.py all testing > "$REQ"
-    ${cmdPrefix}"${PY_EXE}" -m pip install -r "$REQ"
+    if ! ${cmdPrefix}"${PY_EXE}" monai/config/print_dependencies.py all testing > "$REQ"; then
+        rm -f "$REQ"
+        return 1
+    fi
+    if ! ${cmdPrefix}"${PY_EXE}" -m pip install -r "$REQ"; then
+        rm -f "$REQ"
+        return 1
+    fi
+    rm -f "$REQ"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
REQ=$(mktemp --tmpdir XXX.txt)
${cmdPrefix}"${PY_EXE}" monai/config/print_dependencies.py all testing > "$REQ"
${cmdPrefix}"${PY_EXE}" -m pip install -r "$REQ"
REQ=$(mktemp --tmpdir XXX.txt)
if ! ${cmdPrefix}"${PY_EXE}" monai/config/print_dependencies.py all testing > "$REQ"; then
rm -f "$REQ"
return 1
fi
if ! ${cmdPrefix}"${PY_EXE}" -m pip install -r "$REQ"; then
rm -f "$REQ"
return 1
fi
rm -f "$REQ"
🧰 Tools
🪛 Shellcheck (0.11.0)

[info] 145-145: Double quote to prevent globbing and word splitting.

(SC2086)


[info] 146-146: Double quote to prevent globbing and word splitting.

(SC2086)

🤖 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 `@runtests.sh` around lines 144 - 146, Update the dependency installation flow
in runtests.sh around the REQ temporary file to always remove it after pip
installation, including when installation fails; use cleanup that executes
before returning or propagating the installation error.

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.

Modernise Building Process

1 participant