Skip to content

Commit

Permalink
[build/deps] Add yapf to py3-libs "wedge"
Browse files Browse the repository at this point in the history
So we can use a stable version.  But this technically isn't done yet!
Because we're still downloading on demand.

- We don't have a real WEDGE yet
  - I think this is because we don't have a mechanism for the MyPy repo
    dep to work in a container
  - However, here we're building outside of a container, so we don't
    have to worry about mounting
  - TODO: try 'python3 -m pip download'
- Add build/deps.sh rm-oils-crap
  - to let people start from scratch; it's just ~/wedge and /wedge for
    now
- Unconditionally set PATH / PYTHONPATH, to fix bug when running
  build/deps.sh install-wedges from scratch
- Move formatting to devtools/format.sh
  • Loading branch information
Andy C committed Jul 27, 2023
1 parent b9a5bf7 commit a43bc5d
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 61 deletions.
21 changes: 18 additions & 3 deletions build/deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# Examples:
# build/deps.sh fetch
# build/deps.sh install-wedges
# build/deps.sh rm-oils-crap # rm /wedge ~/wedge to start over
#
# - re2c
# - cmark
Expand Down Expand Up @@ -59,7 +60,7 @@ readonly PY3_URL="https://www.python.org/ftp/python/3.10.4/Python-$PY3_VERSION.t
readonly MYPY_GIT_URL=https://github.com/python/mypy
readonly MYPY_VERSION=0.780

readonly PY3_LIBS_VERSION=2023-03-04
readonly PY3_LIBS_VERSION=2023-07-27

readonly PY3_LIBS=~/wedge/oils-for-unix.org/pkg/py3-libs/$MYPY_VERSION

Expand All @@ -85,6 +86,14 @@ die() {
exit 1
}

rm-oils-crap() {
### When you want to start over

rm -r -f -v ~/wedge
sudo rm -r -f -v /wedge
}


install-ubuntu-packages() {
### Packages for build/py.sh all, building wedges, etc.

Expand Down Expand Up @@ -264,11 +273,17 @@ install-py3-libs-in-venv() {

source $venv_dir/bin/activate # enter virtualenv

# Needed for spec/stateful/*.py
python3 -m pip install pexpect
# 2023-07 bug fix: have to install MyPy deps FIRST, THEN yapf. Otherwise
# we get an error from pip:
# "ERROR: pip's dependency resolver does not currently take into account all
# the packages that are installed."

# for mycpp/
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
}

install-py3-libs() {
Expand Down
15 changes: 8 additions & 7 deletions build/dev-shell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ fi

# put 'python3' in $PATH
readonly WEDGE_PY3_DIR=$ROOT_WEDGE_DIR/pkg/python3/3.10.4/bin
if test -d $WEDGE_PY3_DIR; then
export PATH="$WEDGE_PY3_DIR:$PATH"
fi
# Unconditionally add it to PATH; otherwise build/deps.sh install-wedges won't
# work
export PATH="$WEDGE_PY3_DIR:$PATH"

readonly WEDGE_BLOATY_DIR=$ROOT_WEDGE_DIR/pkg/bloaty/1.1 # not in bin
if test -d $WEDGE_BLOATY_DIR; then
Expand Down Expand Up @@ -75,10 +75,11 @@ export PYTHONPATH='.'

readonly site_packages=lib/python3.10/site-packages

readonly PY3_LIBS_WEDGE=$USER_WEDGE_DIR/pkg/py3-libs/2023-03-04/$site_packages
if test -d "$PY3_LIBS_WEDGE"; then
export PYTHONPATH="$PY3_LIBS_WEDGE:$PYTHONPATH"
fi
# Note: Version should match the one in build/deps.sh
readonly PY3_LIBS_WEDGE=$USER_WEDGE_DIR/pkg/py3-libs/2023-07-27/$site_packages
# Unconditionally add to PYTHONPATH; otherwise build/deps.sh install-wedges
# can't work in one shot
export PYTHONPATH="$PY3_LIBS_WEDGE:$PYTHONPATH"

MYPY_VERSION=0.780
# TODO: would be nice to upgrade to newer version
Expand Down
20 changes: 20 additions & 0 deletions devtools/format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash
#
# Run yapf formatter; it's installed in ~/wedge/ by build/deps.sh
#
# Usage:
# test/format.sh <function name>

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

yapf-version() {
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() {
python3 -m yapf -i "$@"
}

"$@"
33 changes: 0 additions & 33 deletions test/format.sh

This file was deleted.

19 changes: 1 addition & 18 deletions test/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,6 @@ mycpp-files() {
done
}

# NOTE: test/format.sh installs and runs yapf for Debian 12 bookworm
yapf-files() {
python3 -m yapf -i "$@"
}

run-yapf-3() {
### Run yapf on Python 3 code
mycpp-files | xargs $0 yapf-files
}

py2-files-to-format() {
for dir in "${CODE_DIRS[@]}"; do
for name in $dir/*.py; do
Expand All @@ -201,16 +191,9 @@ py2-files-to-format() {
done | grep -v 'NINJA_subgraph' # leave out for now
}

run-yapf-2() {
### Run yapf on Python 2 code

# These files originally had 4 space indentation, but it got inconsistent
time py2-files-to-format \
| xargs --verbose -- python3 -m yapf -i --style='{based_on_style: google: indent_width: 4}'
}

run-docformatter() {
### Format docstrings

# Only done as a ONE OFF to indent docstrings after yapf-2
# Because it tends to mangle comments, e.g. grammar comments in
# ysh/expr_to_ast.py
Expand Down

0 comments on commit a43bc5d

Please sign in to comment.