Skip to content

Commit fc1c6ea

Browse files
Support MONAI RC tag in CI without explicitly setting it in bundle metadata and update spleen_segmentation ver (Project-MONAI#596)
Fixes Project-MONAI#595 ### Description Improve the CI to allow metadata bundle to use future release monai version, if the rc version exists. ### Status **Work in progress** ### Please ensure all the checkboxes: <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [x] Codeformat tests passed locally by running `./runtests.sh --codeformat`. --------- Signed-off-by: Mingxin Zheng <mingxinz@nvidia.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 115ed66 commit fc1c6ea

File tree

6 files changed

+75
-7
lines changed

6 files changed

+75
-7
lines changed

ci/get_bundle_requirements.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,44 @@
1212

1313
import argparse
1414
import os
15+
import sys
1516

1617
from bundle_custom_data import install_dependency_dict
1718
from utils import get_json_dict
1819

20+
ALLOW_MONAI_RC = os.environ.get("ALLOW_MONAI_RC", "false").lower() in ("true", "1", "t", "y", "yes")
21+
22+
23+
def increment_version(version):
24+
"""
25+
Split the version into components, assume missing parts are '0'.
26+
27+
Args:
28+
version (str): The version string to increment.
29+
30+
Examples:
31+
print(increment_version("1.3.2")) # Expected output: 1.3.3
32+
print(increment_version("1.4")) # Expected output: 1.4.1
33+
print(increment_version("1")) # Expected output: 1.0.1
34+
"""
35+
version = str(version)
36+
parts = version.split(".")
37+
# Extend the list with zeros to handle cases like "1" or "1.4".
38+
while len(parts) < 3:
39+
parts.append("0")
40+
41+
# Convert all parts to integers.
42+
parts = list(map(int, parts))
43+
44+
# Increment the last part.
45+
parts[-1] += 1
46+
47+
# Join the parts back into a version string.
48+
# This trims trailing '.0's, returning the version in its original format
49+
result_version = ".".join(map(str, parts)).rstrip(".0")
50+
51+
return result_version
52+
1953

2054
def get_requirements(bundle, models_path):
2155
"""
@@ -29,7 +63,12 @@ def get_requirements(bundle, models_path):
2963
libs = []
3064
if "monai_version" in metadata.keys():
3165
monai_version = metadata["monai_version"]
32-
libs.append(f"monai=={monai_version}")
66+
if not ALLOW_MONAI_RC:
67+
lib_monai_req = f"monai=={monai_version}"
68+
else:
69+
lib_monai_req = f"monai>={monai_version}rc1,<{increment_version(monai_version)}"
70+
print(f"ALLOW_MONAI_RC is set to true, the version range is {lib_monai_req}", file=sys.stderr)
71+
libs.append(lib_monai_req)
3372
if "pytorch_version" in metadata.keys():
3473
pytorch_version = metadata["pytorch_version"]
3574
libs.append(f"torch=={pytorch_version}")

ci/run_premerge_cpu.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
set -ex
2222
BUILD_TYPE=all
23+
export ALLOW_MONAI_RC=true
2324

2425
if [[ $# -eq 1 ]]; then
2526
BUILD_TYPE=$1
@@ -54,9 +55,15 @@ verify_bundle() {
5455
pip install -r requirements-dev.txt
5556
# get required libraries according to the bundle's metadata file
5657
requirements=$(python $(pwd)/ci/get_bundle_requirements.py --b "$bundle")
58+
# check if ALLOW_MONAI_RC is set to 1, if so, append --pre to the pip install command
59+
if [ $ALLOW_MONAI_RC = true ]; then
60+
include_pre_release="--pre"
61+
else
62+
include_pre_release=""
63+
fi
5764
if [ ! -z "$requirements" ]; then
5865
echo "install required libraries for bundle: $bundle"
59-
pip install -r "$requirements"
66+
pip install $include_pre_release -r "$requirements"
6067
fi
6168
# verify bundle
6269
python $(pwd)/ci/verify_bundle.py -b "$bundle" -m "min" # min tests on cpu

ci/run_premerge_gpu.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
set -ex
2222
BUILD_TYPE=all
23+
export ALLOW_MONAI_RC=true
2324

2425
if [[ $# -eq 1 ]]; then
2526
BUILD_TYPE=$1
@@ -61,9 +62,15 @@ verify_bundle() {
6162
init_pipenv requirements-dev.txt
6263
# get required libraries according to the bundle's metadata file
6364
requirements=$(pipenv run python $(pwd)/ci/get_bundle_requirements.py --b "$bundle")
65+
# check if ALLOW_MONAI_RC is set to 1, if so, append --pre to the pip install command
66+
if [ $ALLOW_MONAI_RC = true ]; then
67+
include_pre_release="--pre"
68+
else
69+
include_pre_release=""
70+
fi
6471
if [ ! -z "$requirements" ]; then
6572
echo "install required libraries for bundle: $bundle"
66-
pipenv install -r "$requirements"
73+
pipenv install $include_pre_release -r "$requirements"
6774
fi
6875
# get extra install script if exists
6976
extra_script=$(pipenv run python $(pwd)/ci/get_bundle_requirements.py --b "$bundle" --get_script True)

ci/run_premerge_multi_gpu.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
set -ex
2222
BUILD_TYPE=all
23+
export ALLOW_MONAI_RC=true
2324

2425
if [[ $# -eq 1 ]]; then
2526
BUILD_TYPE=$1
@@ -61,9 +62,15 @@ verify_bundle() {
6162
init_pipenv requirements-dev.txt
6263
# get required libraries according to the bundle's metadata file
6364
requirements=$(pipenv run python $(pwd)/ci/get_bundle_requirements.py --b "$bundle")
65+
# check if ALLOW_MONAI_RC is set to 1, if so, append --pre to the pip install command
66+
if [ $ALLOW_MONAI_RC = true ]; then
67+
include_pre_release="--pre"
68+
else
69+
include_pre_release=""
70+
fi
6471
if [ ! -z "$requirements" ]; then
6572
echo "install required libraries for bundle: $bundle"
66-
pipenv install -r "$requirements"
73+
pipenv install $include_pre_release -r "$requirements"
6774
fi
6875
# get extra install script if exists
6976
extra_script=$(pipenv run python $(pwd)/ci/get_bundle_requirements.py --b "$bundle" --get_script True)

ci/run_regular_tests_cpu.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
set -ex
2222
bundle=""
23+
export ALLOW_MONAI_RC=true
2324

2425
if [[ $# -eq 1 ]]; then
2526
bundle=$1
@@ -39,9 +40,15 @@ verify_release_bundle() {
3940
python $(pwd)/ci/download_latest_bundle.py --b "$bundle" --models_path $(pwd)/models --p "$download_path"
4041
# get required libraries according to the bundle's metadata file
4142
requirements=$(python $(pwd)/ci/get_bundle_requirements.py --b "$bundle" --p "$download_path")
43+
# check if ALLOW_MONAI_RC is set to 1, if so, append --pre to the pip install command
44+
if [ $ALLOW_MONAI_RC = true ]; then
45+
include_pre_release="--pre"
46+
else
47+
include_pre_release=""
48+
fi
4249
if [ ! -z "$requirements" ]; then
4350
echo "install required libraries for bundle: $bundle"
44-
pip install -r "$requirements"
51+
pip install $include_pre_release -r "$requirements"
4552
fi
4653
# verify bundle
4754
python $(pwd)/ci/verify_bundle.py -b "$bundle" -p "$download_path" -m "regular" # regular tests on cpu

models/spleen_ct_segmentation/configs/metadata.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"schema": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/meta_schema_20220324.json",
3-
"version": "0.5.7",
3+
"version": "0.5.8",
44
"changelog": {
5+
"0.5.8": "update to use monai 1.3.2",
56
"0.5.7": "update to use monai 1.3.1",
67
"0.5.6": "add load_pretrain flag for infer",
78
"0.5.5": "add checkpoint loader for infer",
@@ -35,7 +36,7 @@
3536
"0.1.0": "complete the model package",
3637
"0.0.1": "initialize the model package structure"
3738
},
38-
"monai_version": "1.3.1",
39+
"monai_version": "1.3.2",
3940
"pytorch_version": "2.2.2",
4041
"numpy_version": "1.24.4",
4142
"optional_packages_version": {

0 commit comments

Comments
 (0)