Skip to content

Commit 5da6a68

Browse files
authored
Renamed Artefact (#2048)
1 parent 139ffad commit 5da6a68

File tree

5 files changed

+65
-65
lines changed

5 files changed

+65
-65
lines changed

src/snowflake/cli/_plugins/snowpark/commands.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
SnowparkEntities,
4040
SnowparkObject,
4141
SnowparkObjectManager,
42-
StageToArtefactMapping,
42+
StageToArtifactMapping,
4343
map_path_mapping_to_artifact,
4444
zip_and_copy_artifacts_to_deploy,
4545
)
@@ -198,11 +198,11 @@ def validate_all_artifacts_exists(
198198
project_paths: SnowparkProjectPaths, snowpark_entities: SnowparkEntities
199199
):
200200
for key, entity in snowpark_entities.items():
201-
for artefact in entity.artifacts:
202-
path = project_paths.get_artefact_dto(artefact).post_build_path
201+
for artifact in entity.artifacts:
202+
path = project_paths.get_artifact_dto(artifact).post_build_path
203203
if not path.exists():
204204
raise UsageError(
205-
f"Artefact {path} required for {entity.type} {key} does not exist."
205+
f"Artifact {path} required for {entity.type} {key} does not exist."
206206
)
207207

208208

@@ -222,39 +222,39 @@ def check_for_existing_objects(
222222

223223
def build_artifacts_mappings(
224224
project_paths: SnowparkProjectPaths, snowpark_entities: SnowparkEntities
225-
) -> Tuple[EntityToImportPathsMapping, StageToArtefactMapping]:
226-
stages_to_artifact_map: StageToArtefactMapping = defaultdict(set)
225+
) -> Tuple[EntityToImportPathsMapping, StageToArtifactMapping]:
226+
stages_to_artifact_map: StageToArtifactMapping = defaultdict(set)
227227
entities_to_imports_map: EntityToImportPathsMapping = defaultdict(set)
228228
for name, entity in snowpark_entities.items():
229229
stage = entity.stage
230230
required_artifacts = set()
231-
for artefact in entity.artifacts:
232-
artefact_dto = project_paths.get_artefact_dto(artefact)
233-
required_artifacts.add(artefact_dto)
234-
entities_to_imports_map[name].add(artefact_dto.import_path(stage))
231+
for artifact in entity.artifacts:
232+
artifact_dto = project_paths.get_artifact_dto(artifact)
233+
required_artifacts.add(artifact_dto)
234+
entities_to_imports_map[name].add(artifact_dto.import_path(stage))
235235
stages_to_artifact_map[stage].update(required_artifacts)
236236

237-
deps_artefact = project_paths.get_dependencies_artefact()
238-
if deps_artefact.post_build_path.exists():
239-
stages_to_artifact_map[stage].add(deps_artefact)
240-
entities_to_imports_map[name].add(deps_artefact.import_path(stage))
237+
deps_artifact = project_paths.get_dependencies_artifact()
238+
if deps_artifact.post_build_path.exists():
239+
stages_to_artifact_map[stage].add(deps_artifact)
240+
entities_to_imports_map[name].add(deps_artifact.import_path(stage))
241241
return entities_to_imports_map, stages_to_artifact_map
242242

243243

244-
def create_stages_and_upload_artifacts(stages_to_artifact_map: StageToArtefactMapping):
244+
def create_stages_and_upload_artifacts(stages_to_artifact_map: StageToArtifactMapping):
245245
stage_manager = StageManager()
246246
for stage, artifacts in stages_to_artifact_map.items():
247247
cli_console.step(f"Creating (if not exists) stage: {stage}")
248248
stage = FQN.from_stage(stage).using_context()
249249
stage_manager.create(fqn=stage, comment="deployments managed by Snowflake CLI")
250-
for artefact in artifacts:
251-
post_build_path = artefact.post_build_path
250+
for artifact in artifacts:
251+
post_build_path = artifact.post_build_path
252252
cli_console.step(
253-
f"Uploading {post_build_path.name} to {artefact.upload_path(stage)}"
253+
f"Uploading {post_build_path.name} to {artifact.upload_path(stage)}"
254254
)
255255
stage_manager.put(
256256
local_path=post_build_path,
257-
stage_path=artefact.upload_path(stage),
257+
stage_path=artifact.upload_path(stage),
258258
overwrite=True,
259259
)
260260

@@ -375,7 +375,7 @@ def build(
375375
)
376376

377377
if any(temp_deps_dir.path.iterdir()):
378-
dep_artifact = project_paths.get_dependencies_artefact()
378+
dep_artifact = project_paths.get_dependencies_artifact()
379379
cli_console.step(f"Creating {dep_artifact.path.name}")
380380
zip_dir(
381381
source=temp_deps_dir.path,
@@ -394,8 +394,8 @@ def build(
394394
if FeatureFlag.ENABLE_SNOWPARK_GLOB_SUPPORT.is_enabled():
395395
zip_and_copy_artifacts_to_deploy(artifacts, project_paths.bundle_root)
396396
else:
397-
for artefact in artifacts:
398-
artefact.build()
397+
for artifact in artifacts:
398+
artifact.build()
399399

400400
return MessageResult(f"Build done.")
401401

src/snowflake/cli/_plugins/snowpark/common.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
SnowparkEntityModel,
2828
)
2929
from snowflake.cli._plugins.snowpark.snowpark_project_paths import (
30-
Artefact,
30+
Artifact,
3131
SnowparkProjectPaths,
3232
)
3333
from snowflake.cli._plugins.snowpark.zipper import zip_dir_using_bundle_map
@@ -48,7 +48,7 @@
4848
log = logging.getLogger(__name__)
4949

5050
SnowparkEntities = Dict[str, SnowparkEntityModel]
51-
StageToArtefactMapping = Dict[str, set[Artefact]]
51+
StageToArtifactMapping = Dict[str, set[Artifact]]
5252
EntityToImportPathsMapping = Dict[str, set[str]]
5353

5454
DEFAULT_RUNTIME = "3.10"
@@ -224,22 +224,22 @@ def _standardize(packages: List[str]) -> Set[str]:
224224

225225
def map_path_mapping_to_artifact(
226226
project_paths: SnowparkProjectPaths, artifacts: List[PathMapping]
227-
) -> List[Artefact]:
228-
return [project_paths.get_artefact_dto(artifact) for artifact in artifacts]
227+
) -> List[Artifact]:
228+
return [project_paths.get_artifact_dto(artifact) for artifact in artifacts]
229229

230230

231231
def zip_and_copy_artifacts_to_deploy(
232-
artifacts: Set[Artefact] | List[Artefact], bundle_root: Path
232+
artifacts: Set[Artifact] | List[Artifact], bundle_root: Path
233233
) -> List[Path]:
234234
copied_files = []
235-
for artefact in artifacts:
235+
for artifact in artifacts:
236236
bundle_map = BundleMap(
237-
project_root=artefact.project_root,
237+
project_root=artifact.project_root,
238238
deploy_root=bundle_root,
239239
)
240-
bundle_map.add(PathMapping(src=str(artefact.path), dest=artefact.dest))
240+
bundle_map.add(PathMapping(src=str(artifact.path), dest=artifact.dest))
241241

242-
if artefact.path.is_file():
242+
if artifact.path.is_file():
243243
for (absolute_src, absolute_dest) in bundle_map.all_mappings(
244244
absolute=True, expand_directories=False
245245
):
@@ -250,7 +250,7 @@ def zip_and_copy_artifacts_to_deploy(
250250
)
251251
copied_files.append(absolute_dest)
252252
else:
253-
post_build_path = artefact.post_build_path
253+
post_build_path = artifact.post_build_path
254254
zip_dir_using_bundle_map(
255255
bundle_map=bundle_map,
256256
dest_zip=post_build_path,

src/snowflake/cli/_plugins/snowpark/snowpark_entity.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,9 @@ def bundle(
139139
)
140140
else:
141141
copied_files = []
142-
for artefact in artifacts:
143-
artefact.build()
144-
copied_files.append(artefact.post_build_path)
142+
for artifact in artifacts:
143+
artifact.build()
144+
copied_files.append(artifact.post_build_path)
145145
return copied_files
146146

147147
def check_if_exists(

src/snowflake/cli/_plugins/snowpark/snowpark_project_paths.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -41,30 +41,30 @@ def path_relative_to_root(self, artifact_path: Path) -> Path:
4141
return artifact_path
4242
return (self.project_root / artifact_path).resolve()
4343

44-
def get_artefact_dto(self, artifact_path: PathMapping) -> Artefact:
44+
def get_artifact_dto(self, artifact_path: PathMapping) -> Artifact:
4545
if FeatureFlag.ENABLE_SNOWPARK_GLOB_SUPPORT.is_enabled():
46-
return Artefact(
46+
return Artifact(
4747
project_root=self.project_root,
4848
bundle_root=self.bundle_root,
4949
dest=artifact_path.dest,
5050
path=Path(artifact_path.src),
5151
)
5252
else:
53-
return ArtefactOldBuild(
53+
return ArtifactOldBuild(
5454
dest=artifact_path.dest,
5555
path=self.path_relative_to_root(Path(artifact_path.src)),
5656
)
5757

58-
def get_dependencies_artefact(self) -> Artefact:
58+
def get_dependencies_artifact(self) -> Artifact:
5959
if FeatureFlag.ENABLE_SNOWPARK_GLOB_SUPPORT.is_enabled():
60-
return Artefact(
60+
return Artifact(
6161
project_root=self.project_root,
6262
bundle_root=self.bundle_root,
6363
dest=None,
6464
path=Path("dependencies.zip"),
6565
)
6666
else:
67-
return ArtefactOldBuild(
67+
return ArtifactOldBuild(
6868
dest=None, path=self.path_relative_to_root(Path("dependencies.zip"))
6969
)
7070

@@ -84,8 +84,8 @@ def bundle_root(self) -> Path:
8484

8585

8686
@dataclass(unsafe_hash=True)
87-
class Artefact:
88-
"""Helper for getting paths related to given artefact."""
87+
class Artifact:
88+
"""Helper for getting paths related to given artifact."""
8989

9090
project_root: Path
9191
bundle_root: Path
@@ -107,9 +107,9 @@ def __init__(
107107
self.dest = self.dest + "/"
108108

109109
@property
110-
def _artefact_name(self) -> str:
110+
def _artifact_name(self) -> str:
111111
"""
112-
Returns artefact name. Directories are mapped to corresponding .zip files.
112+
Returns artifact name. Directories are mapped to corresponding .zip files.
113113
For paths with glob patterns, the last part of the path is used.
114114
For files, the file name is used.
115115
"""
@@ -134,7 +134,7 @@ def _artefact_name(self) -> str:
134134
@property
135135
def post_build_path(self) -> Path:
136136
"""
137-
Returns post-build artefact path. Directories are mapped to corresponding .zip files.
137+
Returns post-build artifact path. Directories are mapped to corresponding .zip files.
138138
"""
139139
bundle_root = self.bundle_root
140140
path = (
@@ -144,11 +144,11 @@ def post_build_path(self) -> Path:
144144
)
145145
if self._is_dest_a_file():
146146
return bundle_root / self.dest # type: ignore
147-
return bundle_root / (self.dest or path) / self._artefact_name
147+
return bundle_root / (self.dest or path) / self._artifact_name
148148

149149
def upload_path(self, stage: FQN | str | None) -> str:
150150
"""
151-
Path on stage to which the artefact should be uploaded.
151+
Path on stage to which the artifact should be uploaded.
152152
"""
153153
stage = stage or DEPLOYMENT_STAGE
154154
if isinstance(stage, str):
@@ -170,7 +170,7 @@ def upload_path(self, stage: FQN | str | None) -> str:
170170

171171
def import_path(self, stage: FQN | str | None) -> str:
172172
"""Path for UDF/sproc imports clause."""
173-
return self.upload_path(stage) + self._artefact_name
173+
return self.upload_path(stage) + self._artifact_name
174174

175175
def _is_dest_a_file(self) -> bool:
176176
if not self.dest:
@@ -188,12 +188,12 @@ def _path_until_asterisk(self) -> Path:
188188

189189
# Can be removed after removing ENABLE_SNOWPARK_GLOB_SUPPORT feature flag.
190190
def build(self) -> None:
191-
raise NotImplementedError("Not implemented in Artefact class.")
191+
raise NotImplementedError("Not implemented in Artifact class.")
192192

193193

194194
@dataclass(unsafe_hash=True)
195-
class ArtefactOldBuild(Artefact):
196-
"""Helper for getting paths related to given artefact."""
195+
class ArtifactOldBuild(Artifact):
196+
"""Helper for getting paths related to given artifact."""
197197

198198
path: Path
199199
dest: str | None = None
@@ -202,21 +202,21 @@ def __init__(self, path: Path, dest: Optional[str] = None) -> None:
202202
super().__init__(project_root=Path(), bundle_root=Path(), path=path, dest=dest)
203203

204204
@property
205-
def _artefact_name(self) -> str:
205+
def _artifact_name(self) -> str:
206206
if self.path.is_dir():
207207
return self.path.stem + ".zip"
208208
return self.path.name
209209

210210
@property
211211
def post_build_path(self) -> Path:
212212
"""
213-
Returns post-build artefact path. Directories are mapped to corresponding .zip files.
213+
Returns post-build artifact path. Directories are mapped to corresponding .zip files.
214214
"""
215-
return self.path.parent / self._artefact_name
215+
return self.path.parent / self._artifact_name
216216

217217
def upload_path(self, stage: FQN | str | None) -> str:
218218
"""
219-
Path on stage to which the artefact should be uploaded.
219+
Path on stage to which the artifact should be uploaded.
220220
"""
221221
stage = stage or DEPLOYMENT_STAGE
222222
if isinstance(stage, str):
@@ -229,10 +229,10 @@ def upload_path(self, stage: FQN | str | None) -> str:
229229

230230
def import_path(self, stage: FQN | str | None) -> str:
231231
"""Path for UDF/sproc imports clause."""
232-
return self.upload_path(stage) + self._artefact_name
232+
return self.upload_path(stage) + self._artifact_name
233233

234234
def build(self) -> None:
235-
"""Build the artefact. Applies only to directories. Files are untouched."""
235+
"""Build the artifact. Applies only to directories. Files are untouched."""
236236
if not self.path.is_dir():
237237
return
238238
cli_console.step(f"Creating: {self.post_build_path.name}")

tests/snowpark/test_project_paths.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from unittest import mock
33

44
import pytest
5-
from snowflake.cli._plugins.snowpark.snowpark_project_paths import Artefact
5+
from snowflake.cli._plugins.snowpark.snowpark_project_paths import Artifact
66

77
bundle_root = Path("output") / "bundle" / "snowpark"
88
absolute_bundle_root = Path.cwd().absolute() / "output" / "bundle" / "snowpark"
@@ -34,7 +34,7 @@ def test_artifact_import_path(mock_ctx_context, path, dest, is_file, expected_pa
3434
stage = "stage"
3535

3636
with mock.patch.object(Path, "is_file" if is_file else "is_dir", return_value=True):
37-
import_path = Artefact(Path(), bundle_root, Path(path), dest).import_path(stage)
37+
import_path = Artifact(Path(), bundle_root, Path(path), dest).import_path(stage)
3838

3939
assert import_path == expected_path
4040

@@ -64,7 +64,7 @@ def test_artifact_upload_path(mock_ctx_context, path, dest, is_file, expected_pa
6464
mock_ctx_context.return_value.connection = mock_connection
6565

6666
with mock.patch.object(Path, "is_file" if is_file else "is_dir", return_value=True):
67-
upload_path = Artefact(Path(), bundle_root, Path(path), dest).upload_path(
67+
upload_path = Artifact(Path(), bundle_root, Path(path), dest).upload_path(
6868
"stage"
6969
)
7070

@@ -106,7 +106,7 @@ def test_artifact_upload_path(mock_ctx_context, path, dest, is_file, expected_pa
106106
)
107107
def test_artifact_post_build_path(path, dest, is_file, expected_path):
108108
with mock.patch.object(Path, "is_file" if is_file else "is_dir", return_value=True):
109-
post_build_path = Artefact(
109+
post_build_path = Artifact(
110110
Path(), bundle_root, Path(path), dest
111111
).post_build_path
112112

@@ -141,7 +141,7 @@ def test_artifact_import_path_from_other_directory(
141141
stage = "stage"
142142

143143
with mock.patch.object(Path, "is_file" if is_file else "is_dir", return_value=True):
144-
import_path = Artefact(
144+
import_path = Artifact(
145145
Path("/tmp"),
146146
Path("/tmp") / "output" / "deploy" / "snowpark",
147147
Path(path),
@@ -178,7 +178,7 @@ def test_artifact_upload_path_from_other_directory(
178178
mock_ctx_context.return_value.connection = mock_connection
179179

180180
with mock.patch.object(Path, "is_file" if is_file else "is_dir", return_value=True):
181-
upload_path = Artefact(
181+
upload_path = Artifact(
182182
Path("/tmp"), Path("/tmp") / "output" / "deploy", Path(path), dest
183183
).upload_path("stage")
184184

@@ -236,7 +236,7 @@ def test_artifact_post_build_path_from_other_directory(
236236
path, dest, is_file, expected_path
237237
):
238238
with mock.patch.object(Path, "is_file" if is_file else "is_dir", return_value=True):
239-
post_build_path = Artefact(
239+
post_build_path = Artifact(
240240
Path.cwd().absolute(),
241241
absolute_bundle_root,
242242
Path(path),

0 commit comments

Comments
 (0)