Add BuildCompiler.plating: generate PUDU/Opentrons plating protocol from transformation results#49
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d2fede0d3f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| f"PLATING_DATA = {json.dumps(plating_data, indent=4)}\n\n" | ||
| f"ADVANCED_PARAMS = {json.dumps(advanced_params, indent=4)}\n\n" |
There was a problem hiding this comment.
Serialize script constants as Python literals
write_plating_protocol_script embeds plating_data/advanced_params into a Python file using json.dumps, which emits JSON tokens like true, false, and null. Those are not Python literals, so when users pass booleans or None in advanced_params (a common config case), the generated run_plating.py crashes with NameError during module evaluation under opentrons_simulate.
Useful? React with 👍 / 👎.
| candidate = Path(value) | ||
| else: | ||
| raise ValueError("Expected a dict, JSON string, or path to a JSON file.") | ||
|
|
||
| if candidate.exists(): |
There was a problem hiding this comment.
Parse JSON strings before probing filesystem paths
load_json_or_dict treats every string as a path first and calls Path.exists() before json.loads; for large but valid JSON strings (e.g., many well mappings), this can raise OSError: [Errno 36] File name too long and abort parsing. The function should attempt JSON parsing (or catch OSError and fall back) so valid JSON string input does not fail based on filename limits.
Useful? React with 👍 / 👎.
Motivation
BuildCompiler.plating(...)entry point to map transformation outputs into a PUDU-compatible plating protocol and simulate it with Opentrons tooling.bacterium_locationsformat for downstream protocol generation.Description
BuildCompiler.plating(...)which: normalizestransformation_results, writesplating_input.jsoncontainingplating_dataandadvanced_params, generates a self-containedrun_plating.pythatfrom pudu.plating import Platingand callsPlating(plating_data=PLATING_DATA, json_params=ADVANCED_PARAMS), invokes the simulation helper, and returns paths forplating_json,protocol_script, andsimulation_zip.src/buildcompiler/robotutils.py:load_json_or_dict,normalize_plating_data,write_plating_protocol_script, andrun_opentrons_script_to_zip(creates a temp working dir, runsopentrons_simulate, captures stdout/stderr/returncode, and zips protocol+JSON+logs).{'bacterium_locations': {...}},{'strain_locations': {...}},{'thermocycler_wells': {...}}, or a raw well map like{'A1': 'strain_1'}and returns{'bacterium_locations': {...}}.BuildCompilerand added an optional automation dependencypudupyunder[project.optional-dependencies]inpyproject.toml.README.mddemonstrating input shape,advanced_params, and callingcompiler.plating(...).Testing
python -m unittest tests/test_plating.py, which executed 7 tests and completed successfully (all tests passed).subprocess.runin tests to validaterun_opentrons_script_to_zipwritessimulate_stdout.txt,simulate_stderr.txt, andsimulate_returncode.txtinto the zip (test passed).ruffon modified files and received no issues.opentrons_simulateinvocation is exercised in production usage but is mocked in unit tests.Codex Task