diff --git a/protocol-designer/src/file-data/__tests__/createFile.test.ts b/protocol-designer/src/file-data/__tests__/createFile.test.ts index cf651c62733..392998fe000 100644 --- a/protocol-designer/src/file-data/__tests__/createFile.test.ts +++ b/protocol-designer/src/file-data/__tests__/createFile.test.ts @@ -106,7 +106,8 @@ describe('createFile selector', () => { fileMetadata, OT2_ROBOT_TYPE, entities, - v7Fixture.initialRobotState + v7Fixture.initialRobotState, + v7Fixture.robotStateTimeline ) // This is just a quick smoke test to make sure createPythonFile() produces // something that looks like a Python file. The individual sections of the @@ -133,6 +134,11 @@ def run(protocol: protocol_api.ProtocolContext): mockPythonName = protocol.load_labware("fixture_trash", "12") mockPythonName = protocol.load_labware("fixture_tiprack_10_ul", "1") mockPythonName = protocol.load_labware("fixture_96_plate", "7") + + # PROTOCOL STEPS + + # Step 1: + pass `.trimStart() ) }) diff --git a/protocol-designer/src/file-data/selectors/fileCreator.ts b/protocol-designer/src/file-data/selectors/fileCreator.ts index 2a0d99c8cc3..e9ddde221c7 100644 --- a/protocol-designer/src/file-data/selectors/fileCreator.ts +++ b/protocol-designer/src/file-data/selectors/fileCreator.ts @@ -310,14 +310,21 @@ export const createPythonFile: Selector = createSelector( getRobotType, stepFormSelectors.getInvariantContext, getInitialRobotState, - (fileMetadata, robotType, invariantContext, robotState) => { + getRobotStateTimeline, + ( + fileMetadata, + robotType, + invariantContext, + robotState, + robotStateTimeline + ) => { return ( [ // Here are the sections of the Python file: pythonImports(), pythonMetadata(fileMetadata), pythonRequirements(robotType), - pythonDefRun(invariantContext, robotState), + pythonDefRun(invariantContext, robotState, robotStateTimeline), ] .filter(section => section) // skip any blank sections .join('\n\n') + '\n' diff --git a/protocol-designer/src/file-data/selectors/pythonFile.ts b/protocol-designer/src/file-data/selectors/pythonFile.ts index 0643b406439..2896dfb320b 100644 --- a/protocol-designer/src/file-data/selectors/pythonFile.ts +++ b/protocol-designer/src/file-data/selectors/pythonFile.ts @@ -11,6 +11,7 @@ import type { InvariantContext, LabwareEntities, ModuleEntities, + Timeline, TimelineFrame, } from '@opentrons/step-generation' import type { RobotType } from '@opentrons/shared-data' @@ -135,9 +136,22 @@ export function getLoadLabware( return pythonLabware ? `# Load Labware:\n${pythonLabware}` : '' } +export function stepCommands(robotStateTimeline: Timeline): string { + return ( + '# PROTOCOL STEPS\n\n' + + robotStateTimeline.timeline + .map( + (timelineFrame, idx) => + `# Step ${idx + 1}:\n${timelineFrame.python || 'pass'}` + ) + .join('\n\n') + ) +} + export function pythonDefRun( invariantContext: InvariantContext, - robotState: TimelineFrame + robotState: TimelineFrame, + robotStateTimeline: Timeline ): string { const { moduleEntities, labwareEntities } = invariantContext const { modules, labware } = robotState @@ -152,7 +166,7 @@ export function pythonDefRun( // loadInstruments(), // defineLiquids(), // loadLiquids(), - // stepCommands(), + stepCommands(robotStateTimeline), ] const functionBody = sections