Skip to content

Commit d3c1e62

Browse files
authored
Merge pull request #99 from Project-MONAI/update_build_script
Update run script - build/bump_version/clean script
2 parents 074f724 + e396e85 commit d3c1e62

File tree

4 files changed

+135
-5
lines changed

4 files changed

+135
-5
lines changed

.bumpversion.cfg

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[bumpversion]
2+
current_version = 0.1.0a1
3+
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)((?P<release>a|b|rc)(?P<build>\d+))?
4+
serialize =
5+
{major}.{minor}.{patch}{release}{build}
6+
{major}.{minor}.{patch}
7+
tag_name = {new_version}
8+
tag_message = Bump version: {current_version} → {new_version}
9+
commit = True
10+
tag = True
11+
12+
[bumpversion:part:release]
13+
values =
14+
''
15+
a
16+
b
17+
rc
18+
19+
[bumpversion:part:build]
20+
first_value = 1

monai/deploy/utils/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def get_sdk_semver():
9292
1.0.0+abc.5 -> 1.0.0+abc.5
9393
0.1.0a1+0.g8444606.dirty -> 0.1.0-a.1+g.8444606.dirty
9494
95-
Assumetion:
95+
Assumption:
9696
<release> is always X.Y.Z format.
9797
<pre_l> is 'a|b|rc'.
9898
<pre_n> is a positive number.

requirements-dev.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ monai
2727
docker>=5.0.0
2828
pydicom>=1.4.2
2929
SimpleITK>=2.0.0
30-
Pillow>=8.0.0
30+
Pillow>=8.0.0
31+
bump2version==1.0.1

run

Lines changed: 112 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ get_package_info() {
302302

303303
install_python_dev_deps() {
304304
if [ -n "${VIRTUAL_ENV}" ] || [ -n "${CONDA_PREFIX}" ]; then
305-
run_command ${MONAI_PY_EXE} -m pip install -q -U setuptools pip wheel
305+
run_command ${MONAI_PY_EXE} -m pip install -q -U setuptools pip wheel build
306306
run_command ${MONAI_PY_EXE} -m pip install -q -r ${TOP}/requirements-dev.txt
307307
run_command ${MONAI_PY_EXE} -m pip install -q -r ${TOP}/requirements-examples.txt
308308

@@ -380,8 +380,49 @@ clean_desc() { c_echo 'Clean up temporary files and uninstall monai-deploy-app-s
380380
'
381381
}
382382
clean() {
383-
c_echo W 'Cleaning up temporary files and run "' "${MONAI_PY_EXE}" ' setup.py develop --uninstall"...'
383+
c_echo W 'Cleaning up temporary files and run "' "${MONAI_PY_EXE}" ' -m pip uninstall monai-deploy-app-sdk"...'
384384

385+
# Remove coverage history
386+
run_command rm -f junit-monai-deploy-app-sdk.xml monai-deploy-app-sdk-coverage.xml
387+
388+
# Uninstall the development package
389+
if [ -n "${VIRTUAL_ENV}" ] || [ -n "${CONDA_PREFIX}" ]; then
390+
c_echo W "Uninstalling MONAI Deploy App SDK installation..."
391+
run_command ${MONAI_PY_EXE} -m pip uninstall monai-deploy-app-sdk
392+
fi
393+
394+
# Remove temporary files (in the directory of this script)
395+
c_echo W "Removing temporary files in ${TOP}"
396+
run_command find ${TOP}/monai -type f -name "*.py[co]" -delete
397+
run_command find ${TOP}/monai -type f -name "*.so" -delete
398+
run_command find ${TOP}/monai -type d -name "__pycache__" -delete
399+
400+
run_command find ${TOP} -depth -maxdepth 1 -type d -name "monai_deploy_app_sdk.egg-info" -exec rm -r "{}" +
401+
run_command find ${TOP} -depth -maxdepth 1 -type d -name "build" -exec rm -r "{}" +
402+
run_command find ${TOP} -depth -maxdepth 1 -type d -name "dist" -exec rm -r "{}" +
403+
run_command find ${TOP} -depth -maxdepth 1 -type d -name ".mypy_cache" -exec rm -r "{}" +
404+
run_command find ${TOP} -depth -maxdepth 1 -type d -name ".pytype" -exec rm -r "{}" +
405+
run_command find ${TOP} -depth -maxdepth 1 -type d -name "__pycache__" -exec rm -r "{}" +
406+
}
407+
408+
build_desc() { c_echo 'Build distribution package
409+
410+
Build a distribution package for this SDK using
411+
"build" (https://pypa-build.readthedocs.io/en/stable/index.html).
412+
413+
Arguements:
414+
$1 - destination folder (default: ${TOP}/dist)
415+
'
416+
}
417+
build() {
418+
local dest_path="${1:-${TOP}/dist}"
419+
install_python_dev_deps
420+
421+
run_command rm -rf ${dest_path}/monai-deploy-app-sdk-*.gz ${dest_path}/monai_deploy_app_sdk-*.whl
422+
423+
# Somehow, 'build' package causes an issue without `PIP_NO_CACHE_DIR=off` at Python 3.6 (with pyenv)
424+
# (https://github.com/pypa/pip/issues/2897)
425+
PIP_NO_CACHE_DIR=off run_command ${MONAI_PY_EXE} -m build -o "${dest_path}"
385426
}
386427

387428
#==================================================================================
@@ -834,7 +875,7 @@ test_python() {
834875

835876
install_doc_requirements() {
836877
if [ -n "${VIRTUAL_ENV}" ] || [ -n "${CONDA_PREFIX}" ]; then
837-
run_command ${MONAI_PY_EXE} -m pip install -q -U setuptools pip wheel
878+
run_command ${MONAI_PY_EXE} -m pip install -q -U setuptools pip wheel build
838879
run_command ${MONAI_PY_EXE} -m pip install -q -r ${TOP}/docs/requirements.txt
839880
install_edit_mode
840881
else
@@ -981,6 +1022,74 @@ clean_docs() {
9811022
# Section: Release
9821023
#==================================================================================
9831024

1025+
bump_version_desc() { c_echo 'Bump version
1026+
1027+
Executes bump2version(https://github.com/c4urself/bump2version).
1028+
`bump2version` package would be installed if not available.
1029+
1030+
<part>
1031+
- major : a non-negative integer
1032+
- minor : a non-negative integer
1033+
- patch : a non-negative integer
1034+
- release : "a", "b" or "rc"
1035+
- build : a positive integer
1036+
1037+
e.g.)
1038+
0.1.0a1
1039+
major : 0
1040+
minor : 1
1041+
patch : 0
1042+
release : a
1043+
build : 1
1044+
1045+
Examples:
1046+
./run bump_version build # 0.1.0a1 -> 0.1.0a2
1047+
./run bump_version release # 0.1.0a1 -> 0.1.0b1
1048+
./run bump_version patch # 0.1.0a1 -> 0.1.1
1049+
./run bump_version minor # 0.1.0a1 -> 0.2.0
1050+
1051+
Arguments:
1052+
$1 - part (major, minor, patch, release, build)
1053+
$@ - additional arguments for bump2version
1054+
1055+
Returns:
1056+
Outputs executed by bump2version
1057+
1058+
Exit code:
1059+
exit code returned from bump2version
1060+
'
1061+
}
1062+
bump_version() {
1063+
local part=${1:-}
1064+
local ret=0
1065+
1066+
if ! command -v bump2version > /dev/null; then
1067+
c_echo G "bump2version" W " doesn't exists. Installing prerequisites..."
1068+
install_python_dev_deps
1069+
fi
1070+
1071+
pushd $TOP > /dev/null
1072+
1073+
case "$part" in
1074+
major|minor|patch|release|build)
1075+
local current_version="$(bump2version --dry-run --list --allow-dirty $part | grep -Po 'current_version=\K[\d\.]+((a|b|rc)\d+)?')"
1076+
local new_version="$(bump2version --dry-run --list --allow-dirty $part | grep -Po 'new_version=\K[\d\.]+((a|b|rc)\d+)?')"
1077+
c_echo W "current_version=" G "${current_version}"
1078+
c_echo W "new_version=" G "${new_version}"
1079+
1080+
bump2version "$@"
1081+
ret=$?
1082+
;;
1083+
*)
1084+
bump2version "$@"
1085+
ret=$?
1086+
;;
1087+
esac
1088+
1089+
popd > /dev/null
1090+
1091+
return $ret
1092+
}
9841093

9851094
#==================================================================================
9861095

0 commit comments

Comments
 (0)