From fb0076670a6be93c43281b73b246a383530107e4 Mon Sep 17 00:00:00 2001 From: Batkhuu Date: Mon, 11 Sep 2023 13:03:53 +0900 Subject: [PATCH] :hammer: Updated scripts options. --- docs/scripts/2.clean.md | 7 ++++- docs/scripts/4.test.md | 15 ++++++++- scripts/build.sh | 2 ++ scripts/bump-version.sh | 1 + scripts/clean.sh | 31 +++++++++++++++--- scripts/test.sh | 70 ++++++++++++++++++++++++++++++++++++++--- 6 files changed, 115 insertions(+), 11 deletions(-) diff --git a/docs/scripts/2.clean.md b/docs/scripts/2.clean.md index dca388b..d01554f 100644 --- a/docs/scripts/2.clean.md +++ b/docs/scripts/2.clean.md @@ -15,9 +15,14 @@ The script performs the following operations: To execute the clean script, simply run the following command in the terminal: ```sh -./clean.sh +./clean.sh [-a|--all] ``` +**Examples**: + +- To clean just non-essential files: `./clean.sh` +- To clean all files: `./clean.sh -a` + This will clean up the project directory, removing any unnecessary files and directories and ensuring a clean environment for a fresh build. **Source code**: [**`clean.sh`**](../../scripts/clean.sh) diff --git a/docs/scripts/4.test.md b/docs/scripts/4.test.md index 7e88deb..84f375a 100644 --- a/docs/scripts/4.test.md +++ b/docs/scripts/4.test.md @@ -6,15 +6,28 @@ The script performs the following operations: - **Loading base script**: Includes the `base.sh` script to gain access to its utility functions and environment variables. - **Running pytest**: Runs the pytest tests for the project. +- **Logging**: If the `-l` or `--log` option is provided, the script will log the output of the pytest tests to console. +- **Coverage**: If the `-c` or `--cov` option is provided, the script will run the pytest tests with coverage. +- **Verbose**: If the `-v` or `--verbose` option is provided, the script will run the pytest tests with verbose error outputs. **Usage**: To execute the test script, simply run the following command in the terminal: ```sh -./test.sh +./test.sh [-l|--log] [-c|--cov] [-v|--verbose] ``` +**Examples**: + +- To test: `./test.sh` +- To test with logging: `./test.sh -l` +- To test with coverage: `./test.sh -c` +- To test with verbose: `./test.sh -v` +- To test with logging, coverage and verbose: `./test.sh -l -c -v` + +This script will run the pytest tests for the project. It can also be used to run the tests with logging, coverage, and verbose options. + **Source code**: [**`test.sh`**](../../scripts/test.sh) --- diff --git a/scripts/build.sh b/scripts/build.sh index 6bf7094..d837151 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -61,6 +61,7 @@ main() fi ## --- Menu arguments --- ## + if [ "${_IS_TEST}" == true ]; then if [ -z "$(which pytest)" ]; then echoError "Pytest not found or not installed." @@ -84,6 +85,7 @@ main() ./scripts/test.sh || exit 2 fi + echoInfo "Building package..." # python setup.py sdist bdist_wheel || exit 2 python -m build || exit 2 diff --git a/scripts/bump-version.sh b/scripts/bump-version.sh index 91a441d..edb525d 100755 --- a/scripts/bump-version.sh +++ b/scripts/bump-version.sh @@ -55,6 +55,7 @@ main() fi ## --- Menu arguments --- ## + if [ -z "${_BUMP_TYPE:-}" ]; then echoError "Bump type is empty! Use '-b=' or '--bump-type=' argument." exit 1 diff --git a/scripts/clean.sh b/scripts/clean.sh index 8a64f34..690a4ec 100755 --- a/scripts/clean.sh +++ b/scripts/clean.sh @@ -13,25 +13,48 @@ source ./scripts/base.sh ## --- Base --- ## +## --- Variables --- ## +# Flags: +_IS_ALL=false +## --- Variables --- ## + + ## --- Main --- ## main() { + ## --- Menu arguments --- ## + if [ -n "${1:-}" ]; then + for _input in "${@:-}"; do + case ${_input} in + -a | --all) + _IS_ALL=true + shift;; + *) + echoError "Failed to parsing input -> ${_input}" + echoInfo "USAGE: ${0} -a, --all" + exit 1;; + esac + done + fi + ## --- Menu arguments --- ## + + echoInfo "Cleaning..." find . -type f -name ".DS_Store" -print -delete || exit 2 find . -type f -name ".Thumbs.db" -print -delete || exit 2 find . -type d -name "__pycache__" -exec rm -rfv {} + || exit 2 - # find . -type d -name "logs" -exec rm -rfv {} + || exit 2 + find ./examples -type d -name "logs" -exec rm -rfv {} + || exit 2 - rm -rfv ./examples/simple/logs || exit 2 - rm -rfv ./examples/advanced/logs || exit 2 rm -rfv .benchmarks || exit 2 rm -rfv .pytest_cache || exit 2 rm -rfv build || exit 2 rm -rfv dist || exit 2 - # rm -rfv ./*.egg-info || exit 2 rm -rfv .coverage || exit 2 + if [ "${_IS_ALL}" == true ]; then + rm -rfv ./*.egg-info || exit 2 + fi echoOk "Done." } diff --git a/scripts/test.sh b/scripts/test.sh index b379dd3..7db84b9 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -24,8 +24,68 @@ fi ## --- Base --- ## -echoInfo "Running test..." -python -m pytest -sv || exit 2 -# python -m pytest -sv -o log_cli=true || exit 2 -# python -m pytest -sv --cov -o log_cli=true || exit 2 -echoOk "Done." +## --- Variables --- ## +# Flags: +_IS_LOGGING=false +_IS_COVERAGE=false +_IS_VERBOSE=false +## --- Variables --- ## + + +## --- Main --- ## +main() +{ + ## --- Menu arguments --- ## + if [ -n "${1:-}" ]; then + for _input in "${@:-}"; do + case ${_input} in + -l | --log) + _IS_LOGGING=true + shift;; + -c | --cov) + _IS_COVERAGE=true + shift;; + -v | --verbose) + _IS_VERBOSE=true + shift;; + *) + echoError "Failed to parsing input -> ${_input}" + echoInfo "USAGE: ${0} -l, --log | -c, --cov | -v, --verbose" + exit 1;; + esac + done + fi + ## --- Menu arguments --- ## + + + if [ "${_IS_COVERAGE}" == true ]; then + if ! python -c "import pytest_cov" &> /dev/null; then + echoError "'pytest-cov' python package is not installed." + exit 1 + fi + fi + + + _logging_param="" + _coverage_param="" + _verbose_param="" + if [ "${_IS_LOGGING}" == true ]; then + _logging_param="-o log_cli=true" + fi + + if [ "${_IS_COVERAGE}" == true ]; then + _coverage_param="--cov" + fi + + if [ "${_IS_VERBOSE}" == true ]; then + _verbose_param="-vv" + fi + + echoInfo "Running test..." + # shellcheck disable=SC2086 + python -m pytest -sv ${_coverage_param} ${_logging_param} ${_verbose_param} || exit 2 + echoOk "Done." +} + +main "${@:-}" +## --- Main --- ##