Skip to content

Commit 417975a

Browse files
authored
Merge pull request #219 from mhucka/mh-fix-nbfmt
Make dev_tools/nbfmt more careful about tensorflow-docs
2 parents 00496fe + 313b61d commit 417975a

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

dev_tools/nbfmt

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,34 @@
1818
cd "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" || exit
1919
cd "$(git rev-parse --show-toplevel)" || exit
2020

21-
# Check if cirq/check/nbformat exists, if not grab it.
21+
# Base URL for downloading tools from Cirq.
22+
declare -r cirq=https://raw.githubusercontent.com/quantumlib/Cirq/main
23+
24+
# Check if cirq/check/nbformat exists; if not, grab it.
2225
if [[ ! -f dev_tools/nbformat ]]; then
23-
wget https://raw.githubusercontent.com/quantumlib/Cirq/master/check/nbformat -P dev_tools/
26+
wget $cirq/check/nbformat -P dev_tools/
2427
chmod u+x dev_tools/nbformat
2528
fi
2629

27-
# Check if tensorflow-docs.txt requirements file exists, if not grab it.
30+
# Check if the tensorflow-docs.txt requirements file exists; if not, grab it.
2831
if [[ ! -f dev_tools/tensorflow-docs.txt ]]; then
29-
wget https://raw.githubusercontent.com/quantumlib/Cirq/master/dev_tools/requirements/deps/tensorflow-docs.txt -P dev_tools/
32+
wget $cirq/dev_tools/requirements/deps/tensorflow-docs.txt -P dev_tools/
33+
fi
34+
35+
# Check if the tensorflow-docs package has been installed; if not, install it.
36+
if ! pip show --quiet tensorflow-docs > /dev/null 2>&1; then
3037
pip install -r dev_tools/tensorflow-docs.txt
3138
fi
3239

3340
# Run the formatter.
3441
result=$(dev_tools/nbformat "$@")
3542
status=$?
3643

37-
# Make sure error message references right file.
38-
result=${result//"check/nbformat"/"dev_tools/nbfmt"}
44+
# If there is an error message, make sure it references this script.
45+
# Note: using vars here avoids a problem with subsituting strings containing /.
46+
check_path="check/"
47+
devtools_path="dev_tools/"
48+
result=${result//$check_path/$devtools_path}
49+
result=${result//"nbformat"/"nbfmt"}
3950
printf '%s\n' "${result[@]}"
4051
exit $status

0 commit comments

Comments
 (0)