Skip to content

Commit

Permalink
[devtools] Install yapf in virtualenv
Browse files Browse the repository at this point in the history
I figured out that PYTHONPATH was an issue.

TODO: make separate wedges for yapf and MyPy deps.  I guess the wedges
are virtualenvs with binary artifacts.
  • Loading branch information
Andy C committed Jul 27, 2023
1 parent 21800e7 commit f13f870
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
15 changes: 13 additions & 2 deletions build/deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,19 @@ install-py3-libs-in-venv() {
time python3 -m pip install -r $mypy_dir/test-requirements.txt

# pexpect: for spec/stateful/*.py
# yapf: all devs should on the same version
python3 -m pip install pexpect yapf
python3 -m pip install pexpect

# TODO:
# - Do something like this 'pip download' in build/deps.sh fetch
# - Then create a WEDGE which installs it
# - However note that this is NOT source code; there is binary code, e.g.
# in lxml-*.whl
if false; then
local pip_dir=_tmp/pip
mkdir -p $pip_dir
python3 -m pip download -d $pip_dir -r $mypy_dir/test-requirements.txt
python3 -m pip download -d $pip_dir pexpect
fi
}

install-py3-libs() {
Expand Down
26 changes: 26 additions & 0 deletions devtools/format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
REPO_ROOT=$(cd "$(dirname $0)/.."; pwd)

. build/dev-shell.sh # python3 in $PATH

# Hack to prevent interference. TODO: Make a seperate wedge for yapf.
unset PYTHONPATH

. build/common.sh # $CLANG_DIR

set -o nounset
Expand All @@ -19,13 +23,35 @@ shopt -s strict:all 2>/dev/null || true # dogfood for OSH
# Python
#

readonly YAPF_VENV='_tmp/yapf-venv'

install-yapf() {
local venv=$YAPF_VENV

rm -r -f -v $venv

python3 -m venv $venv

. $venv/bin/activate

# 0.40.1 is the 2023-06-20 release
#
# Pin the version so formatting is stable!

python3 -m pip install 'yapf == 0.40.1'

yapf-version
}

yapf-version() {
. $YAPF_VENV/bin/activate
python3 -m yapf --version
}

# For now, run yapf on specific files. TODO: could query git for the files
# that are are different from master branch, and run it on those.
yapf-files() {
. $YAPF_VENV/bin/activate
python3 -m yapf -i "$@"
}

Expand Down

0 comments on commit f13f870

Please sign in to comment.