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

Merged
merged 15 commits into from
Jan 17, 2025
Merged

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
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 sfc-gh-astus force-pushed the features/unification-artifacts branch 3 times, most recently from 878d715 to 9b6b495 Compare January 14, 2025 14:18
RELEASE-NOTES.md Outdated
@@ -41,6 +41,8 @@
* Add `snow spcs service metrics` command to fetch service metrics:
* Supports filtering by service name, container name, instance ID, and time intervals (`--since`, `--until`).
* Use `--all` to fetch all columns.
* 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.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any change to existing behavior?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Streamlit is changed, Snowpark needs feature flag enabled, otherwise stays the same.

@pytest.mark.parametrize(
"artifact, local_path, stage_path",
[
("src", bundle_root / "src.zip", "/"),
Copy link
Contributor

Choose a reason for hiding this comment

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

All paths in tests seem to start on src/. Do we support glob patterns like **/snowpark/*.py?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, ** introduce more complexity, so I decided to not add that. This PR is huge even without **.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added that to release notes.

@sfc-gh-jsikorski sfc-gh-jsikorski self-requested a review January 15, 2025 10:40
sfc-gh-pczajka
sfc-gh-pczajka previously approved these changes Jan 15, 2025
@sfc-gh-jsikorski sfc-gh-jsikorski self-requested a review January 15, 2025 13:05
RELEASE-NOTES.md Show resolved Hide resolved
src/snowflake/cli/api/project/schemas/entities/common.py Outdated Show resolved Hide resolved
@@ -214,6 +222,43 @@ def _standardize(packages: List[str]) -> Set[str]:
return _standardize(old_dependencies) != _standardize(new_dependencies)


def map_path_mapping_to_artifact(
project_paths: SnowparkProjectPaths, artifacts: List[PathMapping]
) -> List[Artefact]:
Copy link
Contributor

Choose a reason for hiding this comment

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

minor: would be nice to use one spelling for Artifact throughout the code base :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will do this in next PR.

if (
(isinstance(artifact, str) and glob.has_magic(artifact))
or (isinstance(artifact, PathMapping) and glob.has_magic(artifact.src))
) and FeatureFlag.ENABLE_SNOWPARK_GLOB_SUPPORT.is_disabled():
Copy link
Contributor

Choose a reason for hiding this comment

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

How do we know if user is intending to use glob pattern or not? If we can know the intent, then what's the purpose of the feature flag?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I check if artifact path has glob magic. Feature flag changes build and deploy commands behaviour, they use deploy/bundle/... directory.

return False
return re.search(r"\.[a-zA-Z0-9]{2,4}$", self.dest) is not None

def _path_until_asterisk(self) -> Path:
Copy link
Contributor

Choose a reason for hiding this comment

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

For this glob logic, isn't it already implement for native apps?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't understand the question.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry let me rephrase. This Artifact class, can't it also be used for Native Apps and other entities? If not, what's special about Snowpark artifacts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In Snowpark we build zip files for artifacts which are not single file. It is easier to import one zip file than multiple py files. Artifact class should be used only in Snowpark.

)

return self
@field_validator("artifacts")
Copy link
Contributor

Choose a reason for hiding this comment

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

why aren't we using ArtifactsBase?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What is ArtefactsBase? Can't find in code.

Copy link
Contributor

Choose a reason for hiding this comment

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

sorry I meant ArtifactsBaseModel (now EntityModelBaseWithArtifacts)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point! There is no problem with Snowpark, but Streamlit's artifacts were optional and when I changed to EntityModelBaseWithArtifacts now are required. It is BCR, I will talk with the team what we want to do with it.

SecurePath(self.bundle_root).rmdir(recursive=True)


def bundle_root(root: Path, app_type: str | None = None) -> Path:
Copy link
Contributor

Choose a reason for hiding this comment

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

why is app_type in the path?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To separate Streamlit and Snowpark artifacts, you can run

snowpark build
streamlit deploy
snowpark deploy

Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't we use entity ids instead, since you have multiple entities of each?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There was that idea before but would introduce more complexity, so we decided to go simple way at the beginning.

sfc-gh-astus and others added 2 commits January 16, 2025 13:15
* 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
@sfc-gh-astus sfc-gh-astus force-pushed the features/unification-artifacts branch from 1a17d7e to 6ef2d27 Compare January 16, 2025 12:15
@sfc-gh-astus sfc-gh-astus merged commit 1556a0d into main Jan 17, 2025
34 checks passed
@sfc-gh-astus sfc-gh-astus deleted the features/unification-artifacts branch January 17, 2025 09:06
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.

6 participants