Skip to content

Conversation

mhucka
Copy link
Contributor

@mhucka mhucka commented Sep 26, 2025

This is adapted from, but heavily modified from, Cirq's check/all.

This is adapted from, but heavily modified from, Cirq's check/all.
@mhucka mhucka marked this pull request as ready for review September 26, 2025 20:40
Copy link
Contributor

@pavoljuhas pavoljuhas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the unplugged --no-coverage from the usage doc. Also see inline comments for more suggestions.

Comment on lines +29 to +30
If the option --no-coverage is specified, check/pytest will be run instead of
check/pytest-and-incremental-coverage.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fail to see any code for --no-coverage. Either remove this paragraph or handle the option in the script. Since passing coverage is required by the CI, it seems better to just change the text and keep running pytest-and-incremental-coverage unconditionally.

Comment on lines +45 to +47
thisdir=$(dirname "${BASH_SOURCE[0]:?}") || exit $?
repo_dir=$(git -C "${thisdir}" rev-parse --show-toplevel) || exit $?
cd "${repo_dir}" || exit $?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit - remove || exit $? because it is implied by the errexit (-e) option on line 41.

Comment on lines +55 to +57
declare rev
declare apply_arg
declare only_changed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit - it is safer to set initial value, e.g., declare rev="", otherwise the rev value could be picked from the rev environment variable. Also, as rev and apply_arg are optional for format-incremental, it is better to declare them as arrays which may be empty (and would not trigger shellcheck):

declare -a rev=()
declare -a apply_arg=()

Comment on lines +73 to +77
if [[ -n "${rev}" ]]; then
error "Invalid arguments."
echo "${usage}"
exit 1
fi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This silently skips --no-coverage option or any other unknown option if there is no rev argument. How about

Suggested change
if [[ -n "${rev}" ]]; then
error "Invalid arguments."
echo "${usage}"
exit 1
fi
error "Invalid option '${arg}'"
error "See '$0 --help' for the list of supported options."
exit 1

Comment on lines +80 to +84
if [ "$(git cat-file -t "${arg}" 2> /dev/null)" != "commit" ]; then
error "No revision '${arg}'"
exit 1
fi
rev="${arg}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will reject annotated tag wrapping a commit, because its type is "tag" (this is an issue in Cirq too). Here is a better way:

Suggested change
if [ "$(git cat-file -t "${arg}" 2> /dev/null)" != "commit" ]; then
error "No revision '${arg}'"
exit 1
fi
rev="${arg}"
if ! rev=( "$(git rev-parse --verify --end-of-options "${arg}^{commit}")" ); then
error "No revision '${arg}'"
exit 1
fi

Comment on lines +91 to +92
declare -a errors
declare program
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bash seems to initialize errors[0] from the environment. The program is not used on global scope.

Suggested change
declare -a errors
declare program
declare -a errors=()

Comment on lines +95 to +98
local -r program="$1"
echo "Running $program ..."
$program || errors+=( "${program} failed" )
echo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing the entire command line as one argument (e.g., line 102) is fragile, in case any of desired arguments contain space or a glob-like character which would get expanded. It is safer to pass the command line arguments exactly:

Suggested change
local -r program="$1"
echo "Running $program ..."
$program || errors+=( "${program} failed" )
echo
echo "Running $* ..."
"$@" || errors+=( "$* failed" )
echo

Comment on lines +102 to +103
run "check/format-incremental ${rev} ${apply_arg}"
run "check/pylint-changed-files ${rev}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With rev and apply_arg declared as arrays, we can pass arguments to the run function exactly (similar change needed on lines 105, 109 below):

Suggested change
run "check/format-incremental ${rev} ${apply_arg}"
run "check/pylint-changed-files ${rev}"
run check/format-incremental "${rev[@]}" "${apply_arg[@]}"
run check/pylint-changed-files "${rev[@]}"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants