Merge ~pelpsi/lpci:backward-compatibility into lpci:main

Proposed by Simone Pelosi
Status: Merged
Approved by: Simone Pelosi
Approved revision: 7a08f5f307e2e9b7a5371d09638bcd1bdc0e2b3a
Merge reported by: Simone Pelosi
Merged at revision: 7a08f5f307e2e9b7a5371d09638bcd1bdc0e2b3a
Proposed branch: ~pelpsi/lpci:backward-compatibility
Merge into: lpci:main
Diff against target: 94 lines (+28/-1)
4 files modified
NEWS.rst (+6/-0)
docs/configuration.rst (+7/-0)
lpcraft/commands/tests/test_run.py (+3/-0)
lpcraft/config.py (+12/-1)
Reviewer Review Type Date Requested Status
Jürgen Gmach Approve
Colin Watson (community) Approve
Review via email: mp+440492@code.launchpad.net

Commit message

Forced classic to True if snaps are configured as string

If snaps are configured as string the classic confinement is forced
to improve backward compatibility

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) wrote :

LGTM. Please remember to fix the resulting deprecation warning in Launchpad's own `.launchpad.yaml` after this is on stable. :-)

review: Approve
Revision history for this message
Colin Watson (cjwatson) :
Revision history for this message
Jürgen Gmach (jugmac00) wrote :

Looks good!

- please add a news entry for this fix
- I would suggest to add a sentence to the documentation that the default value for classic is True when defining snaps as a list of strings, but also mention that this way is deprecated and the new way should be used
- typo in the commit message: confinment -> confinement

review: Approve
Revision history for this message
Jürgen Gmach (jugmac00) wrote :

Sorry for the late note.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/NEWS.rst b/NEWS.rst
2index 67eb3af..7ce8031 100644
3--- a/NEWS.rst
4+++ b/NEWS.rst
5@@ -2,6 +2,12 @@
6 Version history
7 ===============
8
9+0.0.52 (Unreleased)
10+===================
11+- Fix regression from adding support to snap keys
12+ passed as strings. For these keys confinement classic
13+ must be True by default to ensure backward compatibility.
14+
15 0.0.51 (2023-04-05)
16 ===================
17 - Add support for snap's channel and confinement level.
18diff --git a/docs/configuration.rst b/docs/configuration.rst
19index 4a3b255..5875b36 100644
20--- a/docs/configuration.rst
21+++ b/docs/configuration.rst
22@@ -191,6 +191,13 @@ Snap properties
23 <https://snapcraft.io/docs/snap-confinement>`_.
24 Default value: False.
25
26+.. note::
27+
28+ To ensure backward compatibility default value for
29+ classic is True when defining snaps as a list of strings.
30+ (i.e. [chromium, firefox]).
31+ Please note that this format for defining snaps is deprecated.
32+
33 .. _package-repositories:
34
35 Package-repositories properties
36diff --git a/lpcraft/commands/tests/test_run.py b/lpcraft/commands/tests/test_run.py
37index 361661c..b1fc6c2 100644
38--- a/lpcraft/commands/tests/test_run.py
39+++ b/lpcraft/commands/tests/test_run.py
40@@ -2103,6 +2103,7 @@ class TestRun(RunBaseTestCase):
41 "chromium",
42 "--channel",
43 "latest/stable",
44+ "--classic",
45 ],
46 check=True,
47 capture_output=True,
48@@ -2125,6 +2126,7 @@ class TestRun(RunBaseTestCase):
49 "firefox",
50 "--channel",
51 "latest/stable",
52+ "--classic",
53 ],
54 check=True,
55 capture_output=True,
56@@ -2259,6 +2261,7 @@ class TestRun(RunBaseTestCase):
57 "firefox",
58 "--channel",
59 "latest/stable",
60+ "--classic",
61 ],
62 check=True,
63 capture_output=True,
64diff --git a/lpcraft/config.py b/lpcraft/config.py
65index 0fdb9b4..0d3db3d 100644
66--- a/lpcraft/config.py
67+++ b/lpcraft/config.py
68@@ -8,6 +8,7 @@ from pathlib import Path
69 from typing import Any, Dict, Iterator, List, Optional, Tuple, Type, Union
70
71 import pydantic
72+from craft_cli import emit
73 from pydantic import AnyHttpUrl, StrictStr, root_validator, validator
74
75 from lpcraft.errors import ConfigurationError
76@@ -304,7 +305,17 @@ class Job(ModelConfigDefaults):
77 for value in v:
78 # Backward compatibility, i.e. [chromium, firefox]
79 if type(value) is str:
80- clean_values.append({"name": value})
81+ emit.message(
82+ f"Warning: You configured snap `{value}` but "
83+ + "you used a deprecated format. "
84+ + "\nPlease use "
85+ + f"\n...\n-name: {value}\n"
86+ + " classic: True\n...\n"
87+ + "instead.\n"
88+ + "Please refer to the documentation for an "
89+ + "overview of supported formats.",
90+ )
91+ clean_values.append({"name": value, "classic": True})
92 elif type(value) is dict:
93 if "name" not in value or value["name"] is None:
94 raise ValueError(

Subscribers

People subscribed via source and target branches