From ad1063cb00642da148eb78b7471fa6485941746f Mon Sep 17 00:00:00 2001 From: mhucka Date: Fri, 10 Apr 2026 02:52:08 +0000 Subject: [PATCH 1/7] Add `.style.yapf` Set the YAPF style to Google style. --- .style.yapf | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .style.yapf diff --git a/.style.yapf b/.style.yapf new file mode 100644 index 000000000..0e9640c29 --- /dev/null +++ b/.style.yapf @@ -0,0 +1,2 @@ +[style] +based_on_style = google From 79c3464208d6ee734a3173d258e183638d399ef0 Mon Sep 17 00:00:00 2001 From: mhucka Date: Fri, 10 Apr 2026 04:27:21 +0000 Subject: [PATCH 2/7] Remove `--style=google` from invocations of `yapf` Moved the style setting to the config file. --- .github/workflows/ci-file-checks.yaml | 2 +- scripts/format_all.sh | 4 ++-- scripts/format_check.sh | 2 +- scripts/format_ipynb.py | 3 +-- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci-file-checks.yaml b/.github/workflows/ci-file-checks.yaml index 166af5c90..bf3a5e704 100644 --- a/.github/workflows/ci-file-checks.yaml +++ b/.github/workflows/ci-file-checks.yaml @@ -336,7 +336,7 @@ jobs: - name: Run Yapf on the Python changed files run: | set +e - yapf --parallel --diff --style=google \ + yapf --parallel --diff \ ${{needs.Changes.outputs.python_files}} > diff.out 2>&1 exit_code=$? if [[ -s ./diff.out ]]; then diff --git a/scripts/format_all.sh b/scripts/format_all.sh index 0e374a3cc..903923046 100755 --- a/scripts/format_all.sh +++ b/scripts/format_all.sh @@ -14,8 +14,8 @@ # limitations under the License. # ============================================================================== echo "Doing python language formatting..." -python3 -m yapf --style=google --in-place --recursive ./benchmarks -python3 -m yapf --style=google --in-place --recursive ./tensorflow_quantum +python3 -m yapf --in-place --recursive ./benchmarks +python3 -m yapf --in-place --recursive ./tensorflow_quantum echo -e "Done! \nDoing notebook formatting..." python3 ./scripts/format_ipynb.py echo -e "Done! \nDoing C++ formatting..." diff --git a/scripts/format_check.sh b/scripts/format_check.sh index f0de918dc..407d3a155 100755 --- a/scripts/format_check.sh +++ b/scripts/format_check.sh @@ -72,7 +72,7 @@ for changed_file in ${changed_files}; do ) if [[ "${changed_line_ranges}" != "--lines=0-0 " ]]; then # Do the formatting. - results=$(yapf --style=google --diff "${changed_file}" ${changed_line_ranges}) + results=$(yapf --diff "${changed_file}" ${changed_line_ranges}) # Print colorized error messages. if [ ! -z "${results}" ]; then diff --git a/scripts/format_ipynb.py b/scripts/format_ipynb.py index a0e475e9c..d43c84323 100644 --- a/scripts/format_ipynb.py +++ b/scripts/format_ipynb.py @@ -28,8 +28,7 @@ lines = cell.get('source') # This will safely skip over cells containing !% magic try: - fmt_lines = yapf.yapf_api.FormatCode(''.join(lines), - style_config="google")[0] + fmt_lines = yapf.yapf_api.FormatCode(''.join(lines))[0] except (SyntaxError, yapf.yapflib.errors.YapfError): continue # google style always adds an EOF newline; undo this. From 1409075891f11a5147b2ad1e57d21042ccbba59a Mon Sep 17 00:00:00 2001 From: mhucka Date: Tue, 14 Apr 2026 19:56:10 +0000 Subject: [PATCH 3/7] Invoke yapf using `python3 -m yapf` The invocation in this script was inconsistent with how the other scripts did it. --- scripts/format_check.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/format_check.sh b/scripts/format_check.sh index 407d3a155..40d65aa27 100755 --- a/scripts/format_check.sh +++ b/scripts/format_check.sh @@ -1,12 +1,12 @@ #!/bin/bash # Copyright 2020 The TensorFlow Quantum Authors. All Rights Reserved. -# +# # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -72,7 +72,7 @@ for changed_file in ${changed_files}; do ) if [[ "${changed_line_ranges}" != "--lines=0-0 " ]]; then # Do the formatting. - results=$(yapf --diff "${changed_file}" ${changed_line_ranges}) + results=$(python3 -m yapf --diff "${changed_file}" ${changed_line_ranges}) # Print colorized error messages. if [ ! -z "${results}" ]; then From 07961933b1dbea8c9b2d53fe08e13eb65c284cb3 Mon Sep 17 00:00:00 2001 From: mhucka Date: Tue, 14 Apr 2026 20:01:52 +0000 Subject: [PATCH 4/7] Supply the current file path to yapf Providing the path to the file allows yapf to find the config file. --- scripts/format_ipynb.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/format_ipynb.py b/scripts/format_ipynb.py index d43c84323..c0e91d465 100644 --- a/scripts/format_ipynb.py +++ b/scripts/format_ipynb.py @@ -28,7 +28,8 @@ lines = cell.get('source') # This will safely skip over cells containing !% magic try: - fmt_lines = yapf.yapf_api.FormatCode(''.join(lines))[0] + fmt_lines = yapf.yapf_api.FormatCode(''.join(lines), + filename=fname)[0] except (SyntaxError, yapf.yapflib.errors.YapfError): continue # google style always adds an EOF newline; undo this. From c7473486fc94da19a3a4fb3ebcd6d775d7bfbf48 Mon Sep 17 00:00:00 2001 From: mhucka Date: Tue, 14 Apr 2026 20:11:41 +0000 Subject: [PATCH 5/7] Run yapf on scripts/ --- scripts/format_all.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/format_all.sh b/scripts/format_all.sh index 903923046..50bacaffb 100755 --- a/scripts/format_all.sh +++ b/scripts/format_all.sh @@ -16,6 +16,7 @@ echo "Doing python language formatting..." python3 -m yapf --in-place --recursive ./benchmarks python3 -m yapf --in-place --recursive ./tensorflow_quantum +python3 -m yapf --in-place --recursive ./scripts echo -e "Done! \nDoing notebook formatting..." python3 ./scripts/format_ipynb.py echo -e "Done! \nDoing C++ formatting..." From 4ccac5cdf6fc926b4b14d185d30bd44dd4879371 Mon Sep 17 00:00:00 2001 From: Michael Hucka Date: Tue, 14 Apr 2026 13:16:26 -0700 Subject: [PATCH 6/7] Update scripts/format_all.sh Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- scripts/format_all.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/format_all.sh b/scripts/format_all.sh index 50bacaffb..65488d49e 100755 --- a/scripts/format_all.sh +++ b/scripts/format_all.sh @@ -14,9 +14,7 @@ # limitations under the License. # ============================================================================== echo "Doing python language formatting..." -python3 -m yapf --in-place --recursive ./benchmarks -python3 -m yapf --in-place --recursive ./tensorflow_quantum -python3 -m yapf --in-place --recursive ./scripts +python3 -m yapf --in-place --recursive ./benchmarks ./tensorflow_quantum ./scripts echo -e "Done! \nDoing notebook formatting..." python3 ./scripts/format_ipynb.py echo -e "Done! \nDoing C++ formatting..." From a6c916331751e8c4b6dc641fb14a573de4fe0e58 Mon Sep 17 00:00:00 2001 From: mhucka Date: Wed, 15 Apr 2026 01:41:10 +0000 Subject: [PATCH 7/7] Run file through format_all.sh --- scripts/build_docs.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/scripts/build_docs.py b/scripts/build_docs.py index dc47df224..733ba72e8 100644 --- a/scripts/build_docs.py +++ b/scripts/build_docs.py @@ -43,8 +43,6 @@ FLAGS = flags.FLAGS - - def main(unused_argv): doc_generator = generate_lib.DocGenerator(