Skip to content

Commit d0e1db6

Browse files
htuchmattklein123
authored andcommitted
tools: regularize pip/venv for format_python_tools.py. (#8176)
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]>
1 parent 73ad41a commit d0e1db6

File tree

3 files changed

+10
-16
lines changed

3 files changed

+10
-16
lines changed

tools/format_python_tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def validateFormat(fix=False):
3939
successful_update_files = set()
4040
for python_file in collectFiles():
4141
reformatted_source, encoding, changed = FormatFile(python_file,
42-
style_config='.style.yapf',
42+
style_config='tools/.style.yapf',
4343
in_place=fix,
4444
print_diff=not fix)
4545
if not fix:

tools/format_python_tools.sh

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
11
#!/bin/bash
22

3-
set -e
4-
5-
VENV_DIR="pyformat"
6-
SCRIPTPATH=$(realpath "$(dirname $0)")
7-
. $SCRIPTPATH/shell_utils.sh
8-
cd "$SCRIPTPATH"
3+
. tools/shell_utils.sh
94

10-
source_venv "$VENV_DIR"
11-
echo "Installing requirements..."
12-
pip3 -q install --upgrade pip
13-
pip3 -q install -r requirements.txt
5+
set -e
146

157
echo "Running Python format check..."
16-
python3 format_python_tools.py $1
8+
python_venv format_python_tools $1
179

1810
echo "Running Python3 flake8 check..."
1911
python3 -m flake8 --version

tools/shell_utils.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
source_venv() {
22
VENV_DIR=$1
3-
if [[ "$VIRTUAL_ENV" == "" ]]; then
3+
if [[ "${VIRTUAL_ENV}" == "" ]]; then
44
if [[ ! -d "${VENV_DIR}"/venv ]]; then
55
virtualenv "${VENV_DIR}"/venv --no-site-packages --python=python3
66
fi
@@ -14,10 +14,12 @@ python_venv() {
1414
SCRIPT_DIR=$(realpath "$(dirname "$0")")
1515

1616
BUILD_DIR=build_tools
17-
VENV_DIR="$BUILD_DIR/$1"
17+
PY_NAME="$1"
18+
VENV_DIR="${BUILD_DIR}/${PY_NAME}"
1819

19-
source_venv "$VENV_DIR"
20+
source_venv "${VENV_DIR}"
2021
pip install -r "${SCRIPT_DIR}"/requirements.txt
2122

22-
python3 "${SCRIPT_DIR}/$1.py" $*
23+
shift
24+
python3 "${SCRIPT_DIR}/${PY_NAME}.py" $*
2325
}

0 commit comments

Comments
 (0)