Skip to content

Commit

Permalink
Changed PathMapping.src to Path
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-astus committed Nov 6, 2024
1 parent 36d208d commit 3eb543d
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 11 deletions.
7 changes: 3 additions & 4 deletions src/snowflake/cli/_plugins/nativeapp/artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,19 +303,18 @@ def _add(self, src: Path, dest: Path, map_as_child: bool) -> None:
src=canonical_src, dest=canonical_dest, dest_is_dir=dest_is_dir
)

def _add_mapping(self, src: str, dest: Optional[str] = None):
def _add_mapping(self, src: Path, dest: Optional[str] = None):
"""
Adds the specified artifact rule to this instance. The source should be relative to the project directory. It
is interpreted as a file, directory or glob pattern. If the destination path is not specified, each source match
is mapped to an identical path in the deploy root.
"""
match_found = False

src_path = Path(src)
if src_path.is_absolute():
if src.is_absolute():
raise ArtifactError("Source path must be a relative path")

for resolved_src in self._project_root.glob(src):
for resolved_src in self._project_root.glob(str(src)):
match_found = True

if dest:
Expand Down
4 changes: 2 additions & 2 deletions src/snowflake/cli/_plugins/snowpark/snowpark_project_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ def get_artefact_dto(self, artifact_path: PathMapping) -> Artefact:
return Artefact(
project_root=self.project_root,
dest=artifact_path.dest,
path=Path(artifact_path.src),
path=artifact_path.src,
)
else:
return ArtefactOldBuild(
dest=artifact_path.dest,
path=self.path_relative_to_root(Path(artifact_path.src)),
path=self.path_relative_to_root(artifact_path.src),
)

def get_dependencies_artefact(self) -> Artefact:
Expand Down
2 changes: 1 addition & 1 deletion src/snowflake/cli/_plugins/streamlit/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def _put_streamlit_files(
deploy_root=streamlit_project_paths.deploy_root(),
)
for artifact in artifacts:
bundle_map.add(PathMapping(src=str(artifact.src), dest=artifact.dest))
bundle_map.add(PathMapping(src=artifact.src, dest=artifact.dest))

if streamlit_project_paths.deploy_root().exists():
rmtree(streamlit_project_paths.deploy_root())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from __future__ import annotations

from pathlib import Path
from typing import Any, Dict, List, Optional, Union

from pydantic import Field, field_validator
Expand All @@ -31,7 +32,7 @@ class ProcessorMapping(UpdatableModel):


class PathMapping(UpdatableModel):
src: str = Field(
src: Path = Field(
title="Source path or glob pattern (relative to project root)", default=None
)

Expand Down
4 changes: 2 additions & 2 deletions tests/helpers/__snapshots__/test_v1_to_v2.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@
type: string
stage: dev_deployment
artifacts:
- src: app/
- src: app
dest: my_snowpark_project
type: procedure
execute_as_caller: false
Expand All @@ -292,7 +292,7 @@
runtime: '3.10'
stage: dev_deployment
artifacts:
- src: app/
- src: app
dest: my_snowpark_project
type: function
test_streamlit:
Expand Down
3 changes: 2 additions & 1 deletion tests/project/test_project_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from pathlib import Path

import pytest
from pydantic import ValidationError
Expand Down Expand Up @@ -83,7 +84,7 @@ def test_project_schema_is_updated_correctly_from_dict(
pkg_model.update_from_dict(update_dict)
assert pkg_model.manifest == "app/manifest.yml"
assert pkg_model.distribution == "external"
assert pkg_model.artifacts[0].src == "app/*"
assert pkg_model.artifacts[0].src == Path("app/*")
assert pkg_model.meta.role == "test_role_2"


Expand Down

0 comments on commit 3eb543d

Please sign in to comment.