Skip to content

Commit

Permalink
fix(alias): add support for optional alias
Browse files Browse the repository at this point in the history
  • Loading branch information
mostaphaRoudsari committed Mar 19, 2021
1 parent fc77ca5 commit deda3bc
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 5 deletions.
12 changes: 11 additions & 1 deletion pollination_dsl/alias/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class _InputAliasBase(BaseModel):
description: str = None
default: Any = None
spec: Dict = None
optional: bool = False
platform: List[str] = Field(
...,
description='Name of the client platform (e.g. Grasshopper, Revit, etc). The '
Expand All @@ -43,11 +44,20 @@ class _InputAliasBase(BaseModel):
description='List of process actions to process the input or output value.'
)

@property
def required(self):
if self.optional:
return False
elif self.default is not None:
return False
else:
return True

def to_queenbee(self):
"""Convert this input to a Queenbee input alias."""
func = _inputs_mapper[self.__class__.__name__]
data = {
'required': True if self.default is None else False,
'required': self.required,
'name': self.name,
'default': self.default,
'description': self.description,
Expand Down
11 changes: 11 additions & 0 deletions pollination_dsl/alias/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,33 @@ class _OutputAliasBase(BaseModel):
name: str = Field(...)
annotations: Dict = None
description: str = None
optional: bool = False

platform: List[str] = Field(
...,
description='Name of the client platform (e.g. Grasshopper, Revit, etc). The '
'value can be any strings as long as it has been agreed between client-side '
'developer and author of the recipe.'
)

handler: List[IOAliasHandler] = Field(
...,
description='List of process actions to process the input or output value.'
)

@property
def required(self):
if self.optional:
return False
else:
return True

def to_queenbee(self):
"""Convert this output to a Queenbee DAG output."""
func = _outputs_mapper[self.__class__.__name__]
data = {
'name': self.name,
'required': self.required,
'description': self.description,
'annotations': self.annotations,
'platform': self.platform,
Expand Down
2 changes: 1 addition & 1 deletion pollination_dsl/dag/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class _InputBase(BaseModel):
default: Any = None
spec: Dict = None
alias: List[InputAliasTypes] = None
optional: Any = None
optional: bool = False

@validator('alias', always=True)
def empty_list_alias(cls, v):
Expand Down
2 changes: 1 addition & 1 deletion pollination_dsl/dag/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class _OutputBase(BaseModel):
annotations: Dict = None
description: str = None
alias: List[OutputAliasTypes] = None
optional: Any = None
optional: bool = False

@validator('source')
def change_self_to_inputs(cls, v):
Expand Down
2 changes: 1 addition & 1 deletion pollination_dsl/function/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class _InputBase(BaseModel):
description: Any = None
default: str = None
spec: Dict = None
optional: Any = None
optional: bool = False

@property
def __decorator__(self) -> str:
Expand Down
2 changes: 1 addition & 1 deletion pollination_dsl/function/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class _OutputBase(BaseModel):
path: str
annotations: Dict = None
description: str = None
optional: Any = None
optional: bool = False

@validator('path')
def change_self_to_inputs(cls, v):
Expand Down

0 comments on commit deda3bc

Please sign in to comment.