Skip to content

Commit a501252

Browse files
authored
Quote $PY_EXE variable to deal with Python path that contain spaces in Bash (#7268)
Fixes #5857. ### Description When dealing with paths that contain spaces in Bash, it's important to properly quote the variables to ensure that spaces are handled correctly. So, maybe we can replace all `$PY_EXE` variables to `"$PY_EXE"` in the `runtests.sh` file. ### Types of changes <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [x] 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. Signed-off-by: ytl0623 <david89062388@gmail.com>
1 parent 860b7c3 commit a501252

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed

runtests.sh

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -119,42 +119,42 @@ function print_usage {
119119
}
120120

121121
# FIXME: https://github.com/Project-MONAI/MONAI/issues/4354
122-
protobuf_major_version=$(${PY_EXE} -m pip list | grep '^protobuf ' | tr -s ' ' | cut -d' ' -f2 | cut -d'.' -f1)
122+
protobuf_major_version=$("${PY_EXE}" -m pip list | grep '^protobuf ' | tr -s ' ' | cut -d' ' -f2 | cut -d'.' -f1)
123123
if [ "$protobuf_major_version" -ge "4" ]
124124
then
125125
export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
126126
fi
127127

128128
function check_import {
129-
echo "Python: ${PY_EXE}"
130-
${cmdPrefix}${PY_EXE} -W error -W ignore::DeprecationWarning -W ignore::ResourceWarning -c "import monai"
129+
echo "Python: "${PY_EXE}""
130+
${cmdPrefix}"${PY_EXE}" -W error -W ignore::DeprecationWarning -W ignore::ResourceWarning -c "import monai"
131131
}
132132

133133
function print_version {
134-
${cmdPrefix}${PY_EXE} -c 'import monai; monai.config.print_config()' # project-monai/monai#6167
134+
${cmdPrefix}"${PY_EXE}" -c 'import monai; monai.config.print_config()' # project-monai/monai#6167
135135
}
136136

137137
function install_deps {
138138
echo "Pip installing MONAI development dependencies and compile MONAI cpp extensions..."
139-
${cmdPrefix}${PY_EXE} -m pip install -r requirements-dev.txt
139+
${cmdPrefix}"${PY_EXE}" -m pip install -r requirements-dev.txt
140140
}
141141

142142
function compile_cpp {
143143
echo "Compiling and installing MONAI cpp extensions..."
144144
# depends on setup.py behaviour for building
145145
# currently setup.py uses environment variables: BUILD_MONAI and FORCE_CUDA
146-
${cmdPrefix}${PY_EXE} setup.py develop --user --uninstall
146+
${cmdPrefix}"${PY_EXE}" setup.py develop --user --uninstall
147147
if [[ "$OSTYPE" == "darwin"* ]];
148148
then # clang for mac os
149-
CC=clang CXX=clang++ ${cmdPrefix}${PY_EXE} setup.py develop --user
149+
CC=clang CXX=clang++ ${cmdPrefix}"${PY_EXE}" setup.py develop --user
150150
else
151-
${cmdPrefix}${PY_EXE} setup.py develop --user
151+
${cmdPrefix}"${PY_EXE}" setup.py develop --user
152152
fi
153153
}
154154

155155
function clang_format {
156156
echo "Running clang-format..."
157-
${cmdPrefix}${PY_EXE} -m tests.clang_format_utils
157+
${cmdPrefix}"${PY_EXE}" -m tests.clang_format_utils
158158
clang_format_tool='.clang-format-bin/clang-format'
159159
# Verify .
160160
if ! type -p "$clang_format_tool" >/dev/null; then
@@ -167,19 +167,19 @@ function clang_format {
167167
}
168168

169169
function is_pip_installed() {
170-
return $(${PY_EXE} -c "import sys, pkgutil; sys.exit(0 if pkgutil.find_loader(sys.argv[1]) else 1)" $1)
170+
return $("${PY_EXE}" -c "import sys, pkgutil; sys.exit(0 if pkgutil.find_loader(sys.argv[1]) else 1)" $1)
171171
}
172172

173173
function clean_py {
174174
if is_pip_installed coverage
175175
then
176176
# remove coverage history
177-
${cmdPrefix}${PY_EXE} -m coverage erase
177+
${cmdPrefix}"${PY_EXE}" -m coverage erase
178178
fi
179179

180180
# uninstall the development package
181181
echo "Uninstalling MONAI development files..."
182-
${cmdPrefix}${PY_EXE} setup.py develop --user --uninstall
182+
${cmdPrefix}"${PY_EXE}" setup.py develop --user --uninstall
183183

184184
# remove temporary files (in the directory of this script)
185185
TO_CLEAN="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
@@ -201,7 +201,7 @@ function clean_py {
201201
}
202202

203203
function torch_validate {
204-
${cmdPrefix}${PY_EXE} -c 'import torch; print(torch.__version__); print(torch.rand(5,3))'
204+
${cmdPrefix}"${PY_EXE}" -c 'import torch; print(torch.__version__); print(torch.rand(5,3))'
205205
}
206206

207207
function print_error_msg() {
@@ -219,7 +219,7 @@ function print_style_fail_msg() {
219219
}
220220

221221
function list_unittests() {
222-
${PY_EXE} - << END
222+
"${PY_EXE}" - << END
223223
import unittest
224224
def print_suite(suite):
225225
if hasattr(suite, "__iter__"):
@@ -448,7 +448,7 @@ then
448448
then
449449
install_deps
450450
fi
451-
${cmdPrefix}${PY_EXE} -m pre_commit run --all-files
451+
${cmdPrefix}"${PY_EXE}" -m pre_commit run --all-files
452452

453453
pre_commit_status=$?
454454
if [ ${pre_commit_status} -ne 0 ]
@@ -477,13 +477,13 @@ then
477477
then
478478
install_deps
479479
fi
480-
${cmdPrefix}${PY_EXE} -m isort --version
480+
${cmdPrefix}"${PY_EXE}" -m isort --version
481481

482482
if [ $doIsortFix = true ]
483483
then
484-
${cmdPrefix}${PY_EXE} -m isort "$homedir"
484+
${cmdPrefix}"${PY_EXE}" -m isort "$homedir"
485485
else
486-
${cmdPrefix}${PY_EXE} -m isort --check "$homedir"
486+
${cmdPrefix}"${PY_EXE}" -m isort --check "$homedir"
487487
fi
488488

489489
isort_status=$?
@@ -513,13 +513,13 @@ then
513513
then
514514
install_deps
515515
fi
516-
${cmdPrefix}${PY_EXE} -m black --version
516+
${cmdPrefix}"${PY_EXE}" -m black --version
517517

518518
if [ $doBlackFix = true ]
519519
then
520-
${cmdPrefix}${PY_EXE} -m black --skip-magic-trailing-comma "$homedir"
520+
${cmdPrefix}"${PY_EXE}" -m black --skip-magic-trailing-comma "$homedir"
521521
else
522-
${cmdPrefix}${PY_EXE} -m black --skip-magic-trailing-comma --check "$homedir"
522+
${cmdPrefix}"${PY_EXE}" -m black --skip-magic-trailing-comma --check "$homedir"
523523
fi
524524

525525
black_status=$?
@@ -544,9 +544,9 @@ then
544544
then
545545
install_deps
546546
fi
547-
${cmdPrefix}${PY_EXE} -m flake8 --version
547+
${cmdPrefix}"${PY_EXE}" -m flake8 --version
548548

549-
${cmdPrefix}${PY_EXE} -m flake8 "$homedir" --count --statistics
549+
${cmdPrefix}"${PY_EXE}" -m flake8 "$homedir" --count --statistics
550550

551551
flake8_status=$?
552552
if [ ${flake8_status} -ne 0 ]
@@ -568,12 +568,12 @@ then
568568
if ! is_pip_installed pylint
569569
then
570570
echo "Pip installing pylint ..."
571-
${cmdPrefix}${PY_EXE} -m pip install "pylint>2.16,!=3.0.0"
571+
${cmdPrefix}"${PY_EXE}" -m pip install "pylint>2.16,!=3.0.0"
572572
fi
573-
${cmdPrefix}${PY_EXE} -m pylint --version
573+
${cmdPrefix}"${PY_EXE}" -m pylint --version
574574

575575
ignore_codes="C,R,W,E1101,E1102,E0601,E1130,E1123,E0102,E1120,E1137,E1136"
576-
${cmdPrefix}${PY_EXE} -m pylint monai tests --disable=$ignore_codes -j $NUM_PARALLEL
576+
${cmdPrefix}"${PY_EXE}" -m pylint monai tests --disable=$ignore_codes -j $NUM_PARALLEL
577577
pylint_status=$?
578578

579579
if [ ${pylint_status} -ne 0 ]
@@ -632,14 +632,14 @@ then
632632
then
633633
install_deps
634634
fi
635-
pytype_ver=$(${cmdPrefix}${PY_EXE} -m pytype --version)
635+
pytype_ver=$(${cmdPrefix}"${PY_EXE}" -m pytype --version)
636636
if [[ "$OSTYPE" == "darwin"* && "$pytype_ver" == "2021."* ]]; then
637637
echo "${red}pytype not working on macOS 2021 (https://github.com/Project-MONAI/MONAI/issues/2391). Please upgrade to 2022*.${noColor}"
638638
exit 1
639639
else
640-
${cmdPrefix}${PY_EXE} -m pytype --version
640+
${cmdPrefix}"${PY_EXE}" -m pytype --version
641641

642-
${cmdPrefix}${PY_EXE} -m pytype -j ${NUM_PARALLEL} --python-version="$(${PY_EXE} -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')")" "$homedir"
642+
${cmdPrefix}"${PY_EXE}" -m pytype -j ${NUM_PARALLEL} --python-version="$(${PY_EXE} -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')")" "$homedir"
643643

644644
pytype_status=$?
645645
if [ ${pytype_status} -ne 0 ]
@@ -664,8 +664,8 @@ then
664664
then
665665
install_deps
666666
fi
667-
${cmdPrefix}${PY_EXE} -m mypy --version
668-
${cmdPrefix}${PY_EXE} -m mypy "$homedir"
667+
${cmdPrefix}"${PY_EXE}" -m mypy --version
668+
${cmdPrefix}"${PY_EXE}" -m mypy "$homedir"
669669

670670
mypy_status=$?
671671
if [ ${mypy_status} -ne 0 ]
@@ -695,7 +695,7 @@ if [ $doMinTests = true ]
695695
then
696696
echo "${separator}${blue}min${noColor}"
697697
doCoverage=false
698-
${cmdPrefix}${PY_EXE} -m tests.min_tests
698+
${cmdPrefix}"${PY_EXE}" -m tests.min_tests
699699
fi
700700

701701
# set coverage command
@@ -707,7 +707,7 @@ then
707707
then
708708
install_deps
709709
fi
710-
cmd="${PY_EXE} -m coverage run --append"
710+
cmd=""${PY_EXE}" -m coverage run --append"
711711
fi
712712

713713
# # download test data if needed
@@ -763,6 +763,6 @@ then
763763
then
764764
install_deps
765765
fi
766-
${cmdPrefix}${PY_EXE} -m coverage combine --append .coverage/
767-
${cmdPrefix}${PY_EXE} -m coverage report --ignore-errors
766+
${cmdPrefix}"${PY_EXE}" -m coverage combine --append .coverage/
767+
${cmdPrefix}"${PY_EXE}" -m coverage report --ignore-errors
768768
fi

0 commit comments

Comments
 (0)