Skip to content

Commit

Permalink
Adding grid_file_path to recipe metadata for uploads (#268)
Browse files Browse the repository at this point in the history
* get metadata in upload.py instead

* update docstring
rugeli authored Jul 1, 2024
1 parent 91e18a9 commit d0b05e2
Showing 2 changed files with 20 additions and 11 deletions.
10 changes: 0 additions & 10 deletions cellpack/autopack/loaders/recipe_loader.py
Original file line number Diff line number Diff line change
@@ -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":
21 changes: 20 additions & 1 deletion cellpack/bin/upload.py
Original file line number Diff line number Diff line change
@@ -8,6 +8,25 @@
from cellpack.autopack.loaders.recipe_loader import RecipeLoader


def get_recipe_metadata(loader):
"""
Extracts and returns essential metadata from a 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:

0 comments on commit d0b05e2

Please sign in to comment.