MarcoM
12/01/2023, 10:42 AMMarvin
12/01/2023, 10:42 AMprefect block register -m prefect_aws
after installing the Prefect-AWS library. However, the documents do not provide a direct method to instantiate a block such as an AwsCredentials Block without importing the class AwsCredentials from prefect_aws.
The common practice in Python to dynamically instantiate a class involves importing the class, as you're currently doing with _globals()<name=model.name, **model.params|class_name>
. Avoiding this would likely require a different approach or design.
I would recommend reaching out to the Prefect community or support for more specific guidance on this issue.Kevin Grismore
12/01/2023, 11:01 AMsave()
, or is this meant to be an interface just for saving blocks?MarcoM
12/01/2023, 11:10 AMMarcoM
12/01/2023, 11:10 AMdef deploy(self, models: Union[Model, list[Model]]) -> None:
models = [models] if not isinstance(models, list) else models
for model in models:
model_name = model.name
model_obj = self.load_model_obj(model)
model_obj.save(name=model_name, overwrite=True)
def load_model_obj(self, model: Model) -> Block:
class_name = model.class_name
for param_name, param_value in model.params.items():
model.params[param_name] = self.expand_param_value(param_value)
model_obj = globals()[class_name](name=model.name, **model.params)#!!!capire come gestire questa cosa, al momento importiamo
return model_obj