From 859bfe0ae6cd2b21636ea5145dfc486c770b0af1 Mon Sep 17 00:00:00 2001 From: Ivan Ogasawara Date: Thu, 26 Sep 2024 15:36:56 -0400 Subject: [PATCH] test: Add smoke test for pyenv and split base.sh into base and base-template scripts (#315) --- .../virtualenvs/pyenv/requirements.txt | 1 - tests/smoke/base-template.sh | 56 +++++++++++++++++++ tests/smoke/base.sh | 53 ++---------------- tests/smoke/virtual-envs.sh | 6 +- 4 files changed, 66 insertions(+), 50 deletions(-) create mode 100755 tests/smoke/base-template.sh diff --git a/src/scicookie/{{cookiecutter.project_slug}}/virtualenvs/pyenv/requirements.txt b/src/scicookie/{{cookiecutter.project_slug}}/virtualenvs/pyenv/requirements.txt index c232a811..6d790b88 100644 --- a/src/scicookie/{{cookiecutter.project_slug}}/virtualenvs/pyenv/requirements.txt +++ b/src/scicookie/{{cookiecutter.project_slug}}/virtualenvs/pyenv/requirements.txt @@ -1,4 +1,3 @@ -python < 3.11 {%- if cookiecutter.build_system == "poetry" %} poetry {%- elif cookiecutter.build_system == "flit" %} diff --git a/tests/smoke/base-template.sh b/tests/smoke/base-template.sh new file mode 100755 index 00000000..faea2850 --- /dev/null +++ b/tests/smoke/base-template.sh @@ -0,0 +1,56 @@ +#!/usr/bin/env bash +echo "-------------------- Smoke test for ${1} -------------------" +set -ex + +export PATH_ORI=${PATH} +export PWD_ORI=$(pwd) +export PROJECT_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && cd ../.. && pwd )" + +export CONDA_PATH=$(ensureconda --conda --no-install | sed 's:/mamba$:/conda:') +export MAMBA_PATH=$(ensureconda --mamba --no-install | sed 's:/conda$:/mamba:') + +if [[ ! -f "$MAMBA_PATH" ]]; then + echo "[EE] 'mamba' not found." + exit 1 +fi + +if [[ ! -f "$CONDA_PATH" ]]; then + echo "[EE] 'conda' not found." + exit 1 +fi + +export input_params="$1" + +if [[ "${input_params}" == *"use_conda=yes"* ]] || [[ "$input_params" == *"use_pyenv=yes"* ]]; then + echo "Virtual environment defined." +else + export input_params="use_conda=yes ${input_params}" +fi + +# NOTE: FOR NOW IT IS JUST USED BY POETRY +export USE_PYENV=0 + +if [[ "${input_params}" == *"use_makim=yes"* ]] || [[ "$input_params" == *"use_make=yes"* ]]; then + echo "Automation task tool defined." +else + export input_params="use_makim=yes ${input_params}" +fi + +if [[ "${input_params}" == *"use_pre_commit=yes"* ]]; then + echo "pre-commit tool defined." +else + export input_params="use_pre_commit=yes ${input_params}" +fi + +export OUTPUT_DIR="/tmp/osl" +rm -rf "${OUTPUT_DIR}" +mkdir -p "${OUTPUT_DIR}" + +cookiecutter --no-input \ + --output-dir "${OUTPUT_DIR}" \ + "${PROJECT_PATH}/src/scicookie" \ + ${input_params} + +echo "${OUTPUT_DIR}" + +set +ex diff --git a/tests/smoke/base.sh b/tests/smoke/base.sh index 6de53d23..ae255109 100755 --- a/tests/smoke/base.sh +++ b/tests/smoke/base.sh @@ -1,58 +1,16 @@ #!/usr/bin/env bash echo "-------------------- Smoke test for ${1} -------------------" -set -ex - -PATH_ORI=${PATH} -PWD_ORI=$(pwd) -PROJECT_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && cd ../.. && pwd )" - -CONDA_PATH=$(ensureconda --conda --no-install | sed 's:/mamba$:/conda:') -MAMBA_PATH=$(ensureconda --mamba --no-install | sed 's:/conda$:/mamba:') - -if [[ ! -f "$MAMBA_PATH" ]]; then - echo "[EE] 'mamba' not found." - exit 1 -fi -if [[ ! -f "$CONDA_PATH" ]]; then - echo "[EE] 'conda' not found." - exit 1 -fi - -input_params="$1" +export PROJECT_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && cd ../.. && pwd )" -if [[ "${input_params}" == *"use_conda=yes"* ]] || [[ "$input_params" == *"use_pyenv=yes"* ]]; then - echo "Virtual environment defined." -else - input_params="use_conda=yes ${input_params}" -fi +source $PROJECT_PATH/tests/smoke/base-template.sh ${1} -if [[ "${input_params}" == *"use_makim=yes"* ]] || [[ "$input_params" == *"use_make=yes"* ]]; then - echo "Automation task tool defined." -else - input_params="use_makim=yes ${input_params}" -fi - -if [[ "${input_params}" == *"use_pre_commit=yes"* ]]; then - echo "pre-commit tool defined." -else - input_params="use_pre_commit=yes ${input_params}" -fi +set -ex ENV_NAME=osl-python-package -OUTPUT_DIR="/tmp/osl" -rm -rf "${OUTPUT_DIR}" -mkdir -p "${OUTPUT_DIR}" - -cookiecutter --no-input \ - --output-dir "${OUTPUT_DIR}" \ - "${PROJECT_PATH}/src/scicookie" \ - ${input_params} - cd "${OUTPUT_DIR}/${ENV_NAME}" - if [[ "${input_params}" == *"use_conda=yes"* ]]; then set +x eval "$($CONDA_PATH shell.bash hook)" @@ -62,10 +20,9 @@ if [[ "${input_params}" == *"use_conda=yes"* ]]; then fi if [[ "$input_params" == *"use_pyenv=yes"* ]]; then - set +x virtualenv "${ENV_NAME}" source "${ENV_NAME}/bin/activate" - set -x + pip install -r requirements.txt fi # remove any path to scicookie environment @@ -127,3 +84,5 @@ export PATH=${PATH_ORI} echo '---------------------------- passed --------------------------' cd "${PWD_ORI}" + +set +ex diff --git a/tests/smoke/virtual-envs.sh b/tests/smoke/virtual-envs.sh index 8d8b6967..ce8053cf 100755 --- a/tests/smoke/virtual-envs.sh +++ b/tests/smoke/virtual-envs.sh @@ -1,7 +1,9 @@ #!/usr/bin/env bash -set -e +set -ex SMOKE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" - . ${SMOKE_DIR}/base.sh "use_conda=yes" +. ${SMOKE_DIR}/base.sh "use_pyenv=yes" + +set +ex