Skip to content

Commit

Permalink
tools: regularize pip/venv for format_python_tools.py. (envoyproxy#8176)
Browse files Browse the repository at this point in the history
As well as being a nice cleanup, this fixes some issues I had with local
Docker use of fix_format as a non-root user.

Signed-off-by: Harvey Tuch <[email protected]>
  • Loading branch information
htuch authored and danzh1989 committed Sep 24, 2019
1 parent d1b64c4 commit 6a72233
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
2 changes: 1 addition & 1 deletion tools/format_python_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def validateFormat(fix=False):
successful_update_files = set()
for python_file in collectFiles():
reformatted_source, encoding, changed = FormatFile(python_file,
style_config='.style.yapf',
style_config='tools/.style.yapf',
in_place=fix,
print_diff=not fix)
if not fix:
Expand Down
14 changes: 3 additions & 11 deletions tools/format_python_tools.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
#!/bin/bash

set -e

VENV_DIR="pyformat"
SCRIPTPATH=$(realpath "$(dirname $0)")
. $SCRIPTPATH/shell_utils.sh
cd "$SCRIPTPATH"
. tools/shell_utils.sh

source_venv "$VENV_DIR"
echo "Installing requirements..."
pip3 -q install --upgrade pip
pip3 -q install -r requirements.txt
set -e

echo "Running Python format check..."
python3 format_python_tools.py $1
python_venv format_python_tools $1

echo "Running Python3 flake8 check..."
python3 -m flake8 --version
Expand Down
10 changes: 6 additions & 4 deletions tools/shell_utils.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source_venv() {
VENV_DIR=$1
if [[ "$VIRTUAL_ENV" == "" ]]; then
if [[ "${VIRTUAL_ENV}" == "" ]]; then
if [[ ! -d "${VENV_DIR}"/venv ]]; then
virtualenv "${VENV_DIR}"/venv --no-site-packages --python=python3
fi
Expand All @@ -14,10 +14,12 @@ python_venv() {
SCRIPT_DIR=$(realpath "$(dirname "$0")")

BUILD_DIR=build_tools
VENV_DIR="$BUILD_DIR/$1"
PY_NAME="$1"
VENV_DIR="${BUILD_DIR}/${PY_NAME}"

source_venv "$VENV_DIR"
source_venv "${VENV_DIR}"
pip install -r "${SCRIPT_DIR}"/requirements.txt

python3 "${SCRIPT_DIR}/$1.py" $*
shift
python3 "${SCRIPT_DIR}/${PY_NAME}.py" $*
}

0 comments on commit 6a72233

Please sign in to comment.