Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make check/nbfmt more careful about tensorflow-docs #219

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions dev_tools/nbfmt
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,34 @@
cd "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$(git rev-parse --show-toplevel)"

# Check if cirq/check/nbformat exists, if not grab it.
# Base URL for downloading tools from Cirq.
declare -r cirq=https://raw.githubusercontent.com/quantumlib/Cirq/main

# Check if cirq/check/nbformat exists; if not, grab it.
if [[ ! -f dev_tools/nbformat ]]; then
wget https://raw.githubusercontent.com/quantumlib/Cirq/master/check/nbformat -P dev_tools/
wget $cirq/check/nbformat -P dev_tools/
chmod u+x dev_tools/nbformat
fi

# Check if tensorflow-docs.txt requirements file exists, if not grab it.
# Check if the tensorflow-docs.txt requirements file exists; if not, grab it.
if [[ ! -f dev_tools/tensorflow-docs.txt ]]; then
wget https://raw.githubusercontent.com/quantumlib/Cirq/master/dev_tools/requirements/deps/tensorflow-docs.txt -P dev_tools/
wget $cirq/dev_tools/requirements/deps/tensorflow-docs.txt -P dev_tools/
fi

# Check if the tensorflow-docs package has been installed; if not, install it.
if ! pip show --quiet tensorflow-docs > /dev/null 2>&1; then
pip install -r dev_tools/tensorflow-docs.txt
fi

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

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