Skip to content

Commit f60a1d8

Browse files
Studio: add recipe and config json to outputs for downloading (#435)
* add recipe and config to output * refactor * path guard * Potential fix for code scanning alert no. 21: Uncontrolled data used in path expression Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * format * fix 404 comment * handle firebase recipe, serialize it before passing to s3 * save recipe data directly to outputs * remove unused import * one more unused import --------- Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 92657b0 commit f60a1d8

3 files changed

Lines changed: 36 additions & 4 deletions

File tree

cellpack/autopack/DBRecipeHandler.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,27 @@ def upload_job_status(self, job_id, status, result_path=None, error_message=None
566566
},
567567
)
568568

569-
def upload_packing_results_workflow(self, source_folder, recipe_name, job_id):
569+
def save_recipe_and_config_to_output(self, output_folder, config_data, recipe_data):
570+
output_path = Path(output_folder)
571+
572+
recipe_output_path = output_path / "recipe.json"
573+
with open(recipe_output_path, "w") as f:
574+
json.dump(recipe_data, f, indent=2)
575+
logging.debug(f"Saved recipe to {recipe_output_path}")
576+
577+
config_path = output_path / "config.json"
578+
with open(config_path, "w") as f:
579+
json.dump(config_data, f, indent=2)
580+
logging.debug(f"Saved config to {config_path}")
581+
582+
def upload_packing_results_workflow(
583+
self,
584+
source_folder,
585+
recipe_name,
586+
job_id,
587+
config_data,
588+
recipe_data,
589+
):
570590
"""
571591
Complete packing results upload workflow including folder preparation and s3 upload
572592
"""
@@ -586,10 +606,15 @@ def upload_packing_results_workflow(self, source_folder, recipe_name, job_id):
586606

587607
logging.debug(f"outputs will be copied to: {s3_upload_folder}")
588608

589-
# copy outputs to unique upload folder
590609
s3_upload_folder.mkdir(parents=True, exist_ok=True)
591610
shutil.copytree(source_folder, s3_upload_folder, dirs_exist_ok=True)
592611

612+
if recipe_data and config_data:
613+
self.save_recipe_and_config_to_output(
614+
output_folder=s3_upload_folder,
615+
config_data=config_data,
616+
recipe_data=recipe_data,
617+
)
593618
upload_result = self.upload_outputs_to_s3(
594619
output_folder=s3_upload_folder,
595620
recipe_name=recipe_name,

cellpack/autopack/loaders/recipe_loader.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,10 @@ def _read(self, resolve_inheritance=True, use_docker=False):
208208
formatted_error = RecipeValidator.format_validation_error(e)
209209
raise ValueError(f"Recipe validation failed:\n{formatted_error}")
210210

211+
# keep a serializable copy before converting to class instances
212+
# this ensures the original data (human-readable) is available for download in the UI
213+
self.serializable_recipe_data = copy.deepcopy(recipe_data)
214+
211215
if "objects" in recipe_data:
212216
for _, obj in recipe_data["objects"].items():
213217
reps = obj["representations"] if "representations" in obj else {}

cellpack/bin/pack.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ def pack(
3939
"""
4040
packing_config_data = ConfigLoader(config_path, docker).config
4141

42-
recipe_data = RecipeLoader(
42+
recipe_loader = RecipeLoader(
4343
recipe, packing_config_data["save_converted_recipe"], docker
44-
).recipe_data
44+
)
45+
recipe_data = recipe_loader.recipe_data
4546
analysis_config_data = {}
4647
if analysis_config_path is not None:
4748
analysis_config_data = AnalysisConfigLoader(analysis_config_path).config
@@ -92,6 +93,8 @@ def pack(
9293
source_folder=env.out_folder,
9394
recipe_name=recipe_data["name"],
9495
job_id=job_id,
96+
config_data=packing_config_data,
97+
recipe_data=recipe_loader.serializable_recipe_data,
9598
)
9699

97100

0 commit comments

Comments
 (0)