From 7a536f63bc66bd5d00b686e299d78ba3c1c21219 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Wed, 29 Jan 2025 09:55:39 -0800 Subject: [PATCH] STY: Enable shellcheck pre-commit hook --- .pre-commit-config.yaml | 5 +++++ ci/code_checks.sh | 18 +++++++++--------- ci/run_tests.sh | 8 +++----- ci/upload_wheels.sh | 9 +++++---- scripts/cibw_before_build.sh | 1 + scripts/cibw_before_build_windows.sh | 1 + scripts/cibw_before_test_windows.sh | 1 + scripts/download_wheels.sh | 17 +++++++++-------- 8 files changed, 34 insertions(+), 26 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1dd8dfc54111e..8031521a140f4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -106,6 +106,11 @@ repos: hooks: - id: meson-fmt args: ['--inplace'] +- repo: https://github.com/shellcheck-py/shellcheck-py + rev: v0.10.0.1 + hooks: + - id: shellcheck + args: ["--severity=warning"] - repo: local hooks: - id: pyright diff --git a/ci/code_checks.sh b/ci/code_checks.sh index ee5b7eb4f09fb..5782b2b171e07 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -24,15 +24,15 @@ else fi [[ -z "$CHECK" || "$CHECK" == "code" || "$CHECK" == "doctests" || "$CHECK" == "docstrings" || "$CHECK" == "single-docs" || "$CHECK" == "notebooks" ]] || \ - { echo "Unknown command $1. Usage: $0 [code|doctests|docstrings|single-docs|notebooks]"; exit 9999; } + { echo "Unknown command $1. Usage: $0 [code|doctests|docstrings|single-docs|notebooks]"; exit 1; } -BASE_DIR="$(dirname $0)/.." +BASE_DIR="$(dirname "$0")/.." RET=0 ### CODE ### if [[ -z "$CHECK" || "$CHECK" == "code" ]]; then - MSG='Check import. No warnings, and blocklist some optional dependencies' ; echo $MSG + MSG='Check import. No warnings, and blocklist some optional dependencies' ; echo "$MSG" python -W error -c " import sys import pandas @@ -49,24 +49,24 @@ if mods: sys.stderr.write('err: pandas should not import: {}\n'.format(', '.join(mods))) sys.exit(len(mods)) " - RET=$(($RET + $?)) ; echo $MSG "DONE" + RET=$(($RET + $?)) ; echo "$MSG" "DONE" fi ### DOCTESTS ### if [[ -z "$CHECK" || "$CHECK" == "doctests" ]]; then - MSG='Python and Cython Doctests' ; echo $MSG + MSG='Python and Cython Doctests' ; echo "$MSG" python -c 'import pandas as pd; pd.test(run_doctests=True)' - RET=$(($RET + $?)) ; echo $MSG "DONE" + RET=$(($RET + $?)) ; echo "$MSG" "DONE" fi ### DOCSTRINGS ### if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then - MSG='Validate Docstrings' ; echo $MSG - $BASE_DIR/scripts/validate_docstrings.py \ + MSG='Validate Docstrings' ; echo "$MSG" + "$BASE_DIR"/scripts/validate_docstrings.py \ --format=actions \ -i ES01 `# For now it is ok if docstrings are missing the extended summary` \ -i "pandas.Series.dt PR01" `# Accessors are implemented as classes, but we do not document the Parameters section` \ @@ -265,7 +265,7 @@ fi if [[ -z "$CHECK" || "$CHECK" == "notebooks" ]]; then MSG='Notebooks' ; echo $MSG - jupyter nbconvert --execute $(find doc/source -name '*.ipynb') --to notebook + jupyter nbconvert --execute "$(find doc/source -name '*.ipynb')" --to notebook RET=$(($RET + $?)) ; echo $MSG "DONE" fi diff --git a/ci/run_tests.sh b/ci/run_tests.sh index d2c2f58427a23..16292beec612b 100755 --- a/ci/run_tests.sh +++ b/ci/run_tests.sh @@ -3,10 +3,8 @@ # Workaround for pytest-xdist (it collects different tests in the workers if PYTHONHASHSEED is not set) # https://github.com/pytest-dev/pytest/issues/920 # https://github.com/pytest-dev/pytest/issues/1075 -export PYTHONHASHSEED=$(python -c 'import random; print(random.randint(1, 4294967295))') - -# May help reproduce flaky CI builds if set in subsequent runs -echo PYTHONHASHSEED=$PYTHONHASHSEED +PYTHONHASHSEED=$(python -c 'import random; print(random.randint(1, 4294967295))') +export PYTHONHASHSEED COVERAGE="-s --cov=pandas --cov-report=xml --cov-append --cov-config=pyproject.toml" @@ -16,5 +14,5 @@ if [[ "$PATTERN" ]]; then PYTEST_CMD="$PYTEST_CMD -m \"$PATTERN\"" fi -echo $PYTEST_CMD +echo "$PYTEST_CMD" sh -c "$PYTEST_CMD" diff --git a/ci/upload_wheels.sh b/ci/upload_wheels.sh index 3c4aa76c02003..c7c7ca00ee466 100644 --- a/ci/upload_wheels.sh +++ b/ci/upload_wheels.sh @@ -1,3 +1,4 @@ +#!/bin/bash # Modified from numpy's https://github.com/numpy/numpy/blob/main/tools/wheels/upload_wheels.sh set_upload_vars() { @@ -19,20 +20,20 @@ set_upload_vars() { fi } upload_wheels() { - echo ${PWD} + echo "${PWD}" if [[ ${ANACONDA_UPLOAD} == true ]]; then - if [ -z ${TOKEN} ]; then + if [ -z "${TOKEN}" ]; then echo no token set, not uploading else # sdists are located under dist folder when built through setup.py if compgen -G "./dist/*.gz"; then echo "Found sdist" - anaconda -q -t ${TOKEN} upload --skip -u ${ANACONDA_ORG} ./dist/*.gz + anaconda -q -t "${TOKEN}" upload --skip -u "${ANACONDA_ORG}" ./dist/*.gz echo "Uploaded sdist" fi if compgen -G "./wheelhouse/*.whl"; then echo "Found wheel" - anaconda -q -t ${TOKEN} upload --skip -u ${ANACONDA_ORG} ./wheelhouse/*.whl + anaconda -q -t "${TOKEN}" upload --skip -u "${ANACONDA_ORG}" ./wheelhouse/*.whl echo "Uploaded wheel" fi echo "PyPI-style index: https://pypi.anaconda.org/$ANACONDA_ORG/simple" diff --git a/scripts/cibw_before_build.sh b/scripts/cibw_before_build.sh index 4cdbf8db0ba89..d326dd3637314 100644 --- a/scripts/cibw_before_build.sh +++ b/scripts/cibw_before_build.sh @@ -1,3 +1,4 @@ +#!/bin/bash # Add 3rd party licenses, like numpy does for file in $PACKAGE_DIR/LICENSES/*; do cat $file >> $PACKAGE_DIR/LICENSE diff --git a/scripts/cibw_before_build_windows.sh b/scripts/cibw_before_build_windows.sh index 5153ebd691f3b..f9e1e68d8efba 100644 --- a/scripts/cibw_before_build_windows.sh +++ b/scripts/cibw_before_build_windows.sh @@ -1,3 +1,4 @@ +#!/bin/bash # Add 3rd party licenses, like numpy does for file in $PACKAGE_DIR/LICENSES/*; do cat $file >> $PACKAGE_DIR/LICENSE diff --git a/scripts/cibw_before_test_windows.sh b/scripts/cibw_before_test_windows.sh index dd02bc23dd5a1..8878e3950452f 100644 --- a/scripts/cibw_before_test_windows.sh +++ b/scripts/cibw_before_test_windows.sh @@ -1,3 +1,4 @@ +#!/bin/bash # TODO: Delete when there's a NumPy Windows wheel for the free-threaded build on PyPI. FREE_THREADED_BUILD="$(python -c"import sysconfig; print(bool(sysconfig.get_config_var('Py_GIL_DISABLED')))")" if [[ $FREE_THREADED_BUILD == "True" ]]; then diff --git a/scripts/download_wheels.sh b/scripts/download_wheels.sh index 84279ac7a04d1..3dcae0cadcdcf 100755 --- a/scripts/download_wheels.sh +++ b/scripts/download_wheels.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # # Download all wheels for a pandas version. # @@ -11,11 +11,12 @@ # one by one to the dist/ directory where they would be generated. VERSION=$1 -mkdir -p $(dirname -- $0)/../dist -DIST_DIR="$(realpath $(dirname -- $0)/../dist)" +BASE_DIR=$(dirname -- $0) +mkdir -p $BASE_DIR/../dist +DIST_DIR="$(realpath $BASE_DIR/../dist)" -if [ -z $VERSION ]; then - printf "Usage:\n\t$0 \n\nWhere is for example 1.5.3" +if [ -z "$VERSION" ]; then + printf "Usage:\n\t%s \n\nWhere is for example 1.5.3" "$0" exit 1 fi @@ -23,7 +24,7 @@ curl "https://anaconda.org/multibuild-wheels-staging/pandas/files?version=${VERS grep "href=\"/multibuild-wheels-staging/pandas/${VERSION}" | \ sed -r 's/.*.*/\1/g' | \ awk '{print "https://anaconda.org" $0 }' | \ - xargs wget -P $DIST_DIR + xargs wget -P "$DIST_DIR" -printf "\nWheels downloaded to $DIST_DIR\nYou can upload them to PyPI using:\n\n" -printf "\ttwine upload ${DIST_DIR}/pandas-${VERSION}*.{whl,tar.gz} --skip-existing" +printf '\nWheels downloaded to %s\nYou can upload them to PyPI using:\n\n' "$DIST_DIR" +printf "\ttwine upload %s/pandas-%s*.{whl,tar.gz} --skip-existing" "$DIST_DIR" "$VERSION"