|
16 | 16 | #
|
17 | 17 |
|
18 | 18 | # Argument(s):
|
19 |
| -# BUILD_TYPE: all/specific_test_name, tests to execute |
| 19 | +# $1 - Dist flag (True/False) |
| 20 | + |
| 21 | +dist_flag=$1 |
20 | 22 |
|
21 | 23 | set -ex
|
22 |
| -BUILD_TYPE=all |
23 |
| -export ALLOW_MONAI_RC=true |
24 | 24 |
|
25 |
| -if [[ $# -eq 1 ]]; then |
26 |
| - BUILD_TYPE=$1 |
| 25 | +export ALLOW_MONAI_RC=true |
27 | 26 |
|
28 |
| -elif [[ $# -gt 1 ]]; then |
| 27 | +if [[ $# -gt 1 ]]; then |
29 | 28 | echo "ERROR: too many parameters are provided"
|
30 | 29 | exit 1
|
31 | 30 | fi
|
32 | 31 |
|
33 |
| -init_pipenv() { |
34 |
| - echo "initializing pip environment: $1" |
35 |
| - pipenv install update pip wheel |
36 |
| - pipenv install --python=3.9 -r $1 |
37 |
| - export PYTHONPATH=$PWD |
| 32 | +init_venv() { |
| 33 | + if [ ! -d "model_zoo_venv" ]; then # Check if the venv directory does not exist |
| 34 | + echo "initializing pip environment: $1" |
| 35 | + python -m venv model_zoo_venv |
| 36 | + source model_zoo_venv/bin/activate |
| 37 | + pip install --upgrade pip wheel |
| 38 | + pip install -r $1 |
| 39 | + export PYTHONPATH=$PWD |
| 40 | + else |
| 41 | + echo "Virtual environment model_zoo_venv already exists. Activating..." |
| 42 | + source model_zoo_venv/bin/activate |
| 43 | + fi |
| 44 | +} |
| 45 | + |
| 46 | +remove_venv() { |
| 47 | + if [ -d "model_zoo_venv" ]; then # Check if the venv directory exists |
| 48 | + echo "Removing virtual environment..." |
| 49 | + deactivate 2>/dev/null || true # Deactivate venv, ignore errors if not activated |
| 50 | + rm -rf model_zoo_venv # Remove the venv directory |
| 51 | + else |
| 52 | + echo "Virtual environment not found. Skipping removal." |
| 53 | + fi |
38 | 54 | }
|
39 | 55 |
|
40 |
| -remove_pipenv() { |
41 |
| - echo "removing pip environment" |
42 |
| - pipenv --rm |
43 |
| - rm Pipfile Pipfile.lock |
| 56 | +set_local_env() { |
| 57 | + echo "set local pip environment: $1" |
| 58 | + pip install --upgrade pip wheel |
| 59 | + pip install -r $1 |
| 60 | + export PYTHONPATH=$PWD |
44 | 61 | }
|
45 | 62 |
|
46 | 63 | verify_bundle() {
|
47 | 64 | echo 'Run verify bundle...'
|
48 |
| - init_pipenv requirements-dev.txt |
49 | 65 | head_ref=$(git rev-parse HEAD)
|
50 | 66 | git fetch origin dev $head_ref
|
51 | 67 | # achieve all changed files in 'models'
|
52 | 68 | changes=$(git diff --name-only $head_ref origin/dev -- models)
|
53 | 69 | if [ ! -z "$changes" ]
|
54 | 70 | then
|
55 | 71 | # get all changed bundles
|
56 |
| - bundle_list=$(pipenv run python $(pwd)/ci/get_changed_bundle.py --f "$changes") |
| 72 | + bundle_list=$(python $(pwd)/ci/get_changed_bundle.py --f "$changes") |
57 | 73 | if [ ! -z "$bundle_list" ]
|
58 | 74 | then
|
59 |
| - pipenv run python $(pwd)/ci/prepare_schema.py --l "$bundle_list" |
60 |
| - for bundle in $bundle_list; |
61 |
| - do |
62 |
| - init_pipenv requirements-dev.txt |
63 |
| - # get required libraries according to the bundle's metadata file |
64 |
| - 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" |
| 75 | + python $(pwd)/ci/prepare_schema.py --l "$bundle_list" |
| 76 | + for bundle in $bundle_list; |
| 77 | + do |
| 78 | + # Check if the bundle is "maisi_ct_generative", if so, set local environment (venv cannot work with xformers) |
| 79 | + if [ "$bundle" == "maisi_ct_generative" ]; then |
| 80 | + echo "Special handling for maisi_ct_generative bundle" |
| 81 | + set_local_env requirements-dev.txt |
| 82 | + else |
| 83 | + init_venv requirements-dev.txt |
| 84 | + fi |
| 85 | + # get required libraries according to the bundle's metadata file |
| 86 | + requirements=$(python $(pwd)/ci/get_bundle_requirements.py --b "$bundle") |
| 87 | + # check if ALLOW_MONAI_RC is set to 1, if so, append --pre to the pip install command |
| 88 | + if [ $ALLOW_MONAI_RC = true ]; then |
| 89 | + include_pre_release="--pre" |
| 90 | + else |
| 91 | + include_pre_release="" |
| 92 | + fi |
| 93 | + if [ ! -z "$requirements" ]; then |
| 94 | + echo "install required libraries for bundle: $bundle" |
| 95 | + pip install $include_pre_release -r "$requirements" |
| 96 | + fi |
| 97 | + # get extra install script if exists |
| 98 | + extra_script=$(python $(pwd)/ci/get_bundle_requirements.py --b "$bundle" --get_script True) |
| 99 | + if [ ! -z "$extra_script" ]; then |
| 100 | + echo "install extra libraries with script: $extra_script" |
| 101 | + bash $extra_script |
| 102 | + fi |
| 103 | + # verify bundle |
| 104 | + python $(pwd)/ci/verify_bundle.py --b "$bundle" |
| 105 | + # unzip data and do unit tests |
| 106 | + DATA_DIR="$(pwd)/models/maisi_ct_generative/datasets" |
| 107 | + ZIP_FILE="$DATA_DIR/all_masks_flexible_size_and_spacing_3000.zip" |
| 108 | + UNZIP_DIR="$DATA_DIR/all_masks_flexible_size_and_spacing_3000" |
| 109 | + if [ -f "$ZIP_FILE" ]; then |
| 110 | + if [ ! -d "$UNZIP_DIR" ]; then |
| 111 | + echo "Unzipping files for MAISI Bundle..." |
| 112 | + unzip $ZIP_FILE -d $DATA_DIR |
| 113 | + echo "Unzipping complete." |
68 | 114 | else
|
69 |
| - include_pre_release="" |
70 |
| - fi |
71 |
| - if [ ! -z "$requirements" ]; then |
72 |
| - echo "install required libraries for bundle: $bundle" |
73 |
| - pipenv install $include_pre_release -r "$requirements" |
| 115 | + echo "Unzipped content already exists, continuing..." |
74 | 116 | fi
|
75 |
| - # get extra install script if exists |
76 |
| - extra_script=$(pipenv run python $(pwd)/ci/get_bundle_requirements.py --b "$bundle" --get_script True) |
77 |
| - if [ ! -z "$extra_script" ]; then |
78 |
| - echo "install extra libraries with script: $extra_script" |
79 |
| - bash $extra_script |
80 |
| - fi |
81 |
| - # verify bundle |
82 |
| - pipenv run python $(pwd)/ci/verify_bundle.py --b "$bundle" |
83 |
| - # do unit tests |
84 |
| - pipenv run python $(pwd)/ci/unit_tests/runner.py --b "$bundle" |
85 |
| - remove_pipenv |
86 |
| - done |
| 117 | + fi |
| 118 | + test_cmd="python $(pwd)/ci/unit_tests/runner.py --b \"$bundle\"" |
| 119 | + if [ "$dist_flag" = "True" ]; then |
| 120 | + test_cmd="$test_cmd --dist True" |
| 121 | + fi |
| 122 | + eval $test_cmd |
| 123 | + # if not maisi_ct_generative, remove venv |
| 124 | + if [ "$bundle" != "maisi_ct_generative" ]; then |
| 125 | + remove_venv |
| 126 | + fi |
| 127 | + done |
87 | 128 | else
|
88 | 129 | echo "this pull request does not change any bundles, skip verify."
|
89 | 130 | fi
|
90 | 131 | else
|
91 | 132 | echo "this pull request does not change any files in 'models', skip verify."
|
92 |
| - remove_pipenv |
| 133 | + remove_venv |
93 | 134 | fi
|
94 | 135 | }
|
95 | 136 |
|
96 |
| -case $BUILD_TYPE in |
97 |
| - |
98 |
| - all) |
99 |
| - echo "Run all tests..." |
100 |
| - verify_bundle |
101 |
| - ;; |
102 |
| - |
103 |
| - verify_bundle) |
104 |
| - verify_bundle |
105 |
| - ;; |
106 |
| - |
107 |
| - *) |
108 |
| - echo "ERROR: unknown parameter: $BUILD_TYPE" |
109 |
| - ;; |
110 |
| -esac |
| 137 | +verify_bundle |
0 commit comments