diff --git a/abr-testing/abr_testing/automation/google_sheets_tool.py b/abr-testing/abr_testing/automation/google_sheets_tool.py index afac386bc40..7e8b4dc0f29 100644 --- a/abr-testing/abr_testing/automation/google_sheets_tool.py +++ b/abr-testing/abr_testing/automation/google_sheets_tool.py @@ -15,6 +15,12 @@ """ +class google_interaction_error(gspread.exceptions.APIError): + """Internal use exception so we don't need to import gspread directly in other projects.""" + + pass + + class google_sheet: """Google Sheets Tool.""" diff --git a/hardware-testing/hardware_testing/liquid_sense/__main__.py b/hardware-testing/hardware_testing/liquid_sense/__main__.py index 674767da40a..b1fc67a2d2e 100644 --- a/hardware-testing/hardware_testing/liquid_sense/__main__.py +++ b/hardware-testing/hardware_testing/liquid_sense/__main__.py @@ -39,8 +39,15 @@ liquid_sense_ot3_p1000_single_vial, ) -from abr_testing.automation import google_sheets_tool +try: + from abr_testing.automation import google_sheets_tool +except ImportError: + ui.print_error( + "Unable to import abr repo if this isn't a simulation push the abr_testing package" + ) + from . import google_sheets_tool # type: ignore[no-redef] + pass CREDENTIALS_PATH = "/var/lib/jupyter/notebooks/abr.json" diff --git a/hardware-testing/hardware_testing/liquid_sense/execute.py b/hardware-testing/hardware_testing/liquid_sense/execute.py index d421a06c71e..53193c8ad8a 100644 --- a/hardware-testing/hardware_testing/liquid_sense/execute.py +++ b/hardware-testing/hardware_testing/liquid_sense/execute.py @@ -28,7 +28,15 @@ from opentrons_shared_data.errors.exceptions import LiquidNotFoundError -from abr_testing.automation import google_sheets_tool +try: + from abr_testing.automation import google_sheets_tool +except ImportError: + ui.print_error( + "Unable to import abr repo if this isn't a simulation push the abr_testing package" + ) + from . import google_sheets_tool # type: ignore[no-redef] + + pass PROBE_MAX_TIME: Dict[int, float] = { diff --git a/hardware-testing/hardware_testing/liquid_sense/post_process.py b/hardware-testing/hardware_testing/liquid_sense/post_process.py index 089f42047e3..680f8c7cdc4 100644 --- a/hardware-testing/hardware_testing/liquid_sense/post_process.py +++ b/hardware-testing/hardware_testing/liquid_sense/post_process.py @@ -1,6 +1,5 @@ """Post process script csvs.""" import csv -import gspread import math import os import statistics @@ -9,6 +8,16 @@ from hardware_testing.data import ui +try: + from abr_testing.automation import google_sheets_tool +except ImportError: + ui.print_error( + "Unable to import abr repo if this isn't a simulation push the abr_testing package" + ) + from . import google_sheets_tool # type: ignore[no-redef] + + pass + COL_TRIAL_CONVERSION = { 1: "E", 2: "H", @@ -170,7 +179,7 @@ def process_csv_directory( # noqa: C901 google_sheet.batch_update_cells( pressure_header_for_google_sheet, "H", 10, sheet_id ) - except gspread.exceptions.APIError: + except google_sheets_tool.google_interaction_error: ui.print_error("Header did not write on google sheet.") # we want to line up the z height's of each trial at time==0 # to do this we drop the results at the beginning of each of the trials @@ -243,7 +252,7 @@ def process_csv_directory( # noqa: C901 google_sheet.batch_update_cells( sheet_name, transposed_pressure_rows, "H", 11, sheet_id ) - except gspread.exceptions.APIError: + except google_sheets_tool.google_interaction_error: ui.print_error("Did not write pressure data to google sheet.") if google_drive: new_folder_id = google_drive.create_folder(new_folder_name) @@ -299,7 +308,7 @@ def process_google_sheet( [accuracy, precision, 100.0 - 100.0 * repeatability_error], ] google_sheet.batch_update_cells(sheet_name, summary, "D", 2, sheet_id) - except gspread.exceptions.APIError: + except google_sheets_tool.google_interaction_error: ui.print_error("stats didn't work.") # Create Graphs diff --git a/hardware-testing/hardware_testing/liquid_sense/report.py b/hardware-testing/hardware_testing/liquid_sense/report.py index acca567025f..ba7332077a6 100644 --- a/hardware-testing/hardware_testing/liquid_sense/report.py +++ b/hardware-testing/hardware_testing/liquid_sense/report.py @@ -1,13 +1,21 @@ """Format the csv report for a liquid-sense run.""" -import gspread import statistics from typing import List, Union, Optional -from abr_testing.automation import google_sheets_tool - from hardware_testing.data import ui +try: + from abr_testing.automation import google_sheets_tool +except ImportError: + ui.print_error( + "Unable to import abr repo if this isn't a simulation push the abr_testing package" + ) + from . import google_sheets_tool # type: ignore[no-redef] + + pass + + from hardware_testing.data.csv_report import ( CSVReport, CSVSection, @@ -176,7 +184,7 @@ def store_baseline_trial( if google_sheet: try: google_sheet.update_cell(sheet_title, 9, 2, height) - except gspread.exceptions.APIError: + except google_sheets_tool.google_interaction_error: ui.print_error("did not store baseline trial on google sheet.") report( "TRIALS", @@ -250,7 +258,7 @@ def store_trial( google_sheet.batch_update_cells( trial_for_google_sheet, "A", 11 + int(trial), sheet_id ) - except gspread.exceptions.APIError: + except google_sheets_tool.google_interaction_error: ui.print_error(f"did not log trial {trial+1} to google sheet.")