Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools: regularize pip/venv for format_python_tools.py. #8176

Merged
merged 2 commits into from
Sep 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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" $*
}