Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix quoting in shell scripts per shellcheck-0.9 #6245

Merged
merged 1 commit into from Aug 15, 2023

Conversation

pavoljuhas
Copy link
Collaborator

Fix instances of SC2086: Double quote to prevent globbing and word splitting.

Ref: https://www.shellcheck.net/wiki/SC2086

Fix instances of `SC2086: Double quote to prevent globbing and word splitting`.

Ref: https://www.shellcheck.net/wiki/SC2086
@pavoljuhas pavoljuhas requested review from vtomole, cduck and a team as code owners August 15, 2023 21:10
@pavoljuhas pavoljuhas requested a review from maffoo August 15, 2023 21:10
@CirqBot CirqBot added the size: S 10< lines changed <50 label Aug 15, 2023
@pavoljuhas pavoljuhas enabled auto-merge (squash) August 15, 2023 21:12
@codecov
Copy link

codecov bot commented Aug 15, 2023

Codecov Report

Patch coverage: 100.0% and no project coverage change.

Comparison is base (c193c48) 97.3% compared to head (67203e1) 97.3%.
Report is 2 commits behind head on master.

Additional details and impacted files
@@          Coverage Diff           @@
##           master   #6245   +/-   ##
======================================
  Coverage    97.3%   97.3%           
======================================
  Files        1116    1116           
  Lines       96174   96076   -98     
======================================
- Hits        93654   93563   -91     
+ Misses       2520    2513    -7     
Files Changed Coverage Δ
cirq-core/cirq/circuits/circuit_operation_test.py 99.8% <ø> (-0.1%) ⬇️
...ristic_decompositions/two_qubit_gate_tabulation.py 100.0% <ø> (ø)
cirq-google/cirq_google/engine/engine_client.py 100.0% <ø> (ø)
cirq-google/cirq_google/engine/engine_job_test.py 100.0% <ø> (ø)
examples/bernstein_vazirani.py 97.0% <ø> (-0.2%) ⬇️
examples/deutsch.py 96.0% <ø> (-0.6%) ⬇️
examples/shor.py 100.0% <ø> (+4.8%) ⬆️
cirq-google/cirq_google/engine/engine.py 98.1% <100.0%> (-0.1%) ⬇️
...rq-google/cirq_google/engine/engine_client_test.py 100.0% <100.0%> (ø)
cirq-google/cirq_google/engine/engine_job.py 97.4% <100.0%> (+0.3%) ⬆️
... and 2 more

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@pavoljuhas pavoljuhas merged commit 9fbaa05 into quantumlib:master Aug 15, 2023
35 checks passed
@pavoljuhas pavoljuhas deleted the apply-shellcheck-0.9 branch August 15, 2023 21:57
@davidmerwin
Copy link

#!/usr/bin/env bash

Finds changed lines not covered by tests related to changed files.

Usage:

check/pytest-and-incremental-coverage [BASE_REVISION]

Get the working directory to the repo root.

cd "$( dirname "${BASH_SOURCE[0]}" )" || exit 1
cd "$(git rev-parse --show-toplevel)" || exit 1

Determine which revision to compare against.

if [ -n "$1" ] && [[ $1 != -* ]]; then
rev=$1
elif [ "$(git cat-file -t upstream/master 2> /dev/null)" == "commit" ]; then
rev=upstream/master
elif [ "$(git cat-file -t origin/master 2> /dev/null)" == "commit" ]; then
rev=origin/master
elif [ "$(git cat-file -t master 2> /dev/null)" == "commit" ]; then
rev=master
else
echo -e "\033[31mNo default revision found to compare against. Argument #1 must be what to diff against (e.g. 'origin/master' or 'HEAD~1').\033[0m" >&2
exit 1
fi
base="$(git merge-base "${rev}" HEAD)"
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
rev="${base}"
fi

source dev_tools/pypath

Run tests while producing coverage files.

check/pytest --cov
--cov-config=pyproject.toml
pytest_result=$?

Analyze coverage JSON files.

python dev_tools/check_incremental_coverage_json.py "${rev}"
cover_result=$?

Clean up generated coverage JSON report.

git clean --force --quiet -x -- "*.json"

Report result.

if [ "${pytest_result}" -ne "0" ] || [ "${cover_result}" -ne "0" ]; then
exit 1
fi
exit 0

#!/usr/bin/env bash

Finds changed lines not covered by tests related to changed files.

Usage:

check/pytest-and-incremental-coverage [BASE_REVISION]

Get the working directory to the repo root.

cd "$( dirname "${BASH_SOURCE[0]}" )" || exit 1
cd "$(git rev-parse --show-toplevel)" || exit 1

Determine which revision to compare against.

if [ -n "$1" ] && [[ $1 != -* ]]; then
rev=$1
elif [ "$(git cat-file -t upstream/master 2> /dev/null)" == "commit" ]; then
rev=upstream/master
elif [ "$(git cat-file -t origin/master 2> /dev/null)" == "commit" ]; then
rev=origin/master
elif [ "$(git cat-file -t master 2> /dev/null)" == "commit" ]; then
rev=master
else
echo -e "\033[31mNo default revision found to compare against. Argument #1 must be what to diff against (e.g. 'origin/master' or 'HEAD~1').\033[0m" >&2
exit 1
fi
base="$(git merge-base "${rev}" HEAD)"
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
rev="${base}"
fi

source dev_tools/pypath

Run tests while producing coverage files.

check/pytest --cov
--cov-config=pyproject.toml
pytest_result=$?

Analyze coverage JSON files.

python dev_tools/check_incremental_coverage_json.py "${rev}"
cover_result=$?

Clean up generated coverage JSON report.

git clean --force --quiet -x -- "*.json"

Report result.

if [ "${pytest_result}" -ne "0" ] || [ "${cover_result}" -ne "0" ]; then
exit 1
fi
exit 0

#!/usr/bin/env bash

Finds changed lines not covered by tests related to changed files.

Usage:

check/pytest-changed-files-and-incremental-coverage [BASE_REVISION]

Get the working directory to the repo root.

cd "$( dirname "${BASH_SOURCE[0]}" )" || exit 1
cd "$(git rev-parse --show-toplevel)" || exit 1

Initialize variables

PYTEST_ARGS=()
ANALYZE_COV=1
BASEREV=""

Check for base revision and pytest arguments

if [[ "$1" == [^-]* ]]; then
BASEREV="$1"
shift
fi

for arg in "$@"; do
if [[ "${arg}" == "--no-analyze" ]]; then
ANALYZE_COV=0
else
PYTEST_ARGS+=("${arg}")
fi
done

Determine which revision to compare against.

if [ -n "${BASEREV}" ]; then
rev="${BASEREV}"
elif [ "$(git cat-file -t upstream/master 2> /dev/null)" == "commit" ]; then
rev=upstream/master
elif [ "$(git cat-file -t origin/master 2> /dev/null)" == "commit" ]; then
rev=origin/master
elif [ "$(git cat-file -t master 2> /dev/null)" == "commit" ]; then
rev=master
else
echo -e "\033[31mNo default revision found to compare against.\033[0m" >&2
exit 1
fi
base="$(git merge-base "${rev}" HEAD)"
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
rev="${base}"
fi

source dev_tools/pypath

Run tests while producing coverage files using pytest and coverage configurations.

check/pytest --cov
--cov-config=pyproject.toml
"${PYTEST_ARGS[@]}"
pytest_result=$?

Assume successful cover_result in case coverage is not run.

cover_result=0
if (( ANALYZE_COV )); then
# Convert coverage data to JSON report.
coverage json

# Analyze coverage JSON report using a custom script.
python dev_tools/check_incremental_coverage_json.py "${rev}"
cover_result=$?

# Clean up generated coverage JSON report.
git clean --force --quiet -x -- "*.json"

fi

Report the final result.

if (( pytest_result || cover_result )); then
exit 1
fi
exit 0

[tool.black]
line-length = 100
target_version = ['py39', 'py310', 'py311']
skip-string-normalization = true
skip-magic-trailing-comma = true

[tool.pytest.ini_options]
filterwarnings = [
"ignore:Matplotlib is currently using agg:UserWarning",
]

[tool.coverage.run]

Omit files outside the current working directory.

Note: this means coverage must be run from the cirq repo root.

Failure to do so will result in false positives.

include = "./"
omit = [
"benchmarks/
",
# additional paths to omit
]

@pavoljuhas @CirqBot

@pavoljuhas
Copy link
Collaborator Author

@davidmerwin - can you please clarify your comment above?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: S 10< lines changed <50
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants