11#! /bin/bash
2- function error
3- {
2+
3+ function usage {
4+ cat << EOF
5+ Usage: $( basename " $0 " ) [options]
6+
7+ Options:
8+ -k, --no-clean, --skip-clean, --keep-venv Skip the cleanup step (leave venv active; do not run cleanup script)
9+ -h, --help Show this help
10+ Env:
11+ SKIP_CLEANUP=1 Same as --no-clean
12+ EOF
13+ }
14+
15+ function error {
416 echo
517 echo " ***************************************************************************"
618 echo " * *"
719 echo " * DEV ENV Initialization FAILED! *"
820 echo " * *"
921 echo " ***************************************************************************"
1022 echo
11- exit - 1
23+ exit 1
1224}
1325
26+ # Default: perform cleanup unless asked not to
27+ CLEANUP=1
28+ # Env toggle
29+ if [[ " ${SKIP_CLEANUP:- } " == " 1" || " ${SKIP_CLEANUP:- } " == " true" ]]; then
30+ CLEANUP=0
31+ fi
32+ # CLI options
33+ while [[ $# -gt 0 ]]; do
34+ case " $1 " in
35+ -k|--no-clean|--skip-clean|--keep-venv)
36+ CLEANUP=0
37+ shift
38+ ;;
39+ -h|--help)
40+ usage
41+ exit 0
42+ ;;
43+ * )
44+ echo " Unknown option: $1 "
45+ usage
46+ exit 2
47+ ;;
48+ esac
49+ done
50+
1451export PYTHONDONTWRITEBYTECODE=1
1552
16- type -P python > /dev/null && PYEXE=python || PYEXE=python3
17- if ! $PYEXE -c ' import sys; assert sys.version_info >= (3,11)' > /dev/null 2>&1 ; then
18- echo " Found $( $PYEXE -V) "
19- echo " Expecting at least python 3.11 - exiting!"
20- exit 1
53+ type -P python > /dev/null && PYEXE=python || PYEXE=python3
54+ if ! $PYEXE -c ' import sys; assert sys.version_info >= (3,11)' > /dev/null 2>&1 ; then
55+ echo " Found $( $PYEXE -V) "
56+ echo " Expecting at least python 3.11 - exiting!"
57+ exit 1
2158fi
2259
2360MY_PATH=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " > /dev/null 2>&1 && pwd ) "
24- cd ${MY_PATH} || error
61+ cd " ${MY_PATH} " || error
2562PROJECT_ROOT_PATH=" $MY_PATH /../.."
2663PYTHON_SETUP_PATH=" $MY_PATH /../python_setup"
2764
@@ -48,27 +85,34 @@ java -cp "$JAR_PATH" com.regnosys.rosetta.generator.python.PythonCodeGeneratorCL
4885 -t " $PYTHON_TESTS_TARGET_PATH "
4986JAVA_EXIT_CODE=$?
5087if [[ $JAVA_EXIT_CODE -ne 0 ]]; then
51- echo " Java program returned exit code $JAVA_EXIT_CODE . Stopping script."
52- exit 1
88+ echo " Java program returned exit code $JAVA_EXIT_CODE . Stopping script."
89+ exit 1
5390fi
5491
5592echo " ***** setting up common environment"
93+ # shellcheck disable=SC1090
5694source " $PYTHON_SETUP_PATH /setup_python_env.sh"
5795
5896echo " ***** activating virtual environment"
5997VENV_NAME=" .pyenv"
98+ # shellcheck disable=SC1090
6099source " $PROJECT_ROOT_PATH /$VENV_NAME /${PY_SCRIPTS} /activate" || error
61100
62101# package and install generated Python
63- cd $PYTHON_TESTS_TARGET_PATH
64- $PYEXE -m pip wheel --no-deps --only-binary :all: . || processError
102+ cd " $PYTHON_TESTS_TARGET_PATH " || error
103+ $PYEXE -m pip wheel --no-deps --only-binary :all: . || error
65104$PYEXE -m pip install python_rosetta_dsl-0.0.0-py3-none-any.whl
66105
67106# run tests
68107echo " ***** run unit tests"
69- cd " $MY_PATH "
108+ cd " $MY_PATH " || error
70109$PYEXE -m pytest -p no:cacheprovider " $MY_PATH "
71110
72- echo " ***** cleanup"
73- deactivate
74- source " $PYTHON_SETUP_PATH /cleanup_python_env.sh"
111+ if (( CLEANUP )) ; then
112+ echo " ***** cleanup"
113+ deactivate 2> /dev/null || true
114+ # shellcheck disable=SC1090
115+ source " $PYTHON_SETUP_PATH /cleanup_python_env.sh"
116+ else
117+ echo " ***** skipping cleanup (requested)"
118+ fi
0 commit comments