Skip to content
Merged
Show file tree
Hide file tree
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
32 changes: 32 additions & 0 deletions .internal/pre_commit_tools/notebook_forbid_deprecation_outputs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env python3

import re

from _common import iter_cells, load_notebook, report, run_precommit

# Also matches subclasses, e.g. `ClassiqDeprecationWarning` and `PendingDeprecationWarning`
DEPRECATION_WARNING = re.compile(r"\w*(DeprecationWarning|FutureWarning|SyntaxWarning)")


def forbid_deprecation_outputs(notebook_path: str) -> bool:
nb = load_notebook(notebook_path)

result = True
for cell_idx, cell in iter_cells(nb, "code"):
for output in cell.get("outputs", []):
if output.get("output_type") != "stream":
continue
if match := DEPRECATION_WARNING.search(output.get("text", "")):
result = False
report(
notebook_path,
"deprecation warning in the outputs - replace the deprecated call, and re-run the notebook",
cell_idx,
match.string[match.start() :].splitlines()[0],
)

return result


if __name__ == "__main__":
run_precommit(forbid_deprecation_outputs)
32 changes: 32 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,38 @@ repos:
additional_dependencies:
- "nbformat"
require_serial: true
- id: forbid-deprecation-outputs
name: forbid deprecation warnings in outputs
entry: .internal/pre_commit_tools/notebook_forbid_deprecation_outputs.py
language: python
files: \.ipynb$
# These notebooks' outputs still show a deprecation warning.
# Remove each one once it's fixed and re-run.
exclude: |
(?x)(^|/)(
projected_based_embedding_tutorial|
link_monitoring|
portfolio_optimization|
task_scheduling_problem|
integer_linear_programming|
evidence_scaling_labs|
max_clique|
max_k_vertex_cover|
set_partition|
ising_model|
radio_access_network_positioning_antennas|
benchmark_dynamical_localization|
benchmark_ghz|
advection_equation_2nd_place_submission|
advection_equation_winning_submission|
select_structures_BE|
quantum_walks_via_efficient_blockencoding|
stateprep_guassian_using_qsvt|
modular_exp_example
)\.ipynb$
additional_dependencies:
- "nbformat"
require_serial: true

- id: validate-latex
name: validate notebook LaTeX
Expand Down
Loading