Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-10 07:49:31

0001 #!/usr/bin/env bash
0002 
0003 usage(){ cat << EOU
0004 CSGOptiXService_FastAPI_test.sh
0005 ================================
0006 
0007 This requires the *uv* python package+venv tool::
0008 
0009     https://github.com/astral-sh/uv
0010 
0011 Build and start the FastAPI HTTP server, on first run dependencies
0012 are downloaded from pypi into the virtual env .venv directory::
0013 
0014     ~/opticks/CSGOptiX/tests/CSGOptiXService_FastAPI_test/CSGOptiXService_FastAPI_test.sh
0015 
0016 Make HTTP POST requests to the endpoint::
0017 
0018      ~/np/tests/np_curl_test/np_curl_test.sh
0019      LEVEL=1 MULTIPART=0  ~/np/tests/np_curl_test/np_curl_test.sh
0020      LEVEL=1 MULTIPART=1  ~/np/tests/np_curl_test/np_curl_test.sh
0021 
0022 EOU
0023 }
0024 
0025 
0026 cd $(dirname $(realpath $BASH_SOURCE))
0027 
0028 source $HOME/.opticks/GEOM/GEOM.sh
0029 
0030 
0031 ## TODO: MOVE THIS CONFIG INTO CODE ?
0032 export OPTICKS_EVENT_MODE=Hit
0033 export OPTICKS_HIT_MASK=EC
0034 
0035 
0036 
0037 defarg="info_venv_run"
0038 arg=${1:-$defarg}
0039 
0040 if [ "${arg/clean}" != "$arg" ]; then
0041 
0042    rm -rf __pycache__
0043    rm -rf .venv
0044 fi
0045 
0046 
0047 if [ "${arg/info}" != "$arg" ]; then
0048     vv="BASH_SOURCE PWD defarg arg GEOM"
0049     for v in $vv ; do printf "%30s : %s\n" "$v" "${!v}" ; done
0050 fi
0051 
0052 if [ "${arg/venv}" != "$arg" ]; then
0053     if [ ! -d ".venv" ]; then
0054         echo $BASH_SOURCE - installing dependencies
0055         echo .venv > .gitignore
0056         echo __pycache__ >> .gitignore
0057         uv venv
0058         uv pip install "fastapi[standard]" numpy ipython
0059     else
0060         echo $BASH_SOURCE - using existing .venv
0061     fi
0062 fi
0063 
0064 if [ -f .venv/bin/activate ]; then
0065    source .venv/bin/activate
0066    [ $? -ne 0 ] && echo $BASH_SOURCE - failed to activate venv && exit 1
0067 else
0068    echo $BASH_SOURCE - no .venv - EXIT HERE && exit 0
0069 fi
0070 
0071 
0072 if [ "${arg/run}" != "$arg" ]; then
0073     which fastapi
0074     fastapi dev main.py
0075     [ $? -ne 0 ] && echo $BASH_SOURCE - failed to fastapi dev && exit 2
0076 fi
0077 
0078 if [ "${arg/pdb}" != "$arg" ]; then
0079     which ipython
0080     ipython -i check.py
0081     [ $? -ne 0 ] && echo $BASH_SOURCE - failed to pdb && exit 3
0082 fi
0083 
0084 
0085 exit 0