Skip to content

Commit

Permalink
defer pydantic import so its an optional dep
Browse files Browse the repository at this point in the history
  • Loading branch information
cisaacstern committed Nov 16, 2023
1 parent 6247c29 commit 07be8f5
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions pangeo_forge_runner/meta_yaml/schema.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
from dataclasses import dataclass
from typing import List, Union

try:
from pydantic.dataclasses import dataclass
except (ImportError, ModuleNotFoundError):
from dataclasses import dataclass


@dataclass
class RecipeObject:
Expand Down Expand Up @@ -44,18 +40,29 @@ class Bakery:


@dataclass
class MetaYaml:
class MetaYamlMinimal:
# TODO: this should always be a list
# recipes: List[Union[RecipeObject, RecipeDictObject]]
recipes: Union[List[RecipeObject], RecipeDictObject]


@dataclass
class MetaYamlExtended(MetaYamlMinimal):
title: str
description: str
pangeo_forge_version: str
pangeo_notebook_version: str
recipes: Union[List[RecipeObject], RecipeDictObject]
provenance: Provenance
maintainers: List[Maintainer]
bakery: Bakery


def get_schema():
from pydantic import TypeAdapter
from pydantic.dataclasses import dataclass as pydantic_dataclass

@pydantic_dataclass
class MetaYamlExtendedModel(MetaYamlExtended):
pass

return TypeAdapter(MetaYaml).json_schema()
return TypeAdapter(MetaYamlExtendedModel).json_schema()

0 comments on commit 07be8f5

Please sign in to comment.