From 994ed3a5e8f760fe688efc55111219b572b9880e Mon Sep 17 00:00:00 2001 From: mhucka Date: Tue, 14 Apr 2026 21:29:23 +0000 Subject: [PATCH 1/6] Run pylint on scripts/ and benchmarks/ too This adds ./scripts and ./benchmarks to directories where the linter is run. --- scripts/lint_all.sh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/scripts/lint_all.sh b/scripts/lint_all.sh index b821610af..e06248145 100755 --- a/scripts/lint_all.sh +++ b/scripts/lint_all.sh @@ -1,20 +1,21 @@ #!/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. # See the License for the specific language governing permissions and # limitations under the License. # ============================================================================== -echo "Checking for lint in python code..."; -linting_outputs=$(pylint --rcfile .pylintrc ./tensorflow_quantum); +echo "Checking for lint in Python code..."; +linting_outputs=$(pylint --rcfile .pylintrc \ + ./benchmarks ./scripts ./tensorflow_quantum) exit_code=$? if [ "$exit_code" == "0" ]; then echo "Python linting complete!"; From e59d6049f825bc4eea461fcb1bed17e357329231 Mon Sep 17 00:00:00 2001 From: mhucka Date: Tue, 14 Apr 2026 21:32:24 +0000 Subject: [PATCH 2/6] Add docstring to satisfy pylint --- scripts/build_docs.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/build_docs.py b/scripts/build_docs.py index dc47df224..0e841ee83 100644 --- a/scripts/build_docs.py +++ b/scripts/build_docs.py @@ -43,9 +43,8 @@ FLAGS = flags.FLAGS - - def main(unused_argv): + """Run documentation builder.""" doc_generator = generate_lib.DocGenerator( root_title="TensorFlow Quantum", From 29c16227d359150bfe645f5e37ce6dd47d05a88e Mon Sep 17 00:00:00 2001 From: mhucka Date: Tue, 14 Apr 2026 21:33:11 +0000 Subject: [PATCH 3/6] Slightly refactor format_ipynb.py to satisfy pylint This puts the code into a function instead of running the loop at the top level of the file. This makes pylint happier. --- scripts/format_ipynb.py | 46 +++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/scripts/format_ipynb.py b/scripts/format_ipynb.py index a0e475e9c..d2f6be83f 100644 --- a/scripts/format_ipynb.py +++ b/scripts/format_ipynb.py @@ -13,27 +13,37 @@ # limitations under the License. # ============================================================================== """Format notebook code cells using yapf google style.""" + import glob import nbformat import yapf # Must be run from the top level of the `TFQuantum` repo. NOTEBOOKS = glob.glob("docs/tutorials/*.ipynb") -for fname in NOTEBOOKS: - nb = nbformat.read(fname, as_version=nbformat.NO_CONVERT) - all_cells = nb.get('cells') - for i, cell in enumerate(all_cells): - if cell.get('cell_type') != 'code': - continue - 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] - except (SyntaxError, yapf.yapflib.errors.YapfError): - continue - # google style always adds an EOF newline; undo this. - all_cells[i]['source'] = fmt_lines[:-1] - - nb['cells'] = all_cells - nbformat.write(nb, fname, version=nbformat.NO_CONVERT) + + +def format_notebooks(): + """Format tutorial notebooks.""" + + for fname in NOTEBOOKS: + nb = nbformat.read(fname, as_version=nbformat.NO_CONVERT) + all_cells = nb.get('cells') + for i, cell in enumerate(all_cells): + if cell.get('cell_type') != 'code': + continue + 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] + except (SyntaxError, yapf.yapflib.errors.YapfError): + continue + # google style always adds an EOF newline; undo this. + all_cells[i]['source'] = fmt_lines[:-1] + + nb['cells'] = all_cells + nbformat.write(nb, fname, version=nbformat.NO_CONVERT) + + +if __name__ == "__main__": + format_notebooks() From 0c1693137274807182bdf784c3d99207f3757468 Mon Sep 17 00:00:00 2001 From: mhucka Date: Tue, 14 Apr 2026 22:00:31 +0000 Subject: [PATCH 4/6] Move glob into the function Per Gemini Code Assist, putting the assignment inside the function is better. --- scripts/format_ipynb.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/scripts/format_ipynb.py b/scripts/format_ipynb.py index d2f6be83f..1624d2d5c 100644 --- a/scripts/format_ipynb.py +++ b/scripts/format_ipynb.py @@ -18,14 +18,13 @@ import nbformat import yapf -# Must be run from the top level of the `TFQuantum` repo. -NOTEBOOKS = glob.glob("docs/tutorials/*.ipynb") - def format_notebooks(): - """Format tutorial notebooks.""" + """Format tutorial notebooks. + + This must be run from the top level of the repository.""" - for fname in NOTEBOOKS: + for fname in glob.glob("docs/tutorials/*.ipynb"): nb = nbformat.read(fname, as_version=nbformat.NO_CONVERT) all_cells = nb.get('cells') for i, cell in enumerate(all_cells): From ebe4968cf6feefaba9a70b363330920a3f56b802 Mon Sep 17 00:00:00 2001 From: mhucka Date: Tue, 14 Apr 2026 22:55:30 +0000 Subject: [PATCH 5/6] Use same indentation as the rest of the file --- scripts/lint_all.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/lint_all.sh b/scripts/lint_all.sh index e06248145..fbb77e6d3 100755 --- a/scripts/lint_all.sh +++ b/scripts/lint_all.sh @@ -15,7 +15,7 @@ # ============================================================================== echo "Checking for lint in Python code..."; linting_outputs=$(pylint --rcfile .pylintrc \ - ./benchmarks ./scripts ./tensorflow_quantum) + ./benchmarks ./scripts ./tensorflow_quantum) exit_code=$? if [ "$exit_code" == "0" ]; then echo "Python linting complete!"; From 2791309652861f43188dfd67a15b6fd52c389a4b Mon Sep 17 00:00:00 2001 From: mhucka Date: Tue, 14 Apr 2026 22:57:33 +0000 Subject: [PATCH 6/6] Remove needless semicolon --- scripts/lint_all.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/lint_all.sh b/scripts/lint_all.sh index fbb77e6d3..e54e8c747 100755 --- a/scripts/lint_all.sh +++ b/scripts/lint_all.sh @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # ============================================================================== -echo "Checking for lint in Python code..."; +echo "Checking for lint in Python code..." linting_outputs=$(pylint --rcfile .pylintrc \ ./benchmarks ./scripts ./tensorflow_quantum) exit_code=$?