Skip to content

Commit

Permalink
[NADE][Bugfix] Use Pyyaml instead of StrictYAML (#897)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-bgoel authored Mar 13, 2024
1 parent 1820607 commit 2b8558c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/snowflake/cli/plugins/nativeapp/artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
from pathlib import Path
from typing import List, Optional, Tuple, Union

import strictyaml
from click import ClickException
from snowflake.cli.api.constants import DEFAULT_SIZE_LIMIT_MB
from snowflake.cli.api.project.schemas.native_app.path_mapping import PathMapping
from snowflake.cli.api.secure_path import SecurePath
from yaml import safe_load


class DeployRootError(ClickException):
Expand Down Expand Up @@ -271,7 +271,7 @@ def find_version_info_in_manifest_file(
with SecurePath(manifest_file).open(
"r", read_file_limit_mb=DEFAULT_SIZE_LIMIT_MB
) as file:
manifest_content = strictyaml.load(file.read())
manifest_content = safe_load(file.read())

version_name: Optional[str] = None
patch_name: Optional[str] = None
Expand Down
16 changes: 9 additions & 7 deletions src/snowflake/cli/plugins/nativeapp/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
)
from snowflake.cli.api.secure_path import SecurePath
from snowflake.cli.api.utils.rendering import generic_render_template
from strictyaml import as_document, load
from yaml import dump
from yaml import dump, safe_dump, safe_load

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -154,17 +153,20 @@ def _replace_snowflake_yml_name_with_project(
path_to_snowflake_yml = SecurePath(target_directory) / "snowflake.yml"
contents = None

with path_to_snowflake_yml.open("r", read_file_limit_mb=DEFAULT_SIZE_LIMIT_MB) as f:
contents = load(f.read()).data
with path_to_snowflake_yml.open(
"r", read_file_limit_mb=DEFAULT_SIZE_LIMIT_MB
) as file:
contents = safe_load(file)

if (
("native_app" in contents)
(contents is not None)
and ("native_app" in contents)
and ("name" in contents["native_app"])
and (contents["native_app"]["name"] != project_identifier)
):
contents["native_app"]["name"] = project_identifier
with path_to_snowflake_yml.open("w") as f:
f.write(as_document(contents).as_yaml())
with path_to_snowflake_yml.open("w") as file:
safe_dump(contents, file, sort_keys=False)


def _validate_and_update_snowflake_yml(target_directory: Path, project_identifier: str):
Expand Down

0 comments on commit 2b8558c

Please sign in to comment.