diff --git a/check/all b/check/all index 57fffe8223d..e8367e8dcb8 100755 --- a/check/all +++ b/check/all @@ -47,7 +47,7 @@ for arg in "$@"; do elif [[ "${arg}" == "--apply-format-changes" ]]; then apply_arg=( "--apply" ) elif [[ "${#rev[@]}" == 0 ]]; then - if [ "$(git cat-file -t "${arg}" 2> /dev/null)" != "commit" ]; then + if [[ "$(git cat-file -t "${arg}" 2> /dev/null)" != "commit" ]]; then echo -e "\033[31mNo revision '${arg}'.\033[0m" >&2 exit 1 fi @@ -61,7 +61,7 @@ done echo "Running misc" check/misc || errors+=( "check/misc failed" ) -if [ ${only_changed} -ne 0 ]; then +if [[ ${only_changed} -ne 0 ]]; then echo "Running incremental pylint" check/pylint-changed-files || errors+=( "check/pylint-changed-files failed" ) else @@ -76,7 +76,7 @@ echo "Running incremental format" check/format-incremental "${rev[@]}" "${apply_arg[@]}" || errors+=( "check/format-incremental failed" ) -if [ ${only_changed} -ne 0 ]; then +if [[ ${only_changed} -ne 0 ]]; then echo "Running pytest and incremental coverage on changed files" check/pytest-changed-files-and-incremental-coverage "${rev[@]}" || errors+=( "check/pytest-changed-files-and-incremental-coverage failed" ) diff --git a/check/format-incremental b/check/format-incremental index d30d7c0c307..a44e98744c4 100755 --- a/check/format-incremental +++ b/check/format-incremental @@ -44,7 +44,7 @@ for arg in "$@"; do only_print=0 elif [[ "${arg}" == "--all" ]]; then only_changed=0 - elif [ -z "${rev}" ]; then + elif [[ -z "${rev}" ]]; then if ! git rev-parse --verify --quiet --no-revs "${arg}^{commit}"; then echo -e "\033[31mNo revision '${arg}'.\033[0m" >&2 exit 1 @@ -59,12 +59,12 @@ done declare -a format_files if (( only_changed == 1 )); then # Figure out which branch to compare against. - if [ -z "${rev}" ]; then - if [ "$(git cat-file -t upstream/main 2> /dev/null)" == "commit" ]; then + if [[ -z "${rev}" ]]; then + if [[ "$(git cat-file -t upstream/main 2> /dev/null)" == "commit" ]]; then rev=upstream/main - elif [ "$(git cat-file -t origin/main 2> /dev/null)" == "commit" ]; then + elif [[ "$(git cat-file -t origin/main 2> /dev/null)" == "commit" ]]; then rev=origin/main - elif [ "$(git cat-file -t main 2> /dev/null)" == "commit" ]; then + elif [[ "$(git cat-file -t main 2> /dev/null)" == "commit" ]]; then rev=main else echo -e "\033[31mNo default revision found to compare against. Argument #1 must be what to diff against (e.g. 'origin/main' or 'HEAD~1').\033[0m" >&2 @@ -72,7 +72,7 @@ if (( only_changed == 1 )); then fi fi base="$(git merge-base "${rev}" HEAD)" - if [ "$(git rev-parse "${rev}")" == "${base}" ]; then + if [[ "$(git rev-parse "${rev}")" == "${base}" ]]; then echo -e "Comparing against revision '${rev}'." >&2 else echo -e "Comparing against revision '${rev}' (merge base ${base})." >&2 diff --git a/check/misc b/check/misc index 1ad4aa33378..41baaeda1f3 100755 --- a/check/misc +++ b/check/misc @@ -15,7 +15,7 @@ cd "${topdir}" || exit $? # Check for non-contrib references to contrib. results=$(grep -Rl "\bcirq\.contrib\b" cirq-core | grep -v "cirq/contrib" | grep -v "__") RESULT=$? -if [ $RESULT -eq 0 ]; then +if [[ $RESULT -eq 0 ]]; then echo -e "\033[31m'cirq.contrib' mentioned in non-contrib files:\033[0m" echo "${results}" echo diff --git a/check/pylint-changed-files b/check/pylint-changed-files index c88b7bcedf2..ae143beb959 100755 --- a/check/pylint-changed-files +++ b/check/pylint-changed-files @@ -30,17 +30,17 @@ topdir="$(git -C "${thisdir}" rev-parse --show-toplevel)" || exit $? cd "${topdir}" || exit $? # Figure out which revision to compare against. -if [ -n "$1" ] && [[ $1 != -* ]]; then +if [[ -n "$1" && $1 != -* ]]; then if ! git rev-parse --verify --quiet --no-revs "$1^{commit}"; then echo -e "\033[31mNo revision '$1'.\033[0m" >&2 exit 1 fi rev=$1 -elif [ "$(git cat-file -t upstream/main 2> /dev/null)" == "commit" ]; then +elif [[ "$(git cat-file -t upstream/main 2> /dev/null)" == "commit" ]]; then rev=upstream/main -elif [ "$(git cat-file -t origin/main 2> /dev/null)" == "commit" ]; then +elif [[ "$(git cat-file -t origin/main 2> /dev/null)" == "commit" ]]; then rev=origin/main -elif [ "$(git cat-file -t main 2> /dev/null)" == "commit" ]; then +elif [[ "$(git cat-file -t main 2> /dev/null)" == "commit" ]]; then rev=main else echo -e "\033[31mNo default revision found to compare against. Argument #1 must be what to diff against (e.g. 'origin/main' or 'HEAD~1').\033[0m" >&2 @@ -65,7 +65,7 @@ declare -i num_changed=${#changed[@]} # Run it. echo "Found ${num_changed} lintable files associated with changes." >&2 -if [ "${num_changed}" -eq 0 ]; then +if [[ "${num_changed}" -eq 0 ]]; then exit 0 fi env PYTHONPATH=dev_tools pylint --jobs=0 --rcfile=dev_tools/conf/.pylintrc "${changed[@]}" diff --git a/check/pytest b/check/pytest index d77a28e4fc1..c4836b85c02 100755 --- a/check/pytest +++ b/check/pytest @@ -25,7 +25,7 @@ source dev_tools/pypath || exit $? pytest "${PYTEST_ARGS[@]}" declare -i RESULT=$? -if [ "$RESULT" = 5 ]; then +if [[ "$RESULT" = 5 ]]; then echo "[exit 5] No tests collected, but ignored." exit 0 fi diff --git a/check/pytest-and-incremental-coverage b/check/pytest-and-incremental-coverage index cb348051cc5..18edcea3250 100755 --- a/check/pytest-and-incremental-coverage +++ b/check/pytest-and-incremental-coverage @@ -45,17 +45,17 @@ done # Figure out which revision to compare against. declare rev="" -if [ -n "${baserev}" ]; then +if [[ -n "${baserev}" ]]; then if ! git rev-parse --verify --quiet --no-revs "${baserev}^{commit}"; then echo -e "\033[31mNo revision '${baserev}'.\033[0m" >&2 exit 1 fi rev="${baserev}" -elif [ "$(git cat-file -t upstream/main 2> /dev/null)" == "commit" ]; then +elif [[ "$(git cat-file -t upstream/main 2> /dev/null)" == "commit" ]]; then rev=upstream/main -elif [ "$(git cat-file -t origin/main 2> /dev/null)" == "commit" ]; then +elif [[ "$(git cat-file -t origin/main 2> /dev/null)" == "commit" ]]; then rev=origin/main -elif [ "$(git cat-file -t main 2> /dev/null)" == "commit" ]; then +elif [[ "$(git cat-file -t main 2> /dev/null)" == "commit" ]]; then rev=main else echo -e "\033[31mNo default revision found to compare against. Argument #1 must be what to diff against (e.g. 'origin/main' or 'HEAD~1').\033[0m" >&2 diff --git a/check/pytest-changed-files b/check/pytest-changed-files index bf289b83f4e..7a31e7160ed 100755 --- a/check/pytest-changed-files +++ b/check/pytest-changed-files @@ -35,18 +35,18 @@ cd "${topdir}" || exit $? # Figure out which branch to compare against. declare -a rest=( "$@" ) declare rev="" -if [ -n "$1" ] && [[ $1 != -* ]]; then +if [[ -n "$1" && $1 != -* ]]; then if ! git rev-parse --verify --quiet --no-revs "$1^{commit}"; then echo -e "\033[31mNo revision '$1'.\033[0m" >&2 exit 1 fi rev=$1 rest=( "${@:2}" ) -elif [ "$(git cat-file -t upstream/main 2> /dev/null)" == "commit" ]; then +elif [[ "$(git cat-file -t upstream/main 2> /dev/null)" == "commit" ]]; then rev=upstream/main -elif [ "$(git cat-file -t origin/main 2> /dev/null)" == "commit" ]; then +elif [[ "$(git cat-file -t origin/main 2> /dev/null)" == "commit" ]]; then rev=origin/main -elif [ "$(git cat-file -t main 2> /dev/null)" == "commit" ]; then +elif [[ "$(git cat-file -t main 2> /dev/null)" == "commit" ]]; then rev=main else echo -e "\033[31mNo default revision found to compare against. Argument #1 must be what to diff against (e.g. 'origin/main' or 'HEAD~1').\033[0m" >&2 @@ -73,7 +73,7 @@ declare -i num_changed=${#changed[@]} # Run it. echo "Found ${num_changed} test files associated with changes." >&2 -if [ "${num_changed}" -eq 0 ]; then +if [[ "${num_changed}" -eq 0 ]]; then exit 0 fi diff --git a/check/pytest-changed-files-and-incremental-coverage b/check/pytest-changed-files-and-incremental-coverage index eb9a2ef8aaf..6e4a74d12ea 100755 --- a/check/pytest-changed-files-and-incremental-coverage +++ b/check/pytest-changed-files-and-incremental-coverage @@ -34,17 +34,17 @@ cd "$(git rev-parse --show-toplevel)" || exit 1 # Figure out which revision to compare against. declare rev="" -if [ -n "$1" ] && [[ $1 != -* ]]; then +if [[ -n "$1" && $1 != -* ]]; then if ! git rev-parse --verify --quiet --no-revs "$1^{commit}"; then echo -e "\033[31mNo revision '$1'.\033[0m" >&2 exit 1 fi rev=$1 -elif [ "$(git cat-file -t upstream/main 2> /dev/null)" == "commit" ]; then +elif [[ "$(git cat-file -t upstream/main 2> /dev/null)" == "commit" ]]; then rev=upstream/main -elif [ "$(git cat-file -t origin/main 2> /dev/null)" == "commit" ]; then +elif [[ "$(git cat-file -t origin/main 2> /dev/null)" == "commit" ]]; then rev=origin/main -elif [ "$(git cat-file -t main 2> /dev/null)" == "commit" ]; then +elif [[ "$(git cat-file -t main 2> /dev/null)" == "commit" ]]; then rev=main else echo -e "\033[31mNo default revision found to compare against. Argument #1 must be what to diff against (e.g. 'origin/main' or 'HEAD~1').\033[0m" >&2 @@ -84,7 +84,7 @@ if git diff --name-only "${rev}" -- | grep "__init__\.py$" > /dev/null; then # Include global API tests when an __init__ file is touched. changed_python_tests+=('cirq-core/cirq/protocols/json_serialization_test.py') fi -if [ "${#changed_python_tests[@]}" -eq 0 ]; then +if [[ "${#changed_python_tests[@]}" -eq 0 ]]; then echo -e "\033[33mNo changed files with associated python tests.\033[0m" >&2 exit 0 fi diff --git a/dev_tools/packaging/produce-package.sh b/dev_tools/packaging/produce-package.sh index 35e4f5927b6..e6b09d03d13 100755 --- a/dev_tools/packaging/produce-package.sh +++ b/dev_tools/packaging/produce-package.sh @@ -28,7 +28,7 @@ set -e trap "{ echo -e '\033[31mFAILED\033[0m'; }" ERR -if [ -z "${1}" ]; then +if [[ -z "${1}" ]]; then echo -e "\033[31mNo output directory given.\033[0m" exit 1 fi @@ -49,7 +49,7 @@ repo_dir=$(git rev-parse --show-toplevel) cd "${repo_dir}" # Make a clean copy of HEAD, without files ignored by git (but potentially kept by setup.py). -if [ -n "$(git status --short)" ]; then +if [[ -n "$(git status --short)" ]]; then echo -e "\033[31mWARNING: You have uncommitted changes. They won't be included in the package.\033[0m" fi tmp_git_dir=$(mktemp -d "/tmp/produce-package-git.XXXXXXXXXXXXXXXX") @@ -57,7 +57,7 @@ trap '{ rm -rf "${tmp_git_dir}"; }' EXIT echo "Creating pristine repository clone at ${tmp_git_dir}" git clone --shared --quiet "${repo_dir}" "${tmp_git_dir}" cd "${tmp_git_dir}" -if [ -n "${SPECIFIED_VERSION}" ]; then +if [[ -n "${SPECIFIED_VERSION}" ]]; then CURRENT_VERSION=$(set -e; my_dev_tools_modules print_version) my_dev_tools_modules replace_version --old="${CURRENT_VERSION}" --new="${SPECIFIED_VERSION}" fi diff --git a/dev_tools/packaging/publish-dev-package.sh b/dev_tools/packaging/publish-dev-package.sh index 2a478abb27b..21ea508da8e 100755 --- a/dev_tools/packaging/publish-dev-package.sh +++ b/dev_tools/packaging/publish-dev-package.sh @@ -54,7 +54,7 @@ trap "{ echo -e '\033[31mFAILED\033[0m'; }" ERR EXPECTED_VERSION=$1 PROD_SWITCH=$2 -if [ -z "${EXPECTED_VERSION}" ]; then +if [[ -z "${EXPECTED_VERSION}" ]]; then echo -e "\033[31mFirst argument must be the expected version.\033[0m" exit 1 fi @@ -63,34 +63,34 @@ if [[ "${EXPECTED_VERSION}" != *dev* ]]; then exit 1 fi ACTUAL_VERSION_LINE=$(tail -n 1 "${PROJECT_NAME}/_version.py") -if [ "${ACTUAL_VERSION_LINE}" != '__version__ = "'"${EXPECTED_VERSION}"'"' ]; then +if [[ "${ACTUAL_VERSION_LINE}" != '__version__ = "'"${EXPECTED_VERSION}"'"' ]]; then echo -e "\033[31mExpected version (${EXPECTED_VERSION}) didn't match the one in ${PROJECT_NAME}/_version.py (${ACTUAL_VERSION_LINE}).\033[0m" exit 1 fi -if [ -z "${PROD_SWITCH}" ] || [ "${PROD_SWITCH}" = "--test" ]; then +if [[ -z "${PROD_SWITCH}" || "${PROD_SWITCH}" = "--test" ]]; then PYPI_REPOSITORY_FLAG=( "--repository-url=https://test.pypi.org/legacy/" ) PYPI_REPO_NAME="TEST" USERNAME="${TEST_TWINE_USERNAME}" PASSWORD="${TEST_TWINE_PASSWORD}" - if [ -z "${USERNAME}" ]; then + if [[ -z "${USERNAME}" ]]; then echo -e "\033[31mTEST_TWINE_USERNAME environment variable must be set.\033[0m" exit 1 fi - if [ -z "${PASSWORD}" ]; then + if [[ -z "${PASSWORD}" ]]; then echo -e "\033[31mTEST_TWINE_PASSWORD environment variable must be set.\033[0m" exit 1 fi -elif [ "${PROD_SWITCH}" = "--prod" ]; then +elif [[ "${PROD_SWITCH}" = "--prod" ]]; then PYPI_REPOSITORY_FLAG=( ) PYPI_REPO_NAME="PROD" USERNAME="${PROD_TWINE_USERNAME}" PASSWORD="${PROD_TWINE_PASSWORD}" - if [ -z "${USERNAME}" ]; then + if [[ -z "${USERNAME}" ]]; then echo -e "\033[31mPROD_TWINE_USERNAME environment variable must be set.\033[0m" exit 1 fi - if [ -z "${PASSWORD}" ]; then + if [[ -z "${PASSWORD}" ]]; then echo -e "\033[31mPROD_TWINE_PASSWORD environment variable must be set.\033[0m" exit 1 fi diff --git a/dev_tools/packaging/verify-published-package.sh b/dev_tools/packaging/verify-published-package.sh index db3f9b3b31d..694b273a602 100755 --- a/dev_tools/packaging/verify-published-package.sh +++ b/dev_tools/packaging/verify-published-package.sh @@ -37,18 +37,18 @@ PROJECT_NAME=cirq PROJECT_VERSION=$1 PROD_SWITCH=$2 -if [ -z "${PROJECT_VERSION}" ]; then +if [[ -z "${PROJECT_VERSION}" ]]; then echo -e "\033[31mFirst argument must be the package version to test.\033[0m" exit 1 fi declare -a PIP_FLAGS -if [ "${PROD_SWITCH}" = "--test" ]; then +if [[ "${PROD_SWITCH}" = "--test" ]]; then PIP_FLAGS=("--index-url=https://test.pypi.org/simple/") PYPI_REPO_NAME="TEST" PYPI_PROJECT_NAME="cirq" -elif [ "${PROD_SWITCH}" = "--prod" ]; then +elif [[ "${PROD_SWITCH}" = "--prod" ]]; then PIP_FLAGS=() PYPI_REPO_NAME="PROD" PYPI_PROJECT_NAME="cirq" @@ -67,7 +67,7 @@ cd "${tmp_dir}" trap '{ rm -rf "${tmp_dir}"; }' EXIT # Test installation from published package -PYTHON_VERSION=python3 + PYTHON_VERSION=python3 # Prepare. CONTRIB_DEPS_FILE="${REPO_ROOT}/cirq-core/cirq/contrib/requirements.txt"