diff --git a/src/snowflake/cli/_plugins/nativeapp/bundle_context.py b/src/snowflake/cli/_plugins/nativeapp/artifact_processor_context.py similarity index 96% rename from src/snowflake/cli/_plugins/nativeapp/bundle_context.py rename to src/snowflake/cli/_plugins/nativeapp/artifact_processor_context.py index a680ff8779..14e71a5aea 100644 --- a/src/snowflake/cli/_plugins/nativeapp/bundle_context.py +++ b/src/snowflake/cli/_plugins/nativeapp/artifact_processor_context.py @@ -22,7 +22,7 @@ @dataclass -class BundleContext: +class ArtifactProcessorContext: package_name: str artifacts: List[PathMapping] project_root: Path diff --git a/src/snowflake/cli/_plugins/nativeapp/codegen/artifact_processor.py b/src/snowflake/cli/_plugins/nativeapp/codegen/artifact_processor.py index 02dc4ff11a..a491864702 100644 --- a/src/snowflake/cli/_plugins/nativeapp/codegen/artifact_processor.py +++ b/src/snowflake/cli/_plugins/nativeapp/codegen/artifact_processor.py @@ -19,7 +19,9 @@ from typing import Optional from click import ClickException -from snowflake.cli._plugins.nativeapp.bundle_context import BundleContext +from snowflake.cli._plugins.nativeapp.artifact_processor_context import ( + ArtifactProcessorContext, +) from snowflake.cli.api.project.schemas.entities.common import ( PathMapping, ProcessorMapping, @@ -74,9 +76,9 @@ def __exit__(self, exc_type, exc_val, exc_tb): class ArtifactProcessor(ABC): def __init__( self, - bundle_ctx: BundleContext, + processor_ctx: ArtifactProcessorContext, ) -> None: - self._bundle_ctx = bundle_ctx + self._processor_ctx = processor_ctx @abstractmethod def process( diff --git a/src/snowflake/cli/_plugins/nativeapp/codegen/compiler.py b/src/snowflake/cli/_plugins/nativeapp/codegen/artifact_processor_registrar.py similarity index 83% rename from src/snowflake/cli/_plugins/nativeapp/codegen/compiler.py rename to src/snowflake/cli/_plugins/nativeapp/codegen/artifact_processor_registrar.py index c8f675663d..6ef844d3a5 100644 --- a/src/snowflake/cli/_plugins/nativeapp/codegen/compiler.py +++ b/src/snowflake/cli/_plugins/nativeapp/codegen/artifact_processor_registrar.py @@ -19,7 +19,9 @@ from typing import Dict, Optional from click import ClickException -from snowflake.cli._plugins.nativeapp.bundle_context import BundleContext +from snowflake.cli._plugins.nativeapp.artifact_processor_context import ( + ArtifactProcessorContext, +) from snowflake.cli._plugins.nativeapp.codegen.artifact_processor import ( ArtifactProcessor, UnsupportedArtifactProcessorError, @@ -41,22 +43,20 @@ ProcessorClassType = type[ArtifactProcessor] -class NativeAppCompiler: +class ArtifactProcessorRegistrar: """ - Compiler class to perform custom processing on all relevant Native Apps artifacts (specified in the project definition file) - before an application package can be created from those artifacts. + Keeps track of registered artifact processors, and invokes them on a set of artifacts. + An artifact can have more than one processor specified for itself, and this class will execute those processors in that order. - The class also maintains a dictionary of processors it creates in order to reuse them across artifacts, since processor initialization - is independent of the artifact to process. """ def __init__( self, - bundle_ctx: BundleContext, + processor_ctx: ArtifactProcessorContext, ): - self._assert_absolute_paths(bundle_ctx) + self._assert_absolute_paths(processor_ctx) self._processor_classes_by_name: Dict[str, ProcessorClassType] = {} - self._bundle_ctx = bundle_ctx + self._processor_ctx = processor_ctx # dictionary of all processors created and shared between different artifact objects. self.cached_processors: Dict[str, ArtifactProcessor] = {} @@ -78,9 +78,9 @@ def register(self, processor_cls: ProcessorClassType): self._processor_classes_by_name[str(name)] = processor_cls @staticmethod - def _assert_absolute_paths(bundle_ctx: BundleContext): + def _assert_absolute_paths(processor_ctx: ArtifactProcessorContext): for name in ["Project", "Deploy", "Bundle", "Generated"]: - path = getattr(bundle_ctx, f"{name.lower()}_root") + 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): @@ -99,12 +99,12 @@ def compile_artifacts(self): cc.phase("Invoking artifact processors"), get_cli_context().metrics.span("artifact_processors"), ): - if self._bundle_ctx.generated_root.exists(): + if self._processor_ctx.generated_root.exists(): raise ClickException( - f"Path {self._bundle_ctx.generated_root} already exists. Please choose a different name for your generated directory in the project definition file." + f"Path {self._processor_ctx.generated_root} already exists. Please choose a different name for your generated directory in the project definition file." ) - for artifact in self._bundle_ctx.artifacts: + for artifact in self._processor_ctx.artifacts: for processor in artifact.processors: if self._is_enabled(processor): artifact_processor = self._try_create_processor( @@ -140,13 +140,13 @@ def _try_create_processor( # No registered processor with the specified name return None - processor_ctx = copy.copy(self._bundle_ctx) + processor_ctx = copy.copy(self._processor_ctx) processor_subdirectory = re.sub(r"[^a-zA-Z0-9_$]", "_", processor_name) processor_ctx.bundle_root = ( - self._bundle_ctx.bundle_root / processor_subdirectory + self._processor_ctx.bundle_root / processor_subdirectory ) processor_ctx.generated_root = ( - self._bundle_ctx.generated_root / processor_subdirectory + self._processor_ctx.generated_root / processor_subdirectory ) current_processor = processor_cls(processor_ctx) self.cached_processors[processor_name] = current_processor @@ -154,7 +154,7 @@ def _try_create_processor( return current_processor def _should_invoke_processors(self): - for artifact in self._bundle_ctx.artifacts: + for artifact in self._processor_ctx.artifacts: for processor in artifact.processors: if self._is_enabled(processor): return True diff --git a/src/snowflake/cli/_plugins/nativeapp/codegen/setup/native_app_setup_processor.py b/src/snowflake/cli/_plugins/nativeapp/codegen/setup/native_app_setup_processor.py index 04290d1f8d..db37728aa4 100644 --- a/src/snowflake/cli/_plugins/nativeapp/codegen/setup/native_app_setup_processor.py +++ b/src/snowflake/cli/_plugins/nativeapp/codegen/setup/native_app_setup_processor.py @@ -94,8 +94,8 @@ def process( Processes a Python setup script and generates the corresponding SQL commands. """ bundle_map = BundleMap( - project_root=self._bundle_ctx.project_root, - deploy_root=self._bundle_ctx.deploy_root, + project_root=self._processor_ctx.project_root, + deploy_root=self._processor_ctx.deploy_root, ) bundle_map.add(artifact_to_process) @@ -108,7 +108,7 @@ def process( absolute=True, expand_directories=True, predicate=is_python_file_artifact ): cc.message( - f"Found Python setup file: {src_file.relative_to(self._bundle_ctx.project_root)}" + f"Found Python setup file: {src_file.relative_to(self._processor_ctx.project_root)}" ) files_to_process.append(src_file) @@ -150,15 +150,15 @@ def _execute_in_sandbox(self, py_files: List[Path]) -> dict: file_count = len(py_files) cc.step(f"Processing {file_count} setup file{'s' if file_count > 1 else ''}") - manifest_path = find_manifest_file(deploy_root=self._bundle_ctx.deploy_root) + manifest_path = find_manifest_file(deploy_root=self._processor_ctx.deploy_root) - generated_root = self._bundle_ctx.generated_root + generated_root = self._processor_ctx.generated_root generated_root.mkdir(exist_ok=True, parents=True) env_vars = { - "_SNOWFLAKE_CLI_PROJECT_PATH": str(self._bundle_ctx.project_root), + "_SNOWFLAKE_CLI_PROJECT_PATH": str(self._processor_ctx.project_root), "_SNOWFLAKE_CLI_SETUP_FILES": os.pathsep.join(map(str, py_files)), - "_SNOWFLAKE_CLI_APP_NAME": str(self._bundle_ctx.package_name), + "_SNOWFLAKE_CLI_APP_NAME": str(self._processor_ctx.package_name), "_SNOWFLAKE_CLI_SQL_DEST_DIR": str(generated_root), "_SNOWFLAKE_CLI_MANIFEST_PATH": str(manifest_path), } @@ -167,7 +167,7 @@ def _execute_in_sandbox(self, py_files: List[Path]) -> dict: result = execute_script_in_sandbox( script_source=DRIVER_PATH.read_text(), env_type=ExecutionEnvironmentType.VENV, - cwd=self._bundle_ctx.bundle_root, + cwd=self._processor_ctx.bundle_root, timeout=DEFAULT_TIMEOUT, path=self.sandbox_root, env_vars=env_vars, @@ -187,7 +187,7 @@ def _execute_in_sandbox(self, py_files: List[Path]) -> dict: def _edit_setup_sql(self, modifications: List[dict]) -> None: cc.step("Patching setup script") setup_file_path = find_setup_script_file( - deploy_root=self._bundle_ctx.deploy_root + deploy_root=self._processor_ctx.deploy_root ) with self.edit_file(setup_file_path) as f: @@ -208,7 +208,7 @@ def _edit_setup_sql(self, modifications: List[dict]) -> None: def _edit_manifest(self, modifications: List[dict]) -> None: cc.step("Patching manifest") - manifest_path = find_manifest_file(deploy_root=self._bundle_ctx.deploy_root) + manifest_path = find_manifest_file(deploy_root=self._processor_ctx.deploy_root) with self.edit_file(manifest_path) as f: manifest = yaml.safe_load(f.contents) @@ -232,14 +232,14 @@ def _setup_mod_instruction_to_sql(self, mod_inst: dict) -> str: if payload_type == "execute immediate": file_path = payload.get("file_path") if file_path: - sql_file_path = self._bundle_ctx.generated_root / file_path - return f"EXECUTE IMMEDIATE FROM '/{to_stage_path(sql_file_path.relative_to(self._bundle_ctx.deploy_root))}';" + sql_file_path = self._processor_ctx.generated_root / file_path + return f"EXECUTE IMMEDIATE FROM '/{to_stage_path(sql_file_path.relative_to(self._processor_ctx.deploy_root))}';" raise ClickException(f"Unsupported instruction type received: {payload_type}") @property def sandbox_root(self): - return self._bundle_ctx.bundle_root / "venv" + return self._processor_ctx.bundle_root / "venv" def _create_or_update_sandbox(self): sandbox_root = self.sandbox_root @@ -248,7 +248,7 @@ def _create_or_update_sandbox(self): cc.step("Virtual environment found") else: cc.step( - f"Creating virtual environment in {sandbox_root.relative_to(self._bundle_ctx.project_root)}" + f"Creating virtual environment in {sandbox_root.relative_to(self._processor_ctx.project_root)}" ) env_builder.ensure_created() diff --git a/src/snowflake/cli/_plugins/nativeapp/codegen/snowpark/python_processor.py b/src/snowflake/cli/_plugins/nativeapp/codegen/snowpark/python_processor.py index 1396665e92..307c3f3d1e 100644 --- a/src/snowflake/cli/_plugins/nativeapp/codegen/snowpark/python_processor.py +++ b/src/snowflake/cli/_plugins/nativeapp/codegen/snowpark/python_processor.py @@ -184,8 +184,8 @@ def process( get_cli_context().metrics.set_counter(CLICounterField.SNOWPARK_PROCESSOR, 1) bundle_map = BundleMap( - project_root=self._bundle_ctx.project_root, - deploy_root=self._bundle_ctx.deploy_root, + project_root=self._processor_ctx.project_root, + deploy_root=self._processor_ctx.deploy_root, ) bundle_map.add(artifact_to_process) @@ -233,7 +233,7 @@ def process( edit_setup_script_with_exec_imm_sql( collected_sql_files=collected_sql_files, deploy_root=bundle_map.deploy_root(), - generated_root=self._bundle_ctx.generated_root, + generated_root=self._processor_ctx.generated_root, ) def _normalize_imports( @@ -314,7 +314,7 @@ def collect_extension_functions( self, bundle_map: BundleMap, processor_mapping: Optional[ProcessorMapping] ) -> Dict[Path, List[NativeAppExtensionFunction]]: kwargs = ( - _determine_virtual_env(self._bundle_ctx.project_root, processor_mapping) + _determine_virtual_env(self._processor_ctx.project_root, processor_mapping) if processor_mapping is not None else {} ) @@ -330,11 +330,11 @@ def collect_extension_functions( predicate=is_python_file_artifact, ) ): - src_file_name = src_file.relative_to(self._bundle_ctx.project_root) + src_file_name = src_file.relative_to(self._processor_ctx.project_root) cc.step(f"Processing Snowpark annotations from {src_file_name}") collected_extension_function_json = _execute_in_sandbox( py_file=str(dest_file.resolve()), - deploy_root=self._bundle_ctx.deploy_root, + deploy_root=self._processor_ctx.deploy_root, kwargs=kwargs, ) @@ -365,9 +365,9 @@ def generate_new_sql_file_name(self, py_file: Path) -> Path: """ Generates a SQL filename for the generated root from the Python file, and creates its parent directories. """ - relative_py_file = py_file.relative_to(self._bundle_ctx.deploy_root) + relative_py_file = py_file.relative_to(self._processor_ctx.deploy_root) sql_file = Path( - self._bundle_ctx.generated_root, relative_py_file.with_suffix(".sql") + self._processor_ctx.generated_root, relative_py_file.with_suffix(".sql") ) if sql_file.exists(): cc.warning( diff --git a/src/snowflake/cli/_plugins/nativeapp/codegen/templates/templates_processor.py b/src/snowflake/cli/_plugins/nativeapp/codegen/templates/templates_processor.py index 95d8ca4d93..cec1929402 100644 --- a/src/snowflake/cli/_plugins/nativeapp/codegen/templates/templates_processor.py +++ b/src/snowflake/cli/_plugins/nativeapp/codegen/templates/templates_processor.py @@ -60,7 +60,7 @@ def expand_templates_in_file( if src.is_dir(): return - src_file_name = src.relative_to(self._bundle_ctx.project_root) + src_file_name = str(src.relative_to(self._processor_ctx.project_root)) try: with self.edit_file(dest) as file: @@ -114,8 +114,8 @@ def process( get_cli_context().metrics.set_counter(CLICounterField.TEMPLATES_PROCESSOR, 1) bundle_map = BundleMap( - project_root=self._bundle_ctx.project_root, - deploy_root=self._bundle_ctx.deploy_root, + project_root=self._processor_ctx.project_root, + deploy_root=self._processor_ctx.deploy_root, ) bundle_map.add(artifact_to_process) diff --git a/src/snowflake/cli/_plugins/nativeapp/entities/application_package.py b/src/snowflake/cli/_plugins/nativeapp/entities/application_package.py index fcce78e58c..9fc2da972c 100644 --- a/src/snowflake/cli/_plugins/nativeapp/entities/application_package.py +++ b/src/snowflake/cli/_plugins/nativeapp/entities/application_package.py @@ -10,13 +10,17 @@ from click import BadOptionUsage, ClickException from pydantic import Field, field_validator from snowflake.cli._plugins.connection.util import UIParameter +from snowflake.cli._plugins.nativeapp.artifact_processor_context import ( + ArtifactProcessorContext, +) from snowflake.cli._plugins.nativeapp.artifacts import ( VersionInfo, build_bundle, find_version_info_in_manifest_file, ) -from snowflake.cli._plugins.nativeapp.bundle_context import BundleContext -from snowflake.cli._plugins.nativeapp.codegen.compiler import NativeAppCompiler +from snowflake.cli._plugins.nativeapp.codegen.artifact_processor_registrar import ( + ArtifactProcessorRegistrar, +) from snowflake.cli._plugins.nativeapp.constants import ( ALLOWED_SPECIAL_COMMENTS, COMMENT_COL, @@ -522,7 +526,7 @@ 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 = BundleContext( + bundle_context = ArtifactProcessorContext( package_name=self.name, artifacts=model.artifacts, project_root=self.project_root, @@ -530,7 +534,7 @@ def _bundle(self): deploy_root=self.deploy_root, generated_root=self.generated_root, ) - compiler = NativeAppCompiler(bundle_context) + compiler = ArtifactProcessorRegistrar(bundle_context) compiler.compile_artifacts() return bundle_map diff --git a/src/snowflake/cli/api/project/definition_conversion.py b/src/snowflake/cli/api/project/definition_conversion.py index b823580e24..7d2e59dd01 100644 --- a/src/snowflake/cli/api/project/definition_conversion.py +++ b/src/snowflake/cli/api/project/definition_conversion.py @@ -9,10 +9,12 @@ from typing import Any, Dict, Literal, Optional from click import ClickException +from snowflake.cli._plugins.nativeapp.artifact_processor_context import ( + ArtifactProcessorContext, +) from snowflake.cli._plugins.nativeapp.artifacts import ( bundle_artifacts, ) -from snowflake.cli._plugins.nativeapp.bundle_context import BundleContext from snowflake.cli._plugins.nativeapp.codegen.templates.templates_processor import ( TemplatesProcessor, ) @@ -467,7 +469,7 @@ def _convert_templates_in_files( # files on disk outside of the artifacts we want to convert with tempfile.TemporaryDirectory() as d: deploy_root = Path(d) - bundle_ctx = BundleContext( + processor_ctx = ArtifactProcessorContext( package_name=pkg_model.identifier, artifacts=pkg_model.artifacts, project_root=project_root, @@ -477,7 +479,7 @@ def _convert_templates_in_files( project_root / deploy_root / pkg_model.generated_root ), ) - template_processor = TemplatesProcessor(bundle_ctx) + template_processor = TemplatesProcessor(processor_ctx) bundle_map = bundle_artifacts( project_root, deploy_root, artifacts_to_template ) diff --git a/tests/nativeapp/codegen/snowpark/test_python_processor.py b/tests/nativeapp/codegen/snowpark/test_python_processor.py index 27adfeb1d8..ec750c9a89 100644 --- a/tests/nativeapp/codegen/snowpark/test_python_processor.py +++ b/tests/nativeapp/codegen/snowpark/test_python_processor.py @@ -21,7 +21,9 @@ from unittest import mock import pytest -from snowflake.cli._plugins.nativeapp.bundle_context import BundleContext +from snowflake.cli._plugins.nativeapp.artifact_processor_context import ( + ArtifactProcessorContext, +) from snowflake.cli._plugins.nativeapp.codegen.sandbox import ( ExecutionEnvironmentType, SandboxExecutionError, @@ -54,7 +56,7 @@ def _get_bundle_context( pkg_model: ApplicationPackageEntityModel, project_root: Path | None = None ): project_root = project_root or Path().resolve() - return BundleContext( + return ArtifactProcessorContext( package_name=pkg_model.fqn.name, artifacts=pkg_model.artifacts, project_root=project_root, diff --git a/tests/nativeapp/codegen/templating/test_templates_processor.py b/tests/nativeapp/codegen/templating/test_templates_processor.py index 5d3b66403d..c528869657 100644 --- a/tests/nativeapp/codegen/templating/test_templates_processor.py +++ b/tests/nativeapp/codegen/templating/test_templates_processor.py @@ -20,7 +20,9 @@ from unittest import mock import pytest -from snowflake.cli._plugins.nativeapp.bundle_context import BundleContext +from snowflake.cli._plugins.nativeapp.artifact_processor_context import ( + ArtifactProcessorContext, +) from snowflake.cli._plugins.nativeapp.codegen.templates.templates_processor import ( TemplatesProcessor, ) @@ -41,7 +43,7 @@ class BundleResult: """ artifact_to_process: PathMapping - bundle_ctx: BundleContext + processor_ctx: ArtifactProcessorContext output_files: list[Path] @@ -69,7 +71,7 @@ def bundle_files( artifact_to_process = PathMapping(src="src/*", dest="./", processors=["templates"]) - bundle_context = BundleContext( + bundle_context = ArtifactProcessorContext( package_name="test_package_name", project_root=project_root, artifacts=[artifact_to_process], @@ -87,7 +89,9 @@ def test_templates_processor_valid_files_no_templates(): file_contents = ["This is a test file\n with some content"] with TemporaryDirectory() as tmp_dir: bundle_result = bundle_files(tmp_dir, file_names, file_contents) - templates_processor = TemplatesProcessor(bundle_ctx=bundle_result.bundle_ctx) + templates_processor = TemplatesProcessor( + processor_ctx=bundle_result.processor_ctx + ) templates_processor.process(bundle_result.artifact_to_process, None) assert bundle_result.output_files[0].is_symlink() @@ -103,7 +107,9 @@ def test_one_file_with_template_and_one_without(): ] with TemporaryDirectory() as tmp_dir: bundle_result = bundle_files(tmp_dir, file_names, file_contents) - templates_processor = TemplatesProcessor(bundle_ctx=bundle_result.bundle_ctx) + templates_processor = TemplatesProcessor( + processor_ctx=bundle_result.processor_ctx + ) templates_processor.process(bundle_result.artifact_to_process, None) assert bundle_result.output_files[0].is_symlink() @@ -124,7 +130,9 @@ def test_templates_with_sql_and_non_sql_files_and_mix_syntax(): ] with TemporaryDirectory() as tmp_dir: bundle_result = bundle_files(tmp_dir, file_names, file_contents) - templates_processor = TemplatesProcessor(bundle_ctx=bundle_result.bundle_ctx) + templates_processor = TemplatesProcessor( + processor_ctx=bundle_result.processor_ctx + ) templates_processor.process(bundle_result.artifact_to_process, None) assert not bundle_result.output_files[0].is_symlink() @@ -145,7 +153,9 @@ def test_templates_with_sql_new_syntax(): with TemporaryDirectory() as tmp_dir: bundle_result = bundle_files(tmp_dir, file_names, file_contents) - templates_processor = TemplatesProcessor(bundle_ctx=bundle_result.bundle_ctx) + templates_processor = TemplatesProcessor( + processor_ctx=bundle_result.processor_ctx + ) templates_processor.process(bundle_result.artifact_to_process, None) assert not bundle_result.output_files[0].is_symlink() @@ -160,7 +170,9 @@ def test_templates_with_sql_old_syntax(): file_contents = ["This is a sql file with &{ ctx.env.name }"] with TemporaryDirectory() as tmp_dir: bundle_result = bundle_files(tmp_dir, file_names, file_contents) - templates_processor = TemplatesProcessor(bundle_ctx=bundle_result.bundle_ctx) + templates_processor = TemplatesProcessor( + processor_ctx=bundle_result.processor_ctx + ) templates_processor.process(bundle_result.artifact_to_process, None) assert not bundle_result.output_files[0].is_symlink() @@ -175,7 +187,9 @@ def test_templates_with_sql_both_old_and_new_syntax(): file_contents = ["This is a sql file with &{ ctx.env.name } and <% ctx.env.name %>"] with TemporaryDirectory() as tmp_dir: bundle_result = bundle_files(tmp_dir, file_names, file_contents) - templates_processor = TemplatesProcessor(bundle_ctx=bundle_result.bundle_ctx) + templates_processor = TemplatesProcessor( + processor_ctx=bundle_result.processor_ctx + ) with pytest.raises(InvalidTemplate) as e: templates_processor.process(bundle_result.artifact_to_process, None) @@ -191,7 +205,9 @@ def test_file_with_syntax_error(): file_contents = ["This is a test file with invalid <% ctx.env.TEST_VAR"] with TemporaryDirectory() as tmp_dir: bundle_result = bundle_files(tmp_dir, file_name, file_contents) - templates_processor = TemplatesProcessor(bundle_ctx=bundle_result.bundle_ctx) + templates_processor = TemplatesProcessor( + processor_ctx=bundle_result.processor_ctx + ) with pytest.raises(InvalidTemplateInFileError) as e: templates_processor.process(bundle_result.artifact_to_process, None) @@ -207,7 +223,9 @@ def test_file_with_undefined_variable(): file_contents = ["This is a test file with invalid <% ctx.env.TEST_VAR %>"] with TemporaryDirectory() as tmp_dir: bundle_result = bundle_files(tmp_dir, file_name, file_contents) - templates_processor = TemplatesProcessor(bundle_ctx=bundle_result.bundle_ctx) + templates_processor = TemplatesProcessor( + processor_ctx=bundle_result.processor_ctx + ) with pytest.raises(InvalidTemplateInFileError) as e: templates_processor.process(bundle_result.artifact_to_process, None) diff --git a/tests/nativeapp/codegen/test_compiler.py b/tests/nativeapp/codegen/test_processor_registrar.py similarity index 89% rename from tests/nativeapp/codegen/test_compiler.py rename to tests/nativeapp/codegen/test_processor_registrar.py index 6f703e3d9e..36f9072d9a 100644 --- a/tests/nativeapp/codegen/test_compiler.py +++ b/tests/nativeapp/codegen/test_processor_registrar.py @@ -16,12 +16,16 @@ from typing import Optional import pytest -from snowflake.cli._plugins.nativeapp.bundle_context import BundleContext +from snowflake.cli._plugins.nativeapp.artifact_processor_context import ( + ArtifactProcessorContext, +) from snowflake.cli._plugins.nativeapp.codegen.artifact_processor import ( ArtifactProcessor, UnsupportedArtifactProcessorError, ) -from snowflake.cli._plugins.nativeapp.codegen.compiler import NativeAppCompiler +from snowflake.cli._plugins.nativeapp.codegen.artifact_processor_registrar import ( + ArtifactProcessorRegistrar, +) from snowflake.cli._plugins.nativeapp.codegen.snowpark.python_processor import ( SnowparkAnnotationProcessor, ) @@ -61,7 +65,7 @@ def test_proj_def(): def _get_bundle_context(pkg_model: ApplicationPackageEntityModel): project_root = Path().resolve() - return BundleContext( + return ArtifactProcessorContext( package_name=pkg_model.fqn.name, artifacts=pkg_model.artifacts, project_root=project_root, @@ -75,7 +79,9 @@ def _get_bundle_context(pkg_model: ApplicationPackageEntityModel): @pytest.fixture() def test_compiler(test_proj_def): - return NativeAppCompiler(_get_bundle_context(test_proj_def.entities["pkg"])) + return ArtifactProcessorRegistrar( + _get_bundle_context(test_proj_def.entities["pkg"]) + ) @pytest.mark.parametrize("name", ["Project", "Deploy", "Bundle", "Generated"]) @@ -88,7 +94,7 @@ def test_compiler_requires_absolute_paths(test_proj_def, name): AssertionError, match=re.escape(rf"{name} root {path} must be an absolute path."), ): - NativeAppCompiler(bundle_context) + ArtifactProcessorRegistrar(bundle_context) def test_try_create_processor_returns_none(test_proj_def, test_compiler): @@ -116,7 +122,7 @@ def test_try_create_processor_returns_processor( def test_find_and_execute_processors_exception(test_proj_def, test_compiler): pkg_model = test_proj_def.entities["pkg"] pkg_model.artifacts = [{"dest": "./", "src": "app/*", "processors": ["DUMMY"]}] - test_compiler = NativeAppCompiler(_get_bundle_context(pkg_model)) + test_compiler = ArtifactProcessorRegistrar(_get_bundle_context(pkg_model)) with pytest.raises(UnsupportedArtifactProcessorError): test_compiler.compile_artifacts() @@ -147,7 +153,7 @@ def test_skips_disabled_processors(test_proj_def, test_compiler): pkg_model.artifacts = [ {"dest": "./", "src": "app/*", "processors": ["test_processor"]} ] - test_compiler = NativeAppCompiler(_get_bundle_context(pkg_model)) + test_compiler = ArtifactProcessorRegistrar(_get_bundle_context(pkg_model)) test_compiler.register(TestProcessor) # TestProcessor is never invoked, otherwise calling its methods will make the test fail diff --git a/tests/nativeapp/test_application_package_entity.py b/tests/nativeapp/test_application_package_entity.py index d07683ac94..de577161aa 100644 --- a/tests/nativeapp/test_application_package_entity.py +++ b/tests/nativeapp/test_application_package_entity.py @@ -63,9 +63,9 @@ def _get_app_pkg_entity(project_directory): def test_bundle(project_directory): - app_pkg, bundle_ctx, mock_console = _get_app_pkg_entity(project_directory) + app_pkg, action_ctx, mock_console = _get_app_pkg_entity(project_directory) - bundle_result = app_pkg.action_bundle(bundle_ctx) + bundle_result = app_pkg.action_bundle(action_ctx) deploy_root = bundle_result.deploy_root() assert (deploy_root / "README.md").exists() @@ -139,10 +139,10 @@ def test_deploy( ) mock_execute.side_effect = side_effects - app_pkg, bundle_ctx, mock_console = _get_app_pkg_entity(project_directory) + app_pkg, action_ctx, mock_console = _get_app_pkg_entity(project_directory) app_pkg.action_deploy( - bundle_ctx, + action_ctx, prune=False, recursive=False, paths=["a/b", "c"],