Skip to content

Commit

Permalink
[Config] YAML dump convention (#5577)
Browse files Browse the repository at this point in the history
  • Loading branch information
moranbental committed May 19, 2024
1 parent f87f68f commit 5f8ae40
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions mlrun/frameworks/_dl_common/loggers/tensorboard_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,13 +648,13 @@ def _markdown_print(value: Any, tabs: int = 0):
if isinstance(value, list):
if len(value) == 0:
return ""
text = "\n" + yaml.dump(value)
text = "\n" + yaml.safe_dump(value)
text = " \n".join([" " * tabs + line for line in text.splitlines()])
return text
if isinstance(value, dict):
if len(value) == 0:
return ""
text = yaml.dump(value)
text = yaml.safe_dump(value)
text = " \n".join(
[" " * tabs + "- " + line for line in text.splitlines()]
)
Expand Down
4 changes: 2 additions & 2 deletions mlrun/package/utils/_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,11 @@ def write(cls, obj: Union[list, dict], file_path: str, **dump_kwargs: dict):
:param obj: The object to write.
:param file_path: The file path to write to.
:param dump_kwargs: Additional keyword arguments to pass to the `yaml.dump` method of the formatter in use.
:param dump_kwargs: Additional keyword arguments to pass to the `yaml.safe_dump` method of the formatter in use.
"""
dump_kwargs = dump_kwargs or cls.DEFAULT_DUMP_KWARGS
with open(file_path, "w") as file:
yaml.dump(obj, file, **dump_kwargs)
yaml.safe_dump(obj, file, **dump_kwargs)

@classmethod
def read(cls, file_path: str) -> Union[list, dict]:
Expand Down
2 changes: 1 addition & 1 deletion mlrun/runtimes/databricks_job/databricks_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def save_credentials(
credentials["DATABRICKS_CLUSTER_ID"] = cluster_id

with open(credentials_path, "w") as yaml_file:
yaml.dump(credentials, yaml_file, default_flow_style=False)
yaml.safe_dump(credentials, yaml_file, default_flow_style=False)


def run_mlrun_databricks_job(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def test_nothing(config):

def create_yaml_config(**kw):
tmp = NamedTemporaryFile(mode="wt", suffix=".yml", delete=False)
yaml.dump(kw, tmp, default_flow_style=False)
yaml.safe_dump(kw, tmp, default_flow_style=False)
tmp.flush()
return tmp.name

Expand Down
2 changes: 1 addition & 1 deletion tests/test_kfp.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def _assert_output_dir(output_dir, name, iterations=1):
with open(iteration_results_file) as file:
count = 0
for row in csv.DictReader(file):
print(yaml.dump(row))
print(yaml.safe_dump(row))
count += 1
assert count == 3, "didnt see expected iterations file output"

Expand Down

0 comments on commit 5f8ae40

Please sign in to comment.