blob: d1b823d948ca8fedfa0e2be4a9b530c5a1d0884b [file] [log] [blame]
#!/bin/bash
# Copyright 2022 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# Formats the Honeydew code as per coding guidelines
LACEWING_SRC="$FUCHSIA_DIR/src/testing/end_to_end"
HONEYDEW_SRC="$LACEWING_SRC/honeydew"
VENV_ROOT_PATH="$LACEWING_SRC/.venvs"
VENV_NAME="fuchsia_python_venv"
VENV_PATH="$VENV_ROOT_PATH/$VENV_NAME"
if [ -d $VENV_PATH ]
then
echo "Activating the virtual environment..."
source $VENV_PATH/bin/activate
else
echo
echo "ERROR: Directory '$VENV_PATH' does not exists. Run the 'install.sh' script first..."
echo
exit 1
fi
cd $FUCHSIA_DIR
echo "Formatting the code..."
# Format the code (using black, isort and autoflake)
fx format-code
echo "Running static type check using 'mypy'..."
OLD_PYTHONPATH=$PYTHONPATH
PYTHONPATH="$FUCHSIA_DIR"/third_party/pylibs/mypy_extensions/src:"$FUCHSIA_DIR"/third_party/pylibs/typing_extensions/src/src:"$FUCHSIA_DIR"/third_party/pylibs/mypy/src:$PYTHONPATH
# Execute the Mypy command with python path
MYPY_CMD="python3 -S -m mypy --config-file $FUCHSIA_DIR/pyproject.toml $HONEYDEW_SRC"
$MYPY_CMD >/dev/null 2>&1
if [ $? -eq 0 ]; then
echo "Code is 'mypy' compliant"
else
echo
echo "ERROR: Code is not 'mypy' compliant!"
echo "ERROR: Please run below command sequence, fix all the issues and then rerun this script"
echo "*************************************"
echo "$ source $VENV_PATH/bin/activate"
echo "$ PYTHONPATH=$PYTHONPATH $MYPY_CMD"
echo "*************************************"
echo
exit 1
fi
echo "Restoring environment..."
PYTHONPATH=$OLD_PYTHONPATH
echo "Running static code analysis using 'pylint'..."
pylint --rcfile=$HONEYDEW_SRC/linter/pylintrc $HONEYDEW_SRC/honeydew/ > /dev/null 2>&1 \
&& \
pylint --rcfile=$HONEYDEW_SRC/linter/pylintrc $HONEYDEW_SRC/tests/ > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "Code is 'pylint' compliant"
else
echo
echo "ERROR: Code is not 'pylint' compliant!"
echo "ERROR: Please run below command sequence, fix all the issues and then rerun this script"
echo "*************************************"
echo "$ source $VENV_PATH/bin/activate"
echo "$ pylint --rcfile=$HONEYDEW_SRC/linter/pylintrc $HONEYDEW_SRC/honeydew/"
echo "$ pylint --rcfile=$HONEYDEW_SRC/linter/pylintrc $HONEYDEW_SRC/tests/"
echo "*************************************"
echo
exit 1
fi
echo "Successfully completed all of the formatting checks"