From b8ad2965372157e4f9e9bdbde2e5cd109557be5f Mon Sep 17 00:00:00 2001 From: Ruge Li Date: Thu, 20 Jun 2024 14:26:44 -0700 Subject: [PATCH 1/2] get metadata in upload.py instead --- cellpack/autopack/loaders/recipe_loader.py | 10 ---------- cellpack/bin/upload.py | 21 ++++++++++++++++++++- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/cellpack/autopack/loaders/recipe_loader.py b/cellpack/autopack/loaders/recipe_loader.py index fd21717e..cf0be99b 100644 --- a/cellpack/autopack/loaders/recipe_loader.py +++ b/cellpack/autopack/loaders/recipe_loader.py @@ -132,16 +132,6 @@ def _sanitize_format_version(recipe_data): format_version = recipe_data["format_version"] return format_version - def get_only_recipe_metadata(self): - recipe_meta_data = { - "format_version": self.recipe_data["format_version"], - "version": self.recipe_data["version"], - "name": self.recipe_data["name"], - "bounding_box": self.recipe_data["bounding_box"], - "composition": {}, - } - return recipe_meta_data - def _migrate_version(self, old_recipe): converted = False if old_recipe["format_version"] == "1.0": diff --git a/cellpack/bin/upload.py b/cellpack/bin/upload.py index 62f1b9f1..60ef9a47 100644 --- a/cellpack/bin/upload.py +++ b/cellpack/bin/upload.py @@ -8,6 +8,25 @@ from cellpack.autopack.loaders.recipe_loader import RecipeLoader +def get_recipe_metadata(loader): + """ + Fetches and returns the metadata of the recipe for uploading + """ + try: + recipe_meta_data = { + "format_version": loader.recipe_data["format_version"], + "version": loader.recipe_data["version"], + "name": loader.recipe_data["name"], + "bounding_box": loader.recipe_data["bounding_box"], + "composition": {}, + } + if "grid_file_path" in loader.recipe_data: + recipe_meta_data["grid_file_path"] = loader.recipe_data["grid_file_path"] + return recipe_meta_data + except KeyError as e: + sys.exit(f"Recipe metadata is missing. {e}") + + def upload( recipe_path, db_id=DATABASE_IDS.FIREBASE, @@ -23,7 +42,7 @@ def upload( if FirebaseHandler._initialized: recipe_loader = RecipeLoader(recipe_path) recipe_full_data = recipe_loader._read(resolve_inheritance=False) - recipe_meta_data = recipe_loader.get_only_recipe_metadata() + recipe_meta_data = get_recipe_metadata(recipe_loader) recipe_db_handler = DBUploader(db_handler) recipe_db_handler.upload_recipe(recipe_meta_data, recipe_full_data) else: From 35e2dfc17246c7d452bc652acd23dc7ca18dd9da Mon Sep 17 00:00:00 2001 From: Ruge Li Date: Mon, 24 Jun 2024 15:43:46 -0700 Subject: [PATCH 2/2] update docstring --- cellpack/bin/upload.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cellpack/bin/upload.py b/cellpack/bin/upload.py index 60ef9a47..9a932ae1 100644 --- a/cellpack/bin/upload.py +++ b/cellpack/bin/upload.py @@ -10,7 +10,7 @@ def get_recipe_metadata(loader): """ - Fetches and returns the metadata of the recipe for uploading + Extracts and returns essential metadata from a recipe for uploading """ try: recipe_meta_data = {