@@ -657,9 +657,23 @@ def system_prerelease(session: nox.sessions.Session):
657
657
658
658
659
659
@nox .session (python = SYSTEM_TEST_PYTHON_VERSIONS )
660
- def notebook (session ):
660
+ def notebook (session : nox .Session ):
661
+ GOOGLE_CLOUD_PROJECT = os .getenv ("GOOGLE_CLOUD_PROJECT" )
662
+ if not GOOGLE_CLOUD_PROJECT :
663
+ session .error (
664
+ "Set GOOGLE_CLOUD_PROJECT environment variable to run notebook session."
665
+ )
666
+
661
667
session .install ("-e" , ".[all]" )
662
- session .install ("pytest" , "pytest-xdist" , "pytest-retry" , "nbmake" )
668
+ session .install (
669
+ "pytest" ,
670
+ "pytest-xdist" ,
671
+ "pytest-retry" ,
672
+ "nbmake" ,
673
+ "google-cloud-aiplatform" ,
674
+ "matplotlib" ,
675
+ "seaborn" ,
676
+ )
663
677
664
678
notebooks_list = list (Path ("notebooks/" ).glob ("*/*.ipynb" ))
665
679
@@ -669,19 +683,22 @@ def notebook(session):
669
683
# These notebooks contain special colab `param {type:"string"}`
670
684
# comments, which make it easy for customers to fill in their
671
685
# own information.
686
+ #
687
+ # With the notebooks_fill_params.py script, we are able to find and
688
+ # replace the PROJECT_ID parameter, but not the others.
689
+ #
672
690
# TODO(ashleyxu): Test these notebooks by replacing parameters with
673
691
# appropriate values and omitting cleanup logic that may break
674
692
# our test infrastructure.
675
- "notebooks/getting_started/getting_started_bq_dataframes.ipynb" ,
676
- "notebooks/getting_started/ml_fundamentals_bq_dataframes.ipynb" ,
677
- "notebooks/generative_ai/bq_dataframes_llm_code_generation.ipynb" ,
678
- "notebooks/generative_ai/bq_dataframes_llm_kmeans.ipynb" ,
679
- "notebooks/regression/bq_dataframes_ml_linear_regression.ipynb" ,
680
- "notebooks/generative_ai/bq_dataframes_ml_drug_name_generation.ipynb" ,
681
- "notebooks/vertex_sdk/sdk2_bigframes_pytorch.ipynb" ,
682
- "notebooks/vertex_sdk/sdk2_bigframes_sklearn.ipynb" ,
683
- "notebooks/vertex_sdk/sdk2_bigframes_tensorflow.ipynb" ,
684
- "notebooks/visualization/bq_dataframes_covid_line_graphs.ipynb" ,
693
+ "notebooks/getting_started/ml_fundamentals_bq_dataframes.ipynb" , # Needs DATASET.
694
+ "notebooks/regression/bq_dataframes_ml_linear_regression.ipynb" , # Needs DATASET_ID.
695
+ "notebooks/generative_ai/bq_dataframes_ml_drug_name_generation.ipynb" , # Needs CONNECTION.
696
+ # TODO(swast): investigate why we get 404 errors, even though
697
+ # bq_dataframes_llm_code_generation creates a bucket in the sample.
698
+ "notebooks/generative_ai/bq_dataframes_llm_code_generation.ipynb" , # Needs BUCKET_URI.
699
+ "notebooks/vertex_sdk/sdk2_bigframes_pytorch.ipynb" , # Needs BUCKET_URI.
700
+ "notebooks/vertex_sdk/sdk2_bigframes_sklearn.ipynb" , # Needs BUCKET_URI.
701
+ "notebooks/vertex_sdk/sdk2_bigframes_tensorflow.ipynb" , # Needs BUCKET_URI.
685
702
# The experimental notebooks imagine features that don't yet
686
703
# exist or only exist as temporary prototypes.
687
704
"notebooks/experimental/longer_ml_demo.ipynb" ,
@@ -709,9 +726,9 @@ def notebook(session):
709
726
for nb , regions in notebooks_reg .items ()
710
727
}
711
728
712
- # For some reason nbmake exits silently with "no tests ran" message if
729
+ # The pytest -- nbmake exits silently with "no tests ran" message if
713
730
# one of the notebook paths supplied does not exist. Let's make sure that
714
- # each path exists
731
+ # each path exists.
715
732
for nb in notebooks + list (notebooks_reg ):
716
733
assert os .path .exists (nb ), nb
717
734
@@ -723,16 +740,33 @@ def notebook(session):
723
740
pytest_command = [
724
741
"py.test" ,
725
742
"--nbmake" ,
726
- "--nbmake-timeout=600" ,
743
+ "--nbmake-timeout=900" , # 15 minutes
727
744
]
728
745
729
- # Run self-contained notebooks in single session.run
730
- # achieve parallelization via -n
731
- session .run (
732
- * pytest_command ,
733
- "-nauto" ,
734
- * notebooks ,
735
- )
746
+ try :
747
+ # Populate notebook parameters and make a backup so that the notebooks
748
+ # are runnable.
749
+ session .run (
750
+ "python" ,
751
+ CURRENT_DIRECTORY / "scripts" / "notebooks_fill_params.py" ,
752
+ * notebooks ,
753
+ )
754
+
755
+ # Run self-contained notebooks in single session.run
756
+ # achieve parallelization via -n
757
+ session .run (
758
+ * pytest_command ,
759
+ "-nauto" ,
760
+ * notebooks ,
761
+ )
762
+ finally :
763
+ # Prevent our notebook changes from getting checked in to git
764
+ # accidentally.
765
+ session .run (
766
+ "python" ,
767
+ CURRENT_DIRECTORY / "scripts" / "notebooks_restore_from_backup.py" ,
768
+ * notebooks ,
769
+ )
736
770
737
771
# Run regionalized notebooks in parallel session.run's, since each notebook
738
772
# takes a different region via env param.
0 commit comments