Skip to content

Commit

Permalink
Tool name and command standardization
Browse files Browse the repository at this point in the history
We've been using the tool name and the actual command in different
ways among the different check scripts.  This standardizes them to use
the same style, and the same behavior.

While it would make sense to call the tools by their names because
that would be applicable to any tool (be it Python based on or) there
are situations on too many platforms where, given the installation of
the tool using PIP, the scripts are not readily available on the PATH.

Even worse, is that different versions may be picked up from outside a
virtual environment, like from system packages.  This change
standardizes on using the Python module entrypoint for the tools
written Python, which will get the right tool if inside a virtual
environment becase "python3" will be already set to the active one.
A similar change was done for "selftests/style.sh" on Avocado itself.

This standardizes the following:

 * TOOL_NAME is the descriptive name that is given to humans
 * TOOL_CMD is the actual command that will be called

Reference: avocado-framework/avocado@77ca585
Signed-off-by: Cleber Rosa <[email protected]>
  • Loading branch information
clebergnu committed Sep 11, 2024
1 parent a7f8a7f commit 1b1753e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 38 deletions.
7 changes: 3 additions & 4 deletions check-import-order
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/bin/sh -e

TOOL_CMD=isort
PATH=$(basename $0)/utils:$PATH
TOOL_PATH=$(which $TOOL_CMD)
TOOL_NAME=isort
TOOL_CMD="python3 -m $TOOL_NAME"

echo "** Running $TOOL_CMD ($TOOL_PATH)..."
$TOOL_PATH --check-only --profile black .
$TOOL_CMD --check-only --profile black .
15 changes: 8 additions & 7 deletions check-lint
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/sh -e

TOOL_CMD=pylint
TOOL_NAME=pylint
TOOL_CMD="python3 -m $TOOL_NAME"
BASE_DIR=$(dirname "$0")
CONFIG_FILE="$BASE_DIR/../avocado-static-checks.conf"

Expand Down Expand Up @@ -70,8 +71,8 @@ if [ -f "$CONFIG_FILE" ]; then
FILES=$(git ls-files "$DIRECTORY_PATH/*.py")

if [ -n "$FILES" ]; then
echo "** Running $TOOL_CMD on directory '$DIRECTORY_PATH' with config from '$CONFIG_PATH'..."
python3 -m pylint --rcfile="$BASE_DIR/../$CONFIG_PATH" $FILES
echo "** Running $TOOL_NAME on directory '$DIRECTORY_PATH' with config from '$CONFIG_PATH'..."
$TOOL_CMD --rcfile="$BASE_DIR/../$CONFIG_PATH" $FILES

# Add the files to the custom config list
for file in $FILES; do
Expand All @@ -82,8 +83,8 @@ if [ -f "$CONFIG_FILE" ]; then
done < "$CONFIG_FILE"
else
# If the configuration file does not exist, print a message and use default config for all files
echo "Configuration file '$CONFIG_FILE' not found. Running $TOOL_CMD with default config on all files..."
python3 -m pylint --rcfile="$DEFAULT_CONFIG_PATH" $ALL_FILES
echo "Configuration file '$CONFIG_FILE' not found. Running $TOOL_NAME with default config on all files..."
$TOOL_CMD --rcfile="$DEFAULT_CONFIG_PATH" $ALL_FILES
exit 0
fi

Expand All @@ -97,6 +98,6 @@ for file in $ALL_FILES; do
done

if [ ${#remaining_files[@]} -gt 0 ]; then
echo "** Running $TOOL_CMD with default config on remaining files..."
python3 -m pylint --rcfile="$DEFAULT_CONFIG_PATH" "${remaining_files[@]}"
echo "** Running $TOOL_NAME with default config on remaining files..."
$TOOL_CMD --rcfile="$DEFAULT_CONFIG_PATH" "${remaining_files[@]}"
fi
9 changes: 4 additions & 5 deletions check-style
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/bin/sh -e

TOOL_CMD=black
PATH=$(basename $0)/utils:$PATH
TOOL_PATH=$(which $TOOL_CMD)
TOOL_NAME=black
TOOL_CMD="python3 -m black"

echo "** Running $TOOL_CMD ($TOOL_PATH)..."
$TOOL_PATH --check --diff --color .
echo "** Running $TOOL_NAME..."
$TOOL_CMD --check --diff --color .
22 changes: 0 additions & 22 deletions utils/which

This file was deleted.

0 comments on commit 1b1753e

Please sign in to comment.