Skip to content

Commit

Permalink
tweak a few things to avoid explicit dependency on gspread in hardwar…
Browse files Browse the repository at this point in the history
…e-testing, and also ignore import errors during simulation
  • Loading branch information
ryanthecoder committed May 31, 2024
1 parent d4d36fc commit 5e50c2d
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 11 deletions.
6 changes: 6 additions & 0 deletions abr-testing/abr_testing/automation/google_sheets_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand Down
9 changes: 8 additions & 1 deletion hardware-testing/hardware_testing/liquid_sense/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
10 changes: 9 additions & 1 deletion hardware-testing/hardware_testing/liquid_sense/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {
Expand Down
17 changes: 13 additions & 4 deletions hardware-testing/hardware_testing/liquid_sense/post_process.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Post process script csvs."""
import csv
import gspread
import math
import os
import statistics
Expand All @@ -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",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
18 changes: 13 additions & 5 deletions hardware-testing/hardware_testing/liquid_sense/report.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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.")


Expand Down

0 comments on commit 5e50c2d

Please sign in to comment.