From 29e84a3c5e8ca13de010d318104a19e7c27bc8da Mon Sep 17 00:00:00 2001 From: Gil Forsyth Date: Wed, 22 Jan 2025 15:48:28 -0500 Subject: [PATCH] Add shellcheck to pre-commit and fix warnings --- .pre-commit-config.yaml | 6 ++++++ ci/build_docs.sh | 11 +++++++---- ci/build_python.sh | 4 +--- ci/build_wheel.sh | 4 ++-- ci/build_wheel_cuspatial.sh | 4 ++-- ci/check_style.sh | 4 ++-- ci/release/update-version.sh | 12 ++++-------- ci/test_cpp.sh | 6 +++--- ci/test_notebooks.sh | 5 +++-- ci/test_wheel_cuproj.sh | 4 ++-- ci/test_wheel_cuspatial.sh | 4 ++-- ci/utils/nbtest.sh | 16 ++++++++-------- ci/validate_wheel.sh | 6 +++--- 13 files changed, 45 insertions(+), 41 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 77a98437e..a12c23fd6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -52,6 +52,12 @@ repos: hooks: - id: rapids-dependency-file-generator args: ["--clean"] + - repo: https://github.com/shellcheck-py/shellcheck-py + rev: v0.10.0.1 + hooks: + - id: shellcheck + args: ["--severity=warning"] + files: ^ci/ default_language_version: diff --git a/ci/build_docs.sh b/ci/build_docs.sh index ab2b56c35..2e7fa5e28 100755 --- a/ci/build_docs.sh +++ b/ci/build_docs.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright (c) 2023-2024, NVIDIA CORPORATION. +# Copyright (c) 2023-2025, NVIDIA CORPORATION. set -euo pipefail @@ -21,9 +21,12 @@ conda activate docs rapids-print-env -export RAPIDS_VERSION="$(rapids-version)" -export RAPIDS_VERSION_MAJOR_MINOR="$(rapids-version-major-minor)" -export RAPIDS_DOCS_DIR="$(mktemp -d)" +RAPIDS_VERSION="$(rapids-version)" +RAPIDS_VERSION_MAJOR_MINOR="$(rapids-version-major-minor)" +RAPIDS_DOCS_DIR="$(mktemp -d)" +export RAPIDS_VERSION +export RAPIDS_VERSION_MAJOR_MINOR +export RAPIDS_DOCS_DIR rapids-logger "Build cuSpatial CPP docs" pushd cpp/doxygen diff --git a/ci/build_python.sh b/ci/build_python.sh index e0ff96639..fd8002480 100755 --- a/ci/build_python.sh +++ b/ci/build_python.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright (c) 2022-2024, NVIDIA CORPORATION. +# Copyright (c) 2022-2025, NVIDIA CORPORATION. set -euo pipefail @@ -13,8 +13,6 @@ export CMAKE_GENERATOR=Ninja rapids-print-env -package_dir="python" - rapids-generate-version > ./VERSION CPP_CHANNEL=$(rapids-download-conda-from-s3 cpp) diff --git a/ci/build_wheel.sh b/ci/build_wheel.sh index 363d10d42..b742baf0a 100755 --- a/ci/build_wheel.sh +++ b/ci/build_wheel.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright (c) 2023-2024, NVIDIA CORPORATION. +# Copyright (c) 2023-2025, NVIDIA CORPORATION. set -euo pipefail @@ -31,7 +31,7 @@ source rapids-date-string rapids-generate-version > ./VERSION -RAPIDS_PY_CUDA_SUFFIX="$(rapids-wheel-ctk-name-gen ${RAPIDS_CUDA_VERSION})" +RAPIDS_PY_CUDA_SUFFIX="$(rapids-wheel-ctk-name-gen "${RAPIDS_CUDA_VERSION}")" cd "${package_dir}" diff --git a/ci/build_wheel_cuspatial.sh b/ci/build_wheel_cuspatial.sh index 780ac0710..1f839ebf8 100755 --- a/ci/build_wheel_cuspatial.sh +++ b/ci/build_wheel_cuspatial.sh @@ -1,11 +1,11 @@ #!/bin/bash -# Copyright (c) 2023-2024, NVIDIA CORPORATION. +# Copyright (c) 2023-2025, NVIDIA CORPORATION. set -euo pipefail package_dir="python/cuspatial" -RAPIDS_PY_CUDA_SUFFIX="$(rapids-wheel-ctk-name-gen ${RAPIDS_CUDA_VERSION})" +RAPIDS_PY_CUDA_SUFFIX="$(rapids-wheel-ctk-name-gen "${RAPIDS_CUDA_VERSION}")" # Downloads libcuspatial wheel from this current build, # then ensures 'cuspatial' wheel builds always use the 'libcuspatial' just built in the same CI run. diff --git a/ci/check_style.sh b/ci/check_style.sh index cbc369dc0..6d20e3a2b 100755 --- a/ci/check_style.sh +++ b/ci/check_style.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright (c) 2020-2024, NVIDIA CORPORATION. +# Copyright (c) 2020-2025, NVIDIA CORPORATION. set -euo pipefail @@ -16,7 +16,7 @@ conda activate checks FORMAT_FILE_URL=https://raw.githubusercontent.com/rapidsai/rapids-cmake/branch-23.02/cmake-format-rapids-cmake.json export RAPIDS_CMAKE_FORMAT_FILE=/tmp/rapids_cmake_ci/cmake-formats-rapids-cmake.json -mkdir -p $(dirname ${RAPIDS_CMAKE_FORMAT_FILE}) +mkdir -p "$(dirname ${RAPIDS_CMAKE_FORMAT_FILE})" wget -O ${RAPIDS_CMAKE_FORMAT_FILE} ${FORMAT_FILE_URL} # Run pre-commit checks diff --git a/ci/release/update-version.sh b/ci/release/update-version.sh index dfd0fe7e3..d99f28882 100755 --- a/ci/release/update-version.sh +++ b/ci/release/update-version.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright (c) 2019-2024, NVIDIA CORPORATION. +# Copyright (c) 2019-2025, NVIDIA CORPORATION. ############################# # cuSpatial Version Updater # ############################# @@ -13,14 +13,10 @@ NEXT_FULL_TAG=$1 # Get current version CURRENT_TAG=$(git tag --merged HEAD | grep -xE '^v.*' | sort --version-sort | tail -n 1 | tr -d 'v') -CURRENT_MAJOR=$(echo $CURRENT_TAG | awk '{split($0, a, "."); print a[1]}') -CURRENT_MINOR=$(echo $CURRENT_TAG | awk '{split($0, a, "."); print a[2]}') -CURRENT_PATCH=$(echo $CURRENT_TAG | awk '{split($0, a, "."); print a[3]}') -CURRENT_SHORT_TAG=${CURRENT_MAJOR}.${CURRENT_MINOR} # Get . for next version -NEXT_MAJOR=$(echo $NEXT_FULL_TAG | awk '{split($0, a, "."); print a[1]}') -NEXT_MINOR=$(echo $NEXT_FULL_TAG | awk '{split($0, a, "."); print a[2]}') +NEXT_MAJOR=$(echo "$NEXT_FULL_TAG" | awk '{split($0, a, "."); print a[1]}') +NEXT_MINOR=$(echo "$NEXT_FULL_TAG" | awk '{split($0, a, "."); print a[2]}') NEXT_SHORT_TAG=${NEXT_MAJOR}.${NEXT_MINOR} # Need to distutils-normalize the original version @@ -30,7 +26,7 @@ echo "Preparing release $CURRENT_TAG => $NEXT_FULL_TAG" # Inplace sed replace; workaround for Linux and Mac function sed_runner() { - sed -i.bak ''"$1"'' $2 && rm -f ${2}.bak + sed -i.bak ''"$1"'' "$2" && rm -f "${2}".bak } # Centralized version file update diff --git a/ci/test_cpp.sh b/ci/test_cpp.sh index 0f0a09ef1..410be367e 100755 --- a/ci/test_cpp.sh +++ b/ci/test_cpp.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright (c) 2022-2024, NVIDIA CORPORATION. +# Copyright (c) 2022-2025, NVIDIA CORPORATION. set -euo pipefail @@ -41,9 +41,9 @@ set +e # Run libcuspatial gtests from libcuspatial-tests package rapids-logger "Run gtests" for gt in "$CONDA_PREFIX"/bin/gtests/libcuspatial/* ; do - test_name=$(basename ${gt}) + test_name=$(basename "${gt}") echo "Running gtest $test_name" - ${gt} --gtest_output=xml:${RAPIDS_TESTS_DIR} + ${gt} --gtest_output=xml:"{RAPIDS_TESTS_DIR}" done rapids-logger "Test script exiting with value: $EXITCODE" diff --git a/ci/test_notebooks.sh b/ci/test_notebooks.sh index c6cba4a15..edb5b4ecb 100755 --- a/ci/test_notebooks.sh +++ b/ci/test_notebooks.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright (c) 2020-2024, NVIDIA CORPORATION. +# Copyright (c) 2020-2025, NVIDIA CORPORATION. set -eEuo pipefail @@ -37,8 +37,9 @@ trap "EXITCODE=1" ERR set +e test_notebooks() { + # shellcheck disable=SC2044 for nb in $(find . -name "*.ipynb"); do - nbBasename=$(basename ${nb}) + nbBasename=$(basename "${nb}") if (echo " ${SKIPNBS} " | grep -q " ${nbBasename} "); then echo "--------------------------------------------------------------------------------" echo "SKIPPING: ${nb} (listed in skip list)" diff --git a/ci/test_wheel_cuproj.sh b/ci/test_wheel_cuproj.sh index abd20ebf1..a5ccf0dbb 100755 --- a/ci/test_wheel_cuproj.sh +++ b/ci/test_wheel_cuproj.sh @@ -1,10 +1,10 @@ #!/bin/bash -# Copyright (c) 2023-2024, NVIDIA CORPORATION. +# Copyright (c) 2023-2025, NVIDIA CORPORATION. set -eou pipefail mkdir -p ./dist -RAPIDS_PY_CUDA_SUFFIX="$(rapids-wheel-ctk-name-gen ${RAPIDS_CUDA_VERSION})" +RAPIDS_PY_CUDA_SUFFIX="$(rapids-wheel-ctk-name-gen "${RAPIDS_CUDA_VERSION}")" # Download the cuproj and cuspatial built in the previous step RAPIDS_PY_WHEEL_NAME="cuproj_${RAPIDS_PY_CUDA_SUFFIX}" rapids-download-wheels-from-s3 python ./dist diff --git a/ci/test_wheel_cuspatial.sh b/ci/test_wheel_cuspatial.sh index a352e1bfd..f669a02b9 100755 --- a/ci/test_wheel_cuspatial.sh +++ b/ci/test_wheel_cuspatial.sh @@ -1,10 +1,10 @@ #!/bin/bash -# Copyright (c) 2023-2024, NVIDIA CORPORATION. +# Copyright (c) 2023-2025, NVIDIA CORPORATION. set -eou pipefail mkdir -p ./dist -RAPIDS_PY_CUDA_SUFFIX="$(rapids-wheel-ctk-name-gen ${RAPIDS_CUDA_VERSION})" +RAPIDS_PY_CUDA_SUFFIX="$(rapids-wheel-ctk-name-gen "${RAPIDS_CUDA_VERSION}")" # Download the cuspatial and libcuspatial built in the previous step RAPIDS_PY_WHEEL_NAME="cuspatial_${RAPIDS_PY_CUDA_SUFFIX}" rapids-download-wheels-from-s3 python ./dist diff --git a/ci/utils/nbtest.sh b/ci/utils/nbtest.sh index fa1489563..624537231 100755 --- a/ci/utils/nbtest.sh +++ b/ci/utils/nbtest.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright (c) 2023-2024, NVIDIA CORPORATION. +# Copyright (c) 2023-2025, NVIDIA CORPORATION. set -e -u -o pipefail @@ -29,20 +29,20 @@ NBTMPDIR="$(mktemp -d)" EXITCODE=0 trap "EXITCODE=1" ERR -for nb in $*; do - NBFILENAME=$1 +for nb in "$@"; do + NBFILENAME=$nb NBNAME=${NBFILENAME%.*} NBNAME=${NBNAME##*/} NBTESTSCRIPT=${NBTMPDIR}/${NBNAME}-test.py shift echo -------------------------------------------------------------------------------- - echo STARTING: ${NBNAME} + echo STARTING: "${NBNAME}" echo -------------------------------------------------------------------------------- - jupyter nbconvert --to script ${NBFILENAME} --output ${NBTMPDIR}/${NBNAME}-test - echo "${MAGIC_OVERRIDE_CODE}" > ${NBTMPDIR}/tmpfile - cat ${NBTESTSCRIPT} >> ${NBTMPDIR}/tmpfile - mv ${NBTMPDIR}/tmpfile ${NBTESTSCRIPT} + jupyter nbconvert --to script "${NBFILENAME}" --output "${NBTMPDIR}"/"${NBNAME}"-test + echo "${MAGIC_OVERRIDE_CODE}" > "${NBTMPDIR}"/tmpfile + cat "${NBTESTSCRIPT}" >> "${NBTMPDIR}"/tmpfile + mv "${NBTMPDIR}"/tmpfile "${NBTESTSCRIPT}" echo "Running \"ipython ${NO_COLORS} ${NBTESTSCRIPT}\" on $(date)" echo diff --git a/ci/validate_wheel.sh b/ci/validate_wheel.sh index 5910a5c59..40bb27fee 100755 --- a/ci/validate_wheel.sh +++ b/ci/validate_wheel.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright (c) 2024, NVIDIA CORPORATION. +# Copyright (c) 2024-2025, NVIDIA CORPORATION. set -euo pipefail @@ -12,10 +12,10 @@ rapids-logger "validate packages with 'pydistcheck'" pydistcheck \ --inspect \ - "$(echo ${wheel_dir_relative_path}/*.whl)" + "$(echo "${wheel_dir_relative_path}"/*.whl)" rapids-logger "validate packages with 'twine'" twine check \ --strict \ - "$(echo ${wheel_dir_relative_path}/*.whl)" + "$(echo "${wheel_dir_relative_path}"/*.whl)"