Преглед изворни кода

feat: add schema deprecation warnings for v0.1.3

- Update version to 0.1.3
- Add deprecation warning when templates inherit variables from schemas
- Warning shows count and list of inherited variables
- Prepares for Phase 2 where schemas will be removed entirely

Co-authored-by: ChristianLempa <28359525+ChristianLempa@users.noreply.github.com>
copilot-swe-agent[bot] пре 1 месец
родитељ
комит
22aeb643cc
2 измењених фајлова са 52 додато и 1 уклоњено
  1. 1 1
      cli/__init__.py
  2. 51 0
      cli/core/template/template.py

+ 1 - 1
cli/__init__.py

@@ -2,6 +2,6 @@
 Boilerplates CLI - A sophisticated command-line tool for managing infrastructure boilerplates.
 """
 
-__version__ = "0.1.2"
+__version__ = "0.1.3"
 __author__ = "Christian Lempa"
 __description__ = "CLI tool for managing infrastructure boilerplates"

+ 51 - 0
cli/core/template/template.py

@@ -394,6 +394,10 @@ class Template:
     def _load_module_specs_for_schema(kind: str, schema_version: str) -> dict:
         """Load specifications from the corresponding module for a specific schema version.
 
+        DEPRECATION NOTICE (v0.1.3): Module schemas are being deprecated. Templates should define
+        all variables in their template.yaml spec section. In future versions, this method will
+        return an empty dict and templates will need to be self-contained.
+
         Uses LRU cache to avoid re-loading the same module spec multiple times.
         This significantly improves performance when listing many templates of the same kind.
 
@@ -464,6 +468,51 @@ class Template:
 
         return merged_spec
 
+    def _warn_about_inherited_variables(self, module_specs: dict, template_specs: dict) -> None:
+        """Warn about variables inherited from module schemas (deprecation warning).
+
+        DEPRECATION (v0.1.3): Templates should define all variables explicitly in template.yaml.
+        This method detects variables that come from module schemas and warns users to add them
+        to the template spec.
+
+        Args:
+            module_specs: Variables defined in module schema
+            template_specs: Variables defined in template.yaml
+        """
+        # Skip if no module specs (already self-contained)
+        if not module_specs:
+            return
+
+        # Collect variables from module specs
+        module_vars = set()
+        for section_data in module_specs.values():
+            if isinstance(section_data, dict) and "vars" in section_data:
+                module_vars.update(section_data["vars"].keys())
+
+        # Collect variables explicitly defined in template
+        template_vars = set()
+        for section_data in (template_specs or {}).values():
+            if isinstance(section_data, dict) and "vars" in section_data:
+                template_vars.update(section_data["vars"].keys())
+
+        # Find variables inherited from module (not overridden in template)
+        inherited_vars = module_vars - template_vars
+
+        if inherited_vars:
+            # Only warn once per template (use a flag to avoid repeated warnings)
+            if not hasattr(self, "_schema_deprecation_warned"):
+                self._schema_deprecation_warned = True
+                logger.warning(
+                    f"DEPRECATION WARNING: Template '{self.id}' inherits {len(inherited_vars)} variables "
+                    f"from module schema (kind='{self._template_data.get('kind')}', schema={self.schema_version}). "
+                    f"In future versions, templates must define all variables in template.yaml. "
+                    f"Inherited variables: {', '.join(sorted(list(inherited_vars)[:10]))}{'...' if len(inherited_vars) > 10 else ''}"
+                )
+                logger.debug(
+                    f"Template '{self.id}' should add these variables to template.yaml spec: "
+                    f"{sorted(inherited_vars)}"
+                )
+
     def _collect_template_files(self) -> None:
         """Collects all TemplateFile objects in the template directory."""
         template_files: list[TemplateFile] = []
@@ -876,6 +925,8 @@ class Template:
     @property
     def merged_specs(self) -> dict:
         if self.__merged_specs is None:
+            # Warn about inherited variables (deprecation)
+            self._warn_about_inherited_variables(self.module_specs, self.template_specs)
             self.__merged_specs = self._merge_specs(self.module_specs, self.template_specs)
         return self.__merged_specs