From 0700a84432f07c7f1294e79b850b10da8accc017 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Fri, 11 Feb 2022 06:32:01 -0600 Subject: [PATCH] PYTHON-1834 Add shellcheck (#858) --- .evergreen/build-manylinux.sh | 2 +- .evergreen/build-windows.sh | 4 ++-- .evergreen/release.sh | 2 +- .evergreen/run-mod-wsgi-tests.sh | 2 +- .evergreen/run-mongodb-aws-test.sh | 2 +- .evergreen/run-tests.sh | 17 +++++++++-------- .pre-commit-config.yaml | 9 +++++++++ .readthedocs.yaml | 1 + doc/conf.py | 1 + doc/docs-requirements.txt | 1 + pymongo/collection.py | 2 +- 11 files changed, 28 insertions(+), 15 deletions(-) diff --git a/.evergreen/build-manylinux.sh b/.evergreen/build-manylinux.sh index 602a8e1e6..a9a7238cb 100755 --- a/.evergreen/build-manylinux.sh +++ b/.evergreen/build-manylinux.sh @@ -27,7 +27,7 @@ fi for image in "${images[@]}"; do docker pull $image - docker run --rm -v `pwd`:/src $image /src/.evergreen/build-manylinux-internal.sh + docker run --rm -v "`pwd`:/src" $image /src/.evergreen/build-manylinux-internal.sh done ls dist diff --git a/.evergreen/build-windows.sh b/.evergreen/build-windows.sh index 97c794076..3a33558cc 100755 --- a/.evergreen/build-windows.sh +++ b/.evergreen/build-windows.sh @@ -9,8 +9,8 @@ mkdir -p validdist mv dist/* validdist || true for VERSION in 36 37 38 39 310; do - _pythons=(C:/Python/Python${VERSION}/python.exe \ - C:/Python/32/Python${VERSION}/python.exe) + _pythons=("C:/Python/Python${VERSION}/python.exe" \ + "C:/Python/32/Python${VERSION}/python.exe") for PYTHON in "${_pythons[@]}"; do rm -rf build $PYTHON setup.py bdist_wheel diff --git a/.evergreen/release.sh b/.evergreen/release.sh index 759786b93..1fdd459ad 100755 --- a/.evergreen/release.sh +++ b/.evergreen/release.sh @@ -1,6 +1,6 @@ #!/bin/bash -ex -if [ $(uname -s) = "Darwin" ]; then +if [ "$(uname -s)" = "Darwin" ]; then .evergreen/build-mac.sh elif [ "Windows_NT" = "$OS" ]; then # Magic variable in cygwin .evergreen/build-windows.sh diff --git a/.evergreen/run-mod-wsgi-tests.sh b/.evergreen/run-mod-wsgi-tests.sh index 03d72e970..9a167895f 100644 --- a/.evergreen/run-mod-wsgi-tests.sh +++ b/.evergreen/run-mod-wsgi-tests.sh @@ -23,7 +23,7 @@ export PYTHONHOME=/opt/python/$PYTHON_VERSION cd .. $APACHE -k start -f ${PROJECT_DIRECTORY}/test/mod_wsgi_test/${APACHE_CONFIG} -trap "$APACHE -k stop -f ${PROJECT_DIRECTORY}/test/mod_wsgi_test/${APACHE_CONFIG}" EXIT HUP +trap '$APACHE -k stop -f ${PROJECT_DIRECTORY}/test/mod_wsgi_test/${APACHE_CONFIG}' EXIT HUP set +e wget -t 1 -T 10 -O - "http://localhost:8080${PROJECT_DIRECTORY}" diff --git a/.evergreen/run-mongodb-aws-test.sh b/.evergreen/run-mongodb-aws-test.sh index e51c12d60..9a33507cc 100755 --- a/.evergreen/run-mongodb-aws-test.sh +++ b/.evergreen/run-mongodb-aws-test.sh @@ -40,7 +40,7 @@ fi set -x # Workaround macOS python 3.9 incompatibility with system virtualenv. -if [ $(uname -s) = "Darwin" ]; then +if [ "$(uname -s)" = "Darwin" ]; then VIRTUALENV="/Library/Frameworks/Python.framework/Versions/3.9/bin/python3 -m virtualenv" else VIRTUALENV=$(command -v virtualenv) diff --git a/.evergreen/run-tests.sh b/.evergreen/run-tests.sh index 69550ec93..7b9d051bd 100755 --- a/.evergreen/run-tests.sh +++ b/.evergreen/run-tests.sh @@ -67,9 +67,9 @@ fi if [ -z "$PYTHON_BINARY" ]; then # Use Python 3 from the server toolchain to test on ARM, POWER or zSeries if a # system python3 doesn't exist or exists but is older than 3.6. - if is_python_36 $(command -v python3); then + if is_python_36 "$(command -v python3)"; then PYTHON=$(command -v python3) - elif is_python_36 $(command -v /opt/mongodbtoolchain/v2/bin/python3); then + elif is_python_36 "$(command -v /opt/mongodbtoolchain/v2/bin/python3)"; then PYTHON=$(command -v /opt/mongodbtoolchain/v2/bin/python3) else echo "Cannot test without python3.6+ installed!" @@ -119,20 +119,21 @@ if [ -n "$TEST_ENCRYPTION" ]; then # Use the nocrypto build to avoid dependency issues with older windows/python versions. BASE=$(pwd)/libmongocrypt/nocrypto if [ -f "${BASE}/lib/libmongocrypt.so" ]; then - export PYMONGOCRYPT_LIB=${BASE}/lib/libmongocrypt.so + PYMONGOCRYPT_LIB=${BASE}/lib/libmongocrypt.so elif [ -f "${BASE}/lib/libmongocrypt.dylib" ]; then - export PYMONGOCRYPT_LIB=${BASE}/lib/libmongocrypt.dylib + PYMONGOCRYPT_LIB=${BASE}/lib/libmongocrypt.dylib elif [ -f "${BASE}/bin/mongocrypt.dll" ]; then PYMONGOCRYPT_LIB=${BASE}/bin/mongocrypt.dll # libmongocrypt's windows dll is not marked executable. chmod +x $PYMONGOCRYPT_LIB - export PYMONGOCRYPT_LIB=$(cygpath -m $PYMONGOCRYPT_LIB) + PYMONGOCRYPT_LIB=$(cygpath -m $PYMONGOCRYPT_LIB) elif [ -f "${BASE}/lib64/libmongocrypt.so" ]; then - export PYMONGOCRYPT_LIB=${BASE}/lib64/libmongocrypt.so + PYMONGOCRYPT_LIB=${BASE}/lib64/libmongocrypt.so else echo "Cannot find libmongocrypt shared object file" exit 1 fi + export PYMONGOCRYPT_LIB # TODO: Test with 'pip install pymongocrypt' git clone --branch master https://github.com/mongodb/libmongocrypt.git libmongocrypt_git @@ -175,7 +176,7 @@ $PYTHON -c 'import sys; print(sys.version)' # Only cover CPython. PyPy reports suspiciously low coverage. PYTHON_IMPL=$($PYTHON -c "import platform; print(platform.python_implementation())") COVERAGE_ARGS="" -if [ -n "$COVERAGE" -a $PYTHON_IMPL = "CPython" ]; then +if [ -n "$COVERAGE" ] && [ "$PYTHON_IMPL" = "CPython" ]; then if $PYTHON -m coverage --version; then echo "INFO: coverage is installed, running tests with coverage..." COVERAGE_ARGS="-m coverage run --branch" @@ -186,7 +187,7 @@ fi $PYTHON setup.py clean if [ -z "$GREEN_FRAMEWORK" ]; then - if [ -z "$C_EXTENSIONS" -a $PYTHON_IMPL = "CPython" ]; then + if [ -z "$C_EXTENSIONS" ] && [ "$PYTHON_IMPL" = "CPython" ]; then # Fail if the C extensions fail to build. # This always sets 0 for exit status, even if the build fails, due diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 39062bbdf..b20ad7ae5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -29,3 +29,12 @@ repos: - id: isort files: \.py$ args: [--profile=black] + +# We use the Python version instead of the original version which seems to require Docker +# https://github.com/koalaman/shellcheck-precommit +- repo: https://github.com/shellcheck-py/shellcheck-py + rev: v0.8.0.1 + hooks: + - id: shellcheck + name: shellcheck + args: ["--severity=warning"] diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 358e7502f..e2956c122 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -8,6 +8,7 @@ version: 2 # Build documentation in the doc/ directory with Sphinx sphinx: configuration: doc/conf.py + fail_on_warning: true # Set the version of Python and requirements required to build the docs. python: diff --git a/doc/conf.py b/doc/conf.py index 47debcf14..3f74a11d6 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -21,6 +21,7 @@ extensions = [ "sphinx.ext.coverage", "sphinx.ext.todo", "sphinx.ext.intersphinx", + "sphinxcontrib.shellcheck", ] # Add any paths that contain templates here, relative to this directory. diff --git a/doc/docs-requirements.txt b/doc/docs-requirements.txt index ce5d1abf3..455a47d21 100644 --- a/doc/docs-requirements.txt +++ b/doc/docs-requirements.txt @@ -1,3 +1,4 @@ Sphinx~=4.2 sphinx_rtd_theme~=0.5 readthedocs-sphinx-search~=0.1 +sphinxcontrib-shellcheck~=1.1 diff --git a/pymongo/collection.py b/pymongo/collection.py index df8db3f10..a61c905d2 100644 --- a/pymongo/collection.py +++ b/pymongo/collection.py @@ -2947,7 +2947,7 @@ class Collection(common.BaseObject, Generic[_DocumentType]): as keyword arguments (for example maxTimeMS can be used with recent server versions). - + .. versionchanged:: 4.1 Added ``let`` parameter. .. versionchanged:: 3.11 Added the ``hint`` option.