1313
1414from azure .ai .ml ._restclient .v2021_10_01 import models
1515
16+ from azure .ai .ml ._utils .utils import dump_yaml
17+ from azure .ai .ml ._telemetry .logging_handler import in_jupyter_notebook
18+
1619from ._system_data import SystemData
1720
1821
@@ -39,15 +42,23 @@ def __init__(
3942 :type description: str, optional
4043 :param tags: Tag dictionary. Tags can be added, removed, and updated., defaults to None
4144 :type tags: Dict, optional
42- :param properties: The asset property dictionary., defaults to None
45+ :param properties: The asset property dictionary. Defaults to None
4346 :type properties: Dict, optional
47+ :param: print_as_yaml: If set to true, then printing out this resource will produce a YAML-formatted object.
48+ False will force a more-compact printing style. By default, the YAML output is only used in jupyter
49+ notebooks. Be aware that some bookkeeping values are shown only in the non-YAML output.
50+ :type print_as_yaml: bool, optional
4451 :param kwargs: A dictionary of additional configuration parameters.
4552 :type kwargs: dict
4653 """
4754 self .name = name
4855 self .description = description
4956 self .tags = dict (tags ) if tags else {}
5057 self .properties = dict (properties ) if properties else {}
58+ # Conditional assignment to prevent entity bloat when unused.
59+ print_as_yaml = kwargs .pop ("print_as_yaml" , in_jupyter_notebook ())
60+ if print_as_yaml :
61+ self .print_as_yaml = True
5162
5263 # Hide read only properties in kwargs
5364 self ._id = kwargs .pop ("id" , None )
@@ -184,4 +195,8 @@ def __repr__(self) -> str:
184195 return f"{ self .__class__ .__name__ } ({ var_dict } )"
185196
186197 def __str__ (self ) -> str :
198+ if hasattr (self , "print_as_yaml" ) and self .print_as_yaml :
199+ # pylint: disable=no-member
200+ yaml_serialized = self ._to_dict ()
201+ return dump_yaml (yaml_serialized , default_flow_style = False )
187202 return self .__repr__ ()
0 commit comments