Repository: canonical/charmcraft

Issue:
The control of `bases` in `charmcraft.yaml` should be different for bundles
Currently it complains that there's no `bases`:

```
$ charmcraft revisions facutest-bundle-1
DEPRECATED: Bases configuration is now required.
See https://discourse.charmhub.io/t/4652#heading--dn03 for more information.
Revision    Version    Created at    Status
1           1          2021-02-03    released
```

But bundles do NOT have bases. So this check should be removed. And ANOTHER check should be implemented, to actually error out if the bundle's config has `bases` included (to avoid confusions).

Thanks!

Comments:

Patch:
diff --git a/charmcraft/config.py b/charmcraft/config.py
index ad62de2..79262ec 100644
--- a/charmcraft/config.py
+++ b/charmcraft/config.py
@@ -343,6 +343,17 @@ class Config(ModelConfigDefaults, validate_all=False):
         validate_part(item)
         return item
 
+    @pydantic.validator("bases", pre=True)
+    def validate_bases_presence(cls, bases, values):
+        """Forbid 'bases' in bundles.
+
+        This is to avoid a posible confusion of expecting the bundle
+        to be built in a specific environment
+        """
+        if values.get("type") == "bundle":
+            raise ValueError("Field not allowed when type=bundle")
+        return bases
+
     @classmethod
     def expand_short_form_bases(cls, bases: List[Dict[str, Any]]) -> None:
         """Expand short-form base configuration into long-form in-place."""
@@ -390,7 +401,8 @@ class Config(ModelConfigDefaults, validate_all=False):
             # type will simplify user facing errors.
             bases = obj.get("bases")
             if bases is None:
-                notify_deprecation("dn03")
+                if obj["type"] in (None, "charm"):
+                    notify_deprecation("dn03")
                 # Set default bases to Ubuntu 20.04 to match strict snap's
                 # effective behavior.
                 bases = [


Test patch:
diff --git a/tests/test_config.py b/tests/test_config.py
index 30a73dd..6b6db1b 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -537,6 +537,40 @@ def test_no_bases_defaults_to_ubuntu_20_04_with_dn03(caplog, create_config, tmp_
     ]
 
 
+def test_no_bases_is_ok_for_bundles(caplog, create_config, tmp_path):
+    """Do not send a deprecation message if it is a bundle."""
+    caplog.set_level(logging.WARNING, logger="charmcraft")
+    create_config(
+        """
+        type: bundle
+    """
+    )
+
+    load(tmp_path)
+    assert not caplog.records
+
+
+def test_bases_forbidden_for_bundles(create_config, check_schema_error):
+    """Do not allow a bases configuration for bundles."""
+    create_config(
+        """
+        type: bundle
+        bases:
+          - build-on:
+              - name: test-build-name
+                channel: test-build-channel
+    """
+    )
+
+    check_schema_error(
+        dedent(
+            """\
+            Bad charmcraft.yaml content:
+            - Field not allowed when type=bundle in field 'bases'"""
+        )
+    )
+
+
 def test_bases_minimal_long_form(create_config):
     tmp_path = create_config(
         """