From 91f51e204c9c0c09304fdc3314ec9f69ddecf7a0 Mon Sep 17 00:00:00 2001 From: anders-albert Date: Mon, 18 Nov 2024 15:58:46 +0100 Subject: [PATCH 1/4] fix: skip yaml files --- cognite_toolkit/_cdf_tk/commands/build.py | 12 ++++++++++++ cognite_toolkit/_cdf_tk/loaders/__init__.py | 7 +++++++ 2 files changed, 19 insertions(+) diff --git a/cognite_toolkit/_cdf_tk/commands/build.py b/cognite_toolkit/_cdf_tk/commands/build.py index a06e2331a..15f17e8f7 100644 --- a/cognite_toolkit/_cdf_tk/commands/build.py +++ b/cognite_toolkit/_cdf_tk/commands/build.py @@ -47,8 +47,10 @@ ToolkitMissingModuleError, ToolkitYAMLFormatError, ) +from cognite_toolkit._cdf_tk.feature_flags import Flags from cognite_toolkit._cdf_tk.hints import ModuleDefinition, verify_module_directory from cognite_toolkit._cdf_tk.loaders import ( + KINDS_BY_FOLDER_NAME, ContainerLoader, DataLoader, DataModelLoader, @@ -426,6 +428,16 @@ def _replace_variables( for source_path in resource_files: if source_path.suffix.lower() not in TEMPLATE_VARS_FILE_SUFFIXES: continue + if ( + Flags.REQUIRE_KIND.is_enabled() + and source_path.suffix in YAML_SUFFIX + and all( + not source_path.stem.casefold().endswith(kind.casefold()) + for kind in KINDS_BY_FOLDER_NAME[resource_name] + ) + ): + # Skipping files that are not of the correct kind. + continue if verbose: self.console(f"Processing file {source_path.name}...") diff --git a/cognite_toolkit/_cdf_tk/loaders/__init__.py b/cognite_toolkit/_cdf_tk/loaders/__init__.py index c0070ede0..38419ef5a 100644 --- a/cognite_toolkit/_cdf_tk/loaders/__init__.py +++ b/cognite_toolkit/_cdf_tk/loaders/__init__.py @@ -94,6 +94,12 @@ RESOURCE_LOADER_LIST = [loader for loader in LOADER_LIST if issubclass(loader, ResourceLoader)] RESOURCE_CONTAINER_LOADER_LIST = [loader for loader in LOADER_LIST if issubclass(loader, ResourceContainerLoader)] RESOURCE_DATA_LOADER_LIST = [loader for loader in LOADER_LIST if issubclass(loader, DataLoader)] +KINDS_BY_FOLDER_NAME: dict[str, set[str]] = {} +for loader in LOADER_LIST: + if loader.folder_name not in KINDS_BY_FOLDER_NAME: + KINDS_BY_FOLDER_NAME[loader.folder_name] = set() + KINDS_BY_FOLDER_NAME[loader.folder_name].add(loader.kind) +del loader # cleanup module namespace if not Flags.STREAMLIT.is_enabled(): ResourceTypes: TypeAlias = Literal[ @@ -195,4 +201,5 @@ def get_loader(resource_dir: str, kind: str) -> type[Loader]: "RESOURCE_LOADER_LIST", "RESOURCE_CONTAINER_LOADER_LIST", "RESOURCE_DATA_LOADER_LIST", + "KINDS_BY_FOLDER_NAME", ] From e3f45885a407cd6bc9af62f09dd95e384f03bcd6 Mon Sep 17 00:00:00 2001 From: anders-albert Date: Mon, 18 Nov 2024 16:01:27 +0100 Subject: [PATCH 2/4] build: changelog --- CHANGELOG.cdf-tk.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.cdf-tk.md b/CHANGELOG.cdf-tk.md index b807b598e..d772286fe 100644 --- a/CHANGELOG.cdf-tk.md +++ b/CHANGELOG.cdf-tk.md @@ -20,6 +20,7 @@ Changes are grouped as follows: ### Fixed - [Alpha feature] `cdf deploy` will no longer deploy `GraphQL` resources if they are not changed. +- [Alpha feature] `cdf build` will no longer copy content `YAML` files to the build directory. ## [0.3.10] - 2024-11-14 From 492f57cfda3b5579e6c1cb03e8a1fbd34352a11b Mon Sep 17 00:00:00 2001 From: anders-albert Date: Mon, 18 Nov 2024 20:47:12 +0100 Subject: [PATCH 3/4] fix: in correct location --- cognite_toolkit/_cdf_tk/commands/build.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/cognite_toolkit/_cdf_tk/commands/build.py b/cognite_toolkit/_cdf_tk/commands/build.py index 15f17e8f7..c72405836 100644 --- a/cognite_toolkit/_cdf_tk/commands/build.py +++ b/cognite_toolkit/_cdf_tk/commands/build.py @@ -50,11 +50,11 @@ from cognite_toolkit._cdf_tk.feature_flags import Flags from cognite_toolkit._cdf_tk.hints import ModuleDefinition, verify_module_directory from cognite_toolkit._cdf_tk.loaders import ( - KINDS_BY_FOLDER_NAME, ContainerLoader, DataLoader, DataModelLoader, ExtractionPipelineConfigLoader, + FileLoader, NodeLoader, RawDatabaseLoader, RawTableLoader, @@ -316,6 +316,10 @@ def _build_module_resources( # is warnings self.warning_list.extend(destination) continue + if Flags.REQUIRE_KIND.is_enabled() and destination.loader is FileLoader: + # This is a content file that we should not copy to the build directory. + continue + safe_write(destination.path, destination.content) if issubclass(destination.loader, DataLoader): continue @@ -428,16 +432,6 @@ def _replace_variables( for source_path in resource_files: if source_path.suffix.lower() not in TEMPLATE_VARS_FILE_SUFFIXES: continue - if ( - Flags.REQUIRE_KIND.is_enabled() - and source_path.suffix in YAML_SUFFIX - and all( - not source_path.stem.casefold().endswith(kind.casefold()) - for kind in KINDS_BY_FOLDER_NAME[resource_name] - ) - ): - # Skipping files that are not of the correct kind. - continue if verbose: self.console(f"Processing file {source_path.name}...") From 1b75017e57956f337397ad0424eb127aed7b4f8b Mon Sep 17 00:00:00 2001 From: anders-albert Date: Mon, 18 Nov 2024 20:49:17 +0100 Subject: [PATCH 4/4] fix: warnings --- cognite_toolkit/_cdf_tk/commands/build.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cognite_toolkit/_cdf_tk/commands/build.py b/cognite_toolkit/_cdf_tk/commands/build.py index c72405836..3e82f654b 100644 --- a/cognite_toolkit/_cdf_tk/commands/build.py +++ b/cognite_toolkit/_cdf_tk/commands/build.py @@ -313,8 +313,8 @@ def _build_module_resources( built_resources = BuiltResourceList[Hashable]() for destination in builder.build(source_files, module): if not isinstance(destination, BuildDestinationFile): - # is warnings - self.warning_list.extend(destination) + for warning in destination: + self.warn(warning) continue if Flags.REQUIRE_KIND.is_enabled() and destination.loader is FileLoader: # This is a content file that we should not copy to the build directory.