Skip to content

Commit 172aea9

Browse files
author
Ace Nassri
authored
feat(AST parser): use v2 parser architecture (GoogleCloudPlatform#5266)
1 parent c3a6599 commit 172aea9

File tree

3 files changed

+30
-11
lines changed

3 files changed

+30
-11
lines changed

.kokoro/docker/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ RUN wget --no-check-certificate -O /tmp/get-pip.py 'https://bootstrap.pypa.io/ge
143143
# https://github.com/docker-library/python/pull/100
144144
&& [ "$(pip list |tac|tac| awk -F '[ ()]+' '$1 == "pip" { print $2; exit }')" = "$PYTHON_PIP_VERSION" ]
145145

146-
# Ensure Pip for 3.8.0
147-
RUN python3.8 /tmp/get-pip.py
146+
# Ensure Pip for python3
147+
RUN python3 /tmp/get-pip.py
148148
RUN rm /tmp/get-pip.py
149149

150150
# Install "virtualenv", since the vast majority of users of this image

.kokoro/tests/run_single_test.sh

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,36 @@ if [[ "${INJECT_REGION_TAGS:-}" == "true" ]]; then
5050
export XUNIT_PATH="$PWD/sponge_log.xml"
5151
export XUNIT_TMP_PATH="$(mktemp)"
5252

53+
# We use `python3.8` because it is the version pip3 installs to.
54+
export PYTHON_CMD="python3"
55+
5356
if [[ -f "$XUNIT_PATH" ]]; then
5457
echo "=== Injecting region tags into XUnit output ==="
5558
echo "Processing XUnit output file: $XUNIT_PATH (saving output to $XUNIT_TMP_PATH)"
5659

57-
# We use `python3` because it will work even if we remove old
58-
# python versions from the docker image.
59-
echo "Calling python3 ${PARSER_PATH} inject-snippet-mapping --output_file ${XUNIT_TMP_PATH} ${PWD}"
60+
TARGET_DIR=$PWD
61+
62+
# First, we generate a Python-specific "polyglot_snippet_data.json" file
63+
# (cd'ing into script's working dir is necessary for imports to work)
64+
echo "Calling $PYTHON_CMD ${PYTHON_PARSER_PATH} ${TARGET_DIR}"
65+
pushd $(dirname $PYTHON_PARSER_PATH)
66+
$PYTHON_CMD "$PYTHON_PARSER_PATH" "$TARGET_DIR"
67+
popd
68+
69+
# Then, we pass the "polyglot_snippet_data.json" file and the XUnit output
70+
# to the "polyglot" parser.
71+
# This outputs the XUnit input with the snippet-test map added
72+
# Again, we use `python3` for pip3 support.
73+
echo "Calling: cat $XUNIT_PATH | $PYTHON_CMD ${POLYGLOT_PARSER_PATH} inject-snippet-mapping --output_file ${XUNIT_TMP_PATH} ${TARGET_DIR}"
74+
pushd $(dirname $POLYGLOT_PARSER_PATH)
6075
cat "$XUNIT_PATH" | \
61-
python3 "$PARSER_PATH" inject-snippet-mapping --output_file "$XUNIT_TMP_PATH" "$PWD"
76+
$PYTHON_CMD "$POLYGLOT_PARSER_PATH" --output_file "$XUNIT_TMP_PATH" inject-snippet-mapping "$TARGET_DIR"
6277
if [[ $? -eq 0 ]] && [[ -s "$XUNIT_PATH" ]]; then
6378
mv $XUNIT_TMP_PATH $XUNIT_PATH
6479
else
6580
echo "Region tag injection FAILED; XUnit file not modified."
6681
fi
82+
popd
6783
else
6884
echo "No XUnit output file found!"
6985
fi

.kokoro/tests/run_tests.sh

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,18 +130,21 @@ ROOT=$(pwd)
130130
if [[ "${INJECT_REGION_TAGS:-}" == "true" ]]; then
131131
echo "=== Setting up DRIFT region tag injector ==="
132132
# install PyYaml (used by the DRIFT region tag parsing system)
133-
echo "--- Installing PyYaml ---"
134-
python3 -m pip install --user pyyaml
133+
echo "--- Installing pip packages ---"
134+
python3 -m pip install --user pyyaml frozendict recordclass
135135

136136
# Use ${HOME} because trampoline will automatically clean up this
137137
# directory.
138138
export REGION_TAG_PARSER_DIR="${HOME}/region-tag-parser"
139-
export PARSER_PATH="${REGION_TAG_PARSER_DIR}/wizard-py/cli.py"
139+
export POLYGLOT_PARSER_PATH="${REGION_TAG_PARSER_DIR}/xunit-autolabeler-v2/cli_bootstrap.py"
140+
export PYTHON_PARSER_PATH="${REGION_TAG_PARSER_DIR}/xunit-autolabeler-v2/ast_parser/python_bootstrap.py"
140141

141-
if [[ ! -f $PARSER_PATH ]]; then
142+
if [[ ! -f $POLYGLOT_PARSER_PATH ]]; then
142143
echo "--- Fetching injection script from HEAD (via GitHub) ---"
143144
git clone https://github.com/GoogleCloudPlatform/repo-automation-playground "$REGION_TAG_PARSER_DIR" --single-branch
144-
chmod +x $PARSER_PATH
145+
146+
chmod +x $PYTHON_PARSER_PATH
147+
chmod +x $POLYGLOT_PARSER_PATH
145148
fi
146149
echo "=== Region tag injector setup complete ==="
147150
fi

0 commit comments

Comments
 (0)