From e245ca8c69b489c3085ebaf5546c41ba40e1946a Mon Sep 17 00:00:00 2001 From: Cleber Rosa Date: Wed, 11 Sep 2024 09:45:15 -0400 Subject: [PATCH] Tool name and command standardization 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: https://github.com/avocado-framework/avocado/commit/77ca585f776dba3d07df81eb41d51828249d54a9 Signed-off-by: Cleber Rosa --- check-import-order | 9 ++++----- check-lint | 15 ++++++++------- check-style | 9 ++++----- utils/which | 22 ---------------------- 4 files changed, 16 insertions(+), 39 deletions(-) delete mode 100755 utils/which diff --git a/check-import-order b/check-import-order index 2998952..5c379cf 100755 --- a/check-import-order +++ b/check-import-order @@ -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 . +echo "** Running $TOOL_NAME..." +$TOOL_CMD --check-only --profile black . diff --git a/check-lint b/check-lint index c08d3e2..969dab7 100755 --- a/check-lint +++ b/check-lint @@ -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" @@ -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 @@ -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 @@ -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 diff --git a/check-style b/check-style index 852a89a..b9ca72e 100755 --- a/check-style +++ b/check-style @@ -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 . diff --git a/utils/which b/utils/which deleted file mode 100755 index 7132b4c..0000000 --- a/utils/which +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env python3 -import os -import shutil -import sys - - -def print_usage(): - print(f"Usage: {sys.argv[0]} [--] COMMAND") - -def main(): - if len(sys.argv) < 2: - print_usage() - return -1 - result = shutil.which(sys.argv[1]) - if result is None: - print(f"{os.path.abspath(sys.argv[0])}: no {sys.argv[1]} in {os.environ['PATH']}") - return -1 - print(result) - return 0 - -if __name__ == '__main__': - sys.exit(main())