Skip to content

Commit

Permalink
Completed renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-bdufour committed Dec 6, 2024
1 parent 97ba76e commit 4753ff4
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ def _assert_absolute_paths(processor_ctx: ArtifactProcessorContext):
path = getattr(processor_ctx, f"{name.lower()}_root")
assert path.is_absolute(), f"{name} root {path} must be an absolute path."

def compile_artifacts(self):
def process_artifacts(self):
"""
Go through every artifact object in the project definition of a native app, and execute processors in order of specification for each of the artifact object.
Go through every artifact object in the project definition of an entity, and execute processors in order of specification for each of the artifact object.
May have side-effects on the filesystem by either directly editing source files or the deploy root.
"""
metrics = get_cli_context().metrics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,16 +526,16 @@ def action_version_drop(
def _bundle(self):
model = self._entity_model
bundle_map = build_bundle(self.project_root, self.deploy_root, model.artifacts)
bundle_context = ArtifactProcessorContext(
processor_ctx = ArtifactProcessorContext(
package_name=self.name,
artifacts=model.artifacts,
project_root=self.project_root,
bundle_root=self.bundle_root,
deploy_root=self.deploy_root,
generated_root=self.generated_root,
)
compiler = ArtifactProcessorRegistrar(bundle_context)
compiler.compile_artifacts()
registrar = ArtifactProcessorRegistrar(processor_ctx)
registrar.process_artifacts()
return bundle_map

def _deploy(
Expand Down
8 changes: 4 additions & 4 deletions tests/nativeapp/codegen/snowpark/test_python_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
# --------------------------------------------------------


def _get_bundle_context(
def _get_processor_context(
pkg_model: ApplicationPackageEntityModel, project_root: Path | None = None
):
project_root = project_root or Path().resolve()
Expand Down Expand Up @@ -372,7 +372,7 @@ def test_process_no_collected_functions(
{"src": "a/b/c/*.py", "dest": "stagepath/", "processors": ["SNOWPARK"]}
]
mock_sandbox.side_effect = [None, []]
project_context = _get_bundle_context(pkg_model, local_path)
project_context = _get_processor_context(pkg_model, local_path)
processor = SnowparkAnnotationProcessor(project_context)
processor.process(
artifact_to_process=pkg_model.artifacts[0],
Expand Down Expand Up @@ -423,7 +423,7 @@ def test_process_with_collected_functions(
[native_app_extension_function_raw_data],
[imports_variation],
]
project_context = _get_bundle_context(pkg_model, local_path)
project_context = _get_processor_context(pkg_model, local_path)
processor_context = copy.copy(project_context)
processor_context.generated_root = (
project_context.generated_root / "snowpark"
Expand Down Expand Up @@ -487,7 +487,7 @@ def test_package_normalization(
]
native_app_extension_function_raw_data["packages"] = package_decl
mock_sandbox.side_effect = [[native_app_extension_function_raw_data]]
project_context = _get_bundle_context(pkg_model)
project_context = _get_processor_context(pkg_model)
processor_context = copy.copy(project_context)
processor_context.generated_root = (
project_context.generated_root / "snowpark"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def bundle_files(

artifact_to_process = PathMapping(src="src/*", dest="./", processors=["templates"])

bundle_context = ArtifactProcessorContext(
processor_context = ArtifactProcessorContext(
package_name="test_package_name",
project_root=project_root,
artifacts=[artifact_to_process],
Expand All @@ -77,7 +77,7 @@ def bundle_files(
deploy_root=deploy_root,
)

return BundleResult(artifact_to_process, bundle_context, output_files)
return BundleResult(artifact_to_process, processor_context, output_files)


@mock.patch(CLI_GLOBAL_TEMPLATE_CONTEXT, {})
Expand Down
36 changes: 18 additions & 18 deletions tests/nativeapp/codegen/test_processor_registrar.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def test_proj_def():
)


def _get_bundle_context(pkg_model: ApplicationPackageEntityModel):
def _get_processor_context(pkg_model: ApplicationPackageEntityModel):
project_root = Path().resolve()
return ArtifactProcessorContext(
package_name=pkg_model.fqn.name,
Expand All @@ -78,28 +78,28 @@ def _get_bundle_context(pkg_model: ApplicationPackageEntityModel):


@pytest.fixture()
def test_compiler(test_proj_def):
def test_registrar(test_proj_def):
return ArtifactProcessorRegistrar(
_get_bundle_context(test_proj_def.entities["pkg"])
_get_processor_context(test_proj_def.entities["pkg"])
)


@pytest.mark.parametrize("name", ["Project", "Deploy", "Bundle", "Generated"])
def test_compiler_requires_absolute_paths(test_proj_def, name):
bundle_context = _get_bundle_context(test_proj_def.entities["pkg"])
def test_requires_absolute_paths(test_proj_def, name):
processor_context = _get_processor_context(test_proj_def.entities["pkg"])

path = Path()
setattr(bundle_context, f"{name.lower()}_root", path)
setattr(processor_context, f"{name.lower()}_root", path)
with pytest.raises(
AssertionError,
match=re.escape(rf"{name} root {path} must be an absolute path."),
):
ArtifactProcessorRegistrar(bundle_context)
ArtifactProcessorRegistrar(processor_context)


def test_try_create_processor_returns_none(test_proj_def, test_compiler):
def test_try_create_processor_returns_none(test_proj_def, test_registrar):
artifact_to_process = test_proj_def.entities["pkg"].artifacts[2]
result = test_compiler._try_create_processor( # noqa: SLF001
result = test_registrar._try_create_processor( # noqa: SLF001
processor_mapping=artifact_to_process.processors[0],
)
assert result is None
Expand All @@ -110,22 +110,22 @@ def test_try_create_processor_returns_none(test_proj_def, test_compiler):
[3, 4],
)
def test_try_create_processor_returns_processor(
artifact_index, test_proj_def, test_compiler
artifact_index, test_proj_def, test_registrar
):
mapping = test_proj_def.entities["pkg"].artifacts[artifact_index]
result = test_compiler._try_create_processor( # noqa: SLF001
result = test_registrar._try_create_processor( # noqa: SLF001
processor_mapping=mapping.processors[0],
)
assert isinstance(result, SnowparkAnnotationProcessor)


def test_find_and_execute_processors_exception(test_proj_def, test_compiler):
def test_find_and_execute_processors_exception(test_proj_def, test_registrar):
pkg_model = test_proj_def.entities["pkg"]
pkg_model.artifacts = [{"dest": "./", "src": "app/*", "processors": ["DUMMY"]}]
test_compiler = ArtifactProcessorRegistrar(_get_bundle_context(pkg_model))
test_registrar = ArtifactProcessorRegistrar(_get_processor_context(pkg_model))

with pytest.raises(UnsupportedArtifactProcessorError):
test_compiler.compile_artifacts()
test_registrar.process_artifacts()


class TestProcessor(ArtifactProcessor):
Expand All @@ -148,13 +148,13 @@ def process(
assert False # never invoked


def test_skips_disabled_processors(test_proj_def, test_compiler):
def test_skips_disabled_processors(test_proj_def, test_registrar):
pkg_model = test_proj_def.entities["pkg"]
pkg_model.artifacts = [
{"dest": "./", "src": "app/*", "processors": ["test_processor"]}
]
test_compiler = ArtifactProcessorRegistrar(_get_bundle_context(pkg_model))
test_compiler.register(TestProcessor)
test_registrar = ArtifactProcessorRegistrar(_get_processor_context(pkg_model))
test_registrar.register(TestProcessor)

# TestProcessor is never invoked, otherwise calling its methods will make the test fail
test_compiler.compile_artifacts()
test_registrar.process_artifacts()

0 comments on commit 4753ff4

Please sign in to comment.