Skip to content

Commit

Permalink
Merge branch 'chore_release-8.0.0' into EXEC-504-get-error-list-route
Browse files Browse the repository at this point in the history
  • Loading branch information
TamarZanzouri authored Aug 5, 2024
2 parents 7822aaf + 4500e21 commit 24f15e2
Show file tree
Hide file tree
Showing 141 changed files with 2,396 additions and 1,238 deletions.
2 changes: 1 addition & 1 deletion api/src/opentrons/cli/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ async def _do_analyze(protocol_source: ProtocolSource) -> RunResult:
protocol_source=protocol_source,
parse_mode=ParseMode.NORMAL,
run_time_param_values=None,
run_time_param_files=None,
run_time_param_paths=None,
)
except Exception as error:
err_id = "analysis-setup-error"
Expand Down
2 changes: 2 additions & 0 deletions api/src/opentrons/protocol_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from opentrons.protocols.parameters.exceptions import (
RuntimeParameterRequired as RuntimeParameterRequiredError,
)
from opentrons.protocols.parameters.types import CSVParameter

from .protocol_context import ProtocolContext
from .deck import Deck
Expand Down Expand Up @@ -74,6 +75,7 @@
"ALL",
"OFF_DECK",
"RuntimeParameterRequiredError",
"CSVParameter",
# For internal Opentrons use only:
"create_protocol_context",
"ProtocolEngineCoreRequiredError",
Expand Down
46 changes: 38 additions & 8 deletions api/src/opentrons/protocol_api/_parameter_context.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Parameter context for python protocols."""

import tempfile
from typing import List, Optional, Union, Dict

from opentrons.protocols.api_support.types import APIVersion
Expand All @@ -19,7 +19,7 @@
from opentrons.protocol_engine.types import (
RunTimeParameter,
PrimitiveRunTimeParamValuesType,
CSVRunTimeParamFilesType,
CSVRuntimeParamPaths,
FileInfo,
)

Expand Down Expand Up @@ -218,15 +218,15 @@ def set_parameters(
parameter.value = validated_value

def initialize_csv_files(
self, run_time_param_file_overrides: CSVRunTimeParamFilesType
self, run_time_param_file_overrides: CSVRuntimeParamPaths
) -> None:
"""Initializes the files for CSV parameters.
:meta private:
This is intended for Opentrons internal use only and is not a guaranteed API.
"""
for variable_name, file_id in run_time_param_file_overrides.items():
for variable_name, file_path in run_time_param_file_overrides.items():
try:
parameter = self._parameters[variable_name]
except KeyError:
Expand All @@ -240,11 +240,41 @@ def initialize_csv_files(
f"File Id was provided for the parameter '{variable_name}',"
f" but '{variable_name}' is not a CSV parameter."
)
# TODO(jbl 2024-08-02) This file opening should be moved elsewhere to provide more flexibility with files
# that may be opened as non-text or non-UTF-8
# The parent folder in the path will be the file ID, so we can use that to resolve that here
file_id = file_path.parent.name
file_name = file_path.name

# Read the contents of the actual file
with file_path.open() as csv_file:
contents = csv_file.read()

# Open a temporary file with write permissions and write contents to that
temporary_file = tempfile.NamedTemporaryFile("r+")
temporary_file.write(contents)
temporary_file.flush()

# Open a new file handler for the temporary file with read-only permissions and close the other
parameter_file = open(temporary_file.name, "r")
temporary_file.close()

parameter.file_info = FileInfo(id=file_id, name=file_name)
parameter.value = parameter_file

def close_csv_files(self) -> None:
"""Close all file handlers for CSV parameters.
parameter.file_info = FileInfo(id=file_id, name="")
# TODO (spp, 2024-07-16): set the file name and assign the file as parameter.value.
# Most likely, we will be creating a temporary file copy of the original
# to pass onto the protocol context
:meta private:
This is intended for Opentrons internal use only and is not a guaranteed API.
"""
for parameter in self._parameters.values():
if (
isinstance(parameter, csv_parameter_definition.CSVParameterDefinition)
and parameter.value is not None
):
parameter.value.close()

def export_parameters_for_analysis(self) -> List[RunTimeParameter]:
"""Exports all parameters into a protocol engine models for reporting in analysis.
Expand Down
Loading

0 comments on commit 24f15e2

Please sign in to comment.