Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Features/unification artifacts #1920

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

sfc-gh-astus
Copy link
Contributor

@sfc-gh-astus sfc-gh-astus commented Dec 4, 2024

Pre-review checklist

  • I've confirmed that instructions included in README.md are still correct after my changes in the codebase.
  • I've added or updated automated unit tests to verify correctness of my new code.
  • I've added or updated integration tests to verify correctness of my new code.
  • I've confirmed that my changes are working by executing CLI's commands manually on MacOS.
  • I've confirmed that my changes are working by executing CLI's commands manually on Windows.
  • I've confirmed that my changes are up-to-date with the target branch.
  • I've described my changes in the release notes.
  • I've described my changes in the section below.

Changes description

  • Added support for glob pattern in artifact paths in snowflake.yml for Streamlit.
  • Added support for glob pattern in artifact paths in snowflake.yml for Snowpark, requires ENABLE_SNOWPARK_GLOB_SUPPORT feature flag.
  • Extracted artifacts common logic to common package.

@sfc-gh-astus sfc-gh-astus requested review from a team as code owners December 4, 2024 17:04
@sfc-gh-bdufour sfc-gh-bdufour force-pushed the features/unification-artifacts branch 2 times, most recently from 85d1c72 to 9cb87b3 Compare December 9, 2024 21:15
@sfc-gh-astus
Copy link
Contributor Author

Check if --project in streamlit works on this branch.

@sfc-gh-astus sfc-gh-astus force-pushed the features/unification-artifacts branch from bf62cfb to 7cd92a3 Compare December 12, 2024 17:53
@sfc-gh-astus sfc-gh-astus changed the title [DO NOT MERGE] Features/unification artifacts Features/unification artifacts Dec 12, 2024
@sfc-gh-astus sfc-gh-astus force-pushed the features/unification-artifacts branch from 2bee685 to c15cca5 Compare December 13, 2024 10:07
@sfc-gh-astus sfc-gh-astus force-pushed the features/unification-artifacts branch 2 times, most recently from 1ce276f to 1d6e6c1 Compare January 8, 2025 13:54
or (isinstance(artifact, PathMapping) and glob.has_magic(artifact.src))
) and FeatureFlag.ENABLE_SNOWPARK_GLOB_SUPPORT.is_disabled():
raise ValueError(
"If you want to use glob patterns in artifacts, you need to enable the Snowpark new build feature flag (ENABLE_SNOWPARK_GLOB_SUPPORT=true)"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"If you want to use glob patterns in artifacts, you need to enable the Snowpark new build feature flag (ENABLE_SNOWPARK_GLOB_SUPPORT=true)"
"If you want to use glob patterns in artifacts, you need to enable the Snowpark new build feature flag (enable_snowpark_glob_support=true)"

I'm pretty sure that feature flags are read only as lowercase from config.toml. SNOWFLAKE_CLI_FEATURES_ENABLE... env variable also works

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed


def remove_up_bundle_root(self) -> None:
if self.bundle_root.exists():
rmtree(self.bundle_root)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use SecurePath.rmdir(recursive=True) instead of shutil.rmtree

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

ssrc.copy(dst)
else:
# 1. Create a new directory in the deploy root
dst.mkdir(exist_ok=True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
dst.mkdir(exist_ok=True)
SecurePath(dst).mkdir(exist_ok=True)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

for root, _, files in sorted(os.walk(absolute_src, followlinks=True)):
relative_root = Path(root).relative_to(absolute_src)
absolute_root_in_deploy = Path(dst, relative_root)
absolute_root_in_deploy.mkdir(parents=True, exist_ok=True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
absolute_root_in_deploy.mkdir(parents=True, exist_ok=True)
SecurePath(absolute_root_in_deploy).mkdir(parents=True, exist_ok=True)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

class BundleMap:
"""
Computes the mapping between project directory artifacts (aka source artifacts) to their deploy root location
(aka destination artifact). This information is primarily used when bundling a native applications project.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docstring mentions Native Apps- we probably should make it CLI-wide

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed


def __init__(self, *, project_root: Path, deploy_root: Path):
# If a relative path ends up here, it's a bug in the app and can lead to other
# subtle bugs as paths would be resolved relative to the current working directory.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this docstring just copied from Native App application?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is

Returns the canonical version of a source path, relative to the project root.
"""
absolute_src = self._absolute_src(src)
return absolute_src.relative_to(self._project_root)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if artifact is in a different subtree? Do we handle the error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is nativeapp code moved to common package.

:param deploy_root: The directory where artifacts should be copied to. Must be an absolute path.
"""

def __init__(self, *, project_root: Path, deploy_root: Path):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sfc-gh-pczajka - shouldn't we use SecurePath everywhere? What's your opinion on this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wherever possible - so if it won't cause cascade of changes, I'd change Path to SecurePath.
I remember that refactor to use it everywhere was problematic

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will cause cascade :( , there will be a lot of changes in nativeapp code.



@dataclass(unsafe_hash=True)
class Artefact:
"""Helper for getting paths related to given artefact."""

project_root: Path
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this logic to main bundle map files? It seems quite similiar

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Artefact logic is only for Snowpark, for me better fits here.

)
for artifact in self._entity_model.artifacts
],
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bundle is an action, so it should not return bundle but rather copy the files

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

sfc-gh-astus and others added 11 commits January 13, 2025 14:54
* Added glob support for Snowpark and Streamlit

* Added glob support for Snowpark and Streamlit

* Added glob support for Snowpark and Streamlit

* Changed PathMapping.src to Path

* Changes after review

* Changes after review 2

* Revert "Changed PathMapping.src to Path"

This reverts commit 3eb543d.

* Changes after review 3

* Changes after review 4

* Added full global support

* Renamed feature flag and added release notes

* Removed or None
#1909)

Moved Snowpark and Streamlit artifacts to separate directory in output/deploy
@sfc-gh-astus sfc-gh-astus force-pushed the features/unification-artifacts branch from 1d6e6c1 to 517a85f Compare January 13, 2025 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants