From 8f475e597d9f37a5149e36c2c277e2b506189a6d Mon Sep 17 00:00:00 2001 From: Ashish Panigrahi Date: Tue, 13 Apr 2021 20:18:02 +0530 Subject: [PATCH 1/7] added black-nb --- check/nbformat | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/check/nbformat b/check/nbformat index 2a123c9ffb8..0c0ea482bc8 100755 --- a/check/nbformat +++ b/check/nbformat @@ -30,24 +30,34 @@ cd "$(git rev-parse --show-toplevel)" # Install a pinned version of tf-docs TF_DOCS_COMMIT=b3dc8a922d8bdc6e998a8ad4f4953359dc6e576a -TF_DOCS_INSTALLED=$(pip list | grep -c $TF_DOCS_COMMIT) +TF_DOCS_INSTALLED="$(pip list | grep -c "$TF_DOCS_COMMIT")" +BLACK_INSTALLED="$(pip list | grep -c 'black-nb')" if [ "$TF_DOCS_INSTALLED" != "1" ]; then pip install -U git+https://github.com/tensorflow/docs@$TF_DOCS_COMMIT fi +if [ "$BLACK_INSTALLED" != "1" ]; then + pip install -U black-nb +fi + FORMAT_CMD="python3 -m tensorflow_docs.tools.nbfmt --indent=1" +BLACK_FORMAT="black-nb" # Test the notebooks -unformatted=$($FORMAT_CMD --test docs 2>&1 | grep "\- docs" || true) +unformatted="$("$FORMAT_CMD" --test docs 2>&1 | grep "\- docs" || true)" +black_unformatted="$("$BLACK_FORMAT" --check docs 2>&1 | grep "would be reformatted")" needed_changes=0 if [ ! -z "${unformatted}" ]; then - needed_changes=1 - if (( only_print == 0 )); then - $FORMAT_CMD docs - else - echo -e "\033[31mThe following notebooks require formatting\033[0m." - echo "${unformatted}" + if [ ! -z "${black_unformatted}" ]; then + needed_changes=1 + if (( only_print == 0 )); then + "$BLACK_FORMAT" docs + "$FORMAT_CMD" docs + else + echo -e "\033[31mThe following notebooks require formatting\033[0m." + echo "${unformatted}" + fi fi fi @@ -58,4 +68,4 @@ elif (( only_print == 1 )); then exit 1 else echo -e "\033[33mReformatted changed notebooks\033[0m." -fi \ No newline at end of file +fi From 68baba85328d7846a3ecce0e1f63e13924bc41b6 Mon Sep 17 00:00:00 2001 From: Ashish Panigrahi Date: Sat, 17 Apr 2021 23:58:58 +0530 Subject: [PATCH 2/7] quoted variables --- check/nbformat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check/nbformat b/check/nbformat index 0c0ea482bc8..3a468e5f9f3 100755 --- a/check/nbformat +++ b/check/nbformat @@ -15,7 +15,7 @@ ################################################################################ only_print=1 -for arg in $@; do +for arg in "$@"; do if [[ "${arg}" == "--apply" ]]; then only_print=0 else From af5d8a63216d60d493bdbe16b68e6f72a0f74898 Mon Sep 17 00:00:00 2001 From: Ashish Panigrahi Date: Sun, 18 Apr 2021 00:11:52 +0530 Subject: [PATCH 3/7] hopefully fails test --- check/nbformat | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/check/nbformat b/check/nbformat index 3a468e5f9f3..1c034756270 100755 --- a/check/nbformat +++ b/check/nbformat @@ -48,16 +48,14 @@ BLACK_FORMAT="black-nb" unformatted="$("$FORMAT_CMD" --test docs 2>&1 | grep "\- docs" || true)" black_unformatted="$("$BLACK_FORMAT" --check docs 2>&1 | grep "would be reformatted")" needed_changes=0 -if [ ! -z "${unformatted}" ]; then - if [ ! -z "${black_unformatted}" ]; then - needed_changes=1 - if (( only_print == 0 )); then - "$BLACK_FORMAT" docs - "$FORMAT_CMD" docs - else - echo -e "\033[31mThe following notebooks require formatting\033[0m." - echo "${unformatted}" - fi +if [ ! -z "${unformatted}" || ! -z "${black_unformatted}" ]; then + needed_changes=1 + if (( only_print == 0 )); then + "$BLACK_FORMAT" docs + "$FORMAT_CMD" docs + else + echo -e "\033[31mThe following notebooks require formatting\033[0m." + echo "${unformatted}" fi fi From 31353840f6cbc37dc0258562a03d631459f567b2 Mon Sep 17 00:00:00 2001 From: Ashish Panigrahi Date: Tue, 27 Apr 2021 22:41:55 +0530 Subject: [PATCH 4/7] fixed shell errors --- check/nbformat | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/check/nbformat b/check/nbformat index 1c034756270..b6797a84dd1 100755 --- a/check/nbformat +++ b/check/nbformat @@ -25,8 +25,8 @@ for arg in "$@"; do done # Get the working directory to the repo root. -cd "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -cd "$(git rev-parse --show-toplevel)" +cd "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" || exit +cd "$(git rev-parse --show-toplevel)" || exit # Install a pinned version of tf-docs TF_DOCS_COMMIT=b3dc8a922d8bdc6e998a8ad4f4953359dc6e576a @@ -48,7 +48,7 @@ BLACK_FORMAT="black-nb" unformatted="$("$FORMAT_CMD" --test docs 2>&1 | grep "\- docs" || true)" black_unformatted="$("$BLACK_FORMAT" --check docs 2>&1 | grep "would be reformatted")" needed_changes=0 -if [ ! -z "${unformatted}" || ! -z "${black_unformatted}" ]; then +if [ -n "${unformatted}" ] || [ -n "${black_unformatted}" ]; then needed_changes=1 if (( only_print == 0 )); then "$BLACK_FORMAT" docs From 47f55028e86442129b2ba3e43ca3b5b0a03a295c Mon Sep 17 00:00:00 2001 From: Ashish Panigrahi Date: Tue, 27 Apr 2021 23:58:37 +0530 Subject: [PATCH 5/7] fixed dependency line and order of format run --- check/nbformat | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/check/nbformat b/check/nbformat index b6797a84dd1..c68925b2ba8 100755 --- a/check/nbformat +++ b/check/nbformat @@ -31,31 +31,27 @@ cd "$(git rev-parse --show-toplevel)" || exit # Install a pinned version of tf-docs TF_DOCS_COMMIT=b3dc8a922d8bdc6e998a8ad4f4953359dc6e576a TF_DOCS_INSTALLED="$(pip list | grep -c "$TF_DOCS_COMMIT")" -BLACK_INSTALLED="$(pip list | grep -c 'black-nb')" if [ "$TF_DOCS_INSTALLED" != "1" ]; then pip install -U git+https://github.com/tensorflow/docs@$TF_DOCS_COMMIT fi -if [ "$BLACK_INSTALLED" != "1" ]; then - pip install -U black-nb -fi - FORMAT_CMD="python3 -m tensorflow_docs.tools.nbfmt --indent=1" -BLACK_FORMAT="black-nb" +TFDOCS_FORMAT="black-nb" # Test the notebooks +black_unformatted="$("$TFDOCS_FORMAT" --check docs 2>&1 | grep "would be reformatted")" unformatted="$("$FORMAT_CMD" --test docs 2>&1 | grep "\- docs" || true)" -black_unformatted="$("$BLACK_FORMAT" --check docs 2>&1 | grep "would be reformatted")" needed_changes=0 if [ -n "${unformatted}" ] || [ -n "${black_unformatted}" ]; then needed_changes=1 if (( only_print == 0 )); then - "$BLACK_FORMAT" docs + "$TFDOCS_FORMAT" docs "$FORMAT_CMD" docs else echo -e "\033[31mThe following notebooks require formatting\033[0m." echo "${unformatted}" + echo "${black_unformatted}" fi fi From 634a3a9bc67ea0eab1807fe94621a263204d9bea Mon Sep 17 00:00:00 2001 From: Ashish Panigrahi Date: Wed, 28 Apr 2021 09:38:34 +0530 Subject: [PATCH 6/7] added dependency and removed quotes --- check/nbformat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check/nbformat b/check/nbformat index c68925b2ba8..1496a8e0a6d 100755 --- a/check/nbformat +++ b/check/nbformat @@ -30,7 +30,7 @@ cd "$(git rev-parse --show-toplevel)" || exit # Install a pinned version of tf-docs TF_DOCS_COMMIT=b3dc8a922d8bdc6e998a8ad4f4953359dc6e576a -TF_DOCS_INSTALLED="$(pip list | grep -c "$TF_DOCS_COMMIT")" +TF_DOCS_INSTALLED=$(pip list | grep -c "$TF_DOCS_COMMIT") if [ "$TF_DOCS_INSTALLED" != "1" ]; then pip install -U git+https://github.com/tensorflow/docs@$TF_DOCS_COMMIT From 758d2304476731eabd39d2af414a932e5755ebba Mon Sep 17 00:00:00 2001 From: Ashish Panigrahi Date: Wed, 28 Apr 2021 09:39:55 +0530 Subject: [PATCH 7/7] added dependency file --- dev_tools/conf/pip-list-dev-tools.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dev_tools/conf/pip-list-dev-tools.txt b/dev_tools/conf/pip-list-dev-tools.txt index e5eafb200f9..9dabb80f989 100644 --- a/dev_tools/conf/pip-list-dev-tools.txt +++ b/dev_tools/conf/pip-list-dev-tools.txt @@ -3,6 +3,7 @@ asv virtualenv black==20.8b1 +black-nb~=0.4.0 mypy~=0.782.0 pylint~=2.6.0 pytest~=6.2.2 @@ -39,4 +40,4 @@ rstcheck~=3.3.1 freezegun~=0.3.15 # for python 3.7 and below needs to be installed -importlib-metadata; python_version < '3.8' \ No newline at end of file +importlib-metadata; python_version < '3.8'