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

Always use bash arrays for changed files and directories #4703

Merged
merged 2 commits into from
Nov 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions check/pylint-changed-files
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,17 @@ else
rev="${base}"
fi

changed=$(git diff --name-only ${rev} -- \
typeset -a changed
IFS=$'\n' read -r -d '' -a changed < \
<(git diff --name-only ${rev} -- \
| grep -E "^(cirq|dev_tools|examples).*.py$"
)

num_changed=$(echo -e "${changed[@]}" | wc -w)
num_changed=${#changed[@]}

# Run it.
echo "Found ${num_changed} lintable files associated with changes." >&2
if [ "${num_changed}" -eq 0 ]; then
exit 0
fi
env PYTHONPATH=dev_tools pylint --rcfile=dev_tools/conf/.pylintrc ${changed[@]}

env PYTHONPATH=dev_tools pylint --rcfile=dev_tools/conf/.pylintrc "${changed[@]}"
8 changes: 5 additions & 3 deletions check/pytest-changed-files
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ fi
echo "Comparing against revision '${rev}'." >&2

# Get the _test version of changed python files.
changed=$(git diff --name-only ${rev} -- \
typeset -a changed
IFS=$'\n' read -r -d '' -a changed < \
<(git diff --name-only ${rev} -- \
| grep "\.py$" \
| sed -e "s/\.py$/_test.py/" \
| sed -e "s/_test_test\.py$/_test.py/" \
Expand All @@ -65,7 +67,7 @@ if git diff --name-only "${rev}" -- | grep "__init__\.py$" > /dev/null; then
# Include global API tests when an __init__ file is touched.
changed+=('cirq-core/cirq/protocols/json_serialization_test.py')
fi
num_changed=$(echo -e "${changed[@]}" | wc -w)
num_changed=${#changed[@]}

# Run it.
echo "Found ${num_changed} test files associated with changes." >&2
Expand All @@ -75,4 +77,4 @@ fi

source dev_tools/pypath

pytest ${rest} ${changed[@]}
pytest ${rest} "${changed[@]}"
8 changes: 6 additions & 2 deletions check/pytest-changed-files-and-incremental-coverage
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,19 @@ else
fi

# Find involved files.
cov_changed_python_file_dirs=$(git diff --name-only "${rev}" -- \
typeset -a cov_changed_python_file_dirs
IFS=$'\n' read -r -d '' -a cov_changed_python_file_dirs < \
<(git diff --name-only "${rev}" -- \
| grep "\.py$" \
| grep -v "_pb2\.py$" \
| xargs -I {} dirname {} \
| perl -ne 'chomp(); if (-e $_) {print "--cov=$_\n"}' \
| sort \
| uniq \
)
changed_python_tests=$(git diff --name-only "${rev}" -- \
typeset -a changed_python_tests
IFS=$'\n' read -r -d '' -a changed_python_tests < \
<(git diff --name-only "${rev}" -- \
| grep "\.py$" \
| sed -e "s/\.py$/_test.py/" \
| sed -e "s/_test_test\.py$/_test.py/" \
Expand Down