Skip to content

Commit

Permalink
[doctools] Fix PYTHONPATH issue
Browse files Browse the repository at this point in the history
doctools/ul_table_test.py runs under both Python 2 and Python 3.

vendor/typing.py is Python 2 only.  Because Python 3 has typing in the
stdlib.

So we need the regular 'import typing', which is better anyway.

---

Note: we could also put pyannotate, mypy_extensions, and six in vendor/
!

And maybe an old version of pygments.
  • Loading branch information
Andy C committed Jan 14, 2025
1 parent 31ae20f commit e7e02b5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
8 changes: 6 additions & 2 deletions doctools/src-tree.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ source build/common.sh # log

export PYTHONPATH=.

src-tree-py() {
PYTHONPATH='.:vendor/' doctools/src_tree.py "$@"
}

install-deps() {
sudo apt-get install moreutils # for isutf8
}
Expand Down Expand Up @@ -141,7 +145,7 @@ all-html-to-files() {
log "=== $lang ==="

cat $BASE_DIR/$lang.txt | xargs _tmp/micro-syntax/micro_syntax -l $lang -w \
| doctools/src_tree.py write-html-fragments $out_dir
| $0 src-tree-py write-html-fragments $out_dir
log ''
done
}
Expand Down Expand Up @@ -184,7 +188,7 @@ highlight() {
time all-html-to-files $www_dir > $attrs

# Now write index.html dir listings
time doctools/src_tree.py dirs $www_dir < $attrs
time src-tree-py dirs $www_dir < $attrs
}

soil-run() {
Expand Down
9 changes: 7 additions & 2 deletions doctools/ul-table-test.ysh
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,14 @@ source $LIB_OSH/task-five.sh
#source $LIB_YSH/yblocks.ysh

proc run-py {
### Run with the shebang setting
PYTHONPATH='.:vendor/' @ARGV
}

proc run-py3 {
PYTHONPATH='.' python3 @ARGV
}

deps() {
# Good: only 3 files: ul_table, lazylex/html, util.py
build/dynamic-deps.sh py-tool doctools.ul_table
Expand All @@ -76,7 +81,7 @@ test-unit-py2() {
# Problem: We import cmark, which imports ctypes
test-unit-py3() {
# like test/unit.sh
run-py python3 doctools/ul_table_test.py
run-py3 doctools/ul_table_test.py
}

# Taken from unit test
Expand Down Expand Up @@ -116,7 +121,7 @@ test-without-cmark-py2() {
}

test-without-cmark-py3() {
echo $TD_ATTRS | cmark-bin --unsafe | run-py python3 doctools/ul_table.py
echo $TD_ATTRS | cmark-bin --unsafe | run-py3 doctools/ul_table.py
}

proc run-tests() {
Expand Down
5 changes: 1 addition & 4 deletions doctools/util.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
#!/usr/bin/env python2
"""util.py."""
from __future__ import print_function

import sys

# Note: from typing import Any causes ImportError when PYTHONPATH is not .:vendor
# So we import from vendor.typing which is a little inconsistent
from vendor.typing import Any
from typing import Any


def log(msg, *args):
Expand Down
6 changes: 5 additions & 1 deletion test/spec-runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -345,12 +345,16 @@ all-parallel() {
time $0 _all-parallel "$@"
}

src-tree-py() {
PYTHONPATH='.:vendor/' doctools/src_tree.py "$@"
}

all-tests-to-html() {
local manifest=$1
local output_base_dir=$2
# ignore attrs output
head -n $NUM_SPEC_TASKS $manifest \
| xargs --verbose -- doctools/src_tree.py spec-files $output_base_dir >/dev/null
| xargs --verbose -- $0 src-tree-py spec-files $output_base_dir >/dev/null

#| xargs -n 1 -P $MAX_PROCS -- $0 test-to-html $output_base_dir
log "done: all-tests-to-html"
Expand Down

0 comments on commit e7e02b5

Please sign in to comment.