← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~pelpsi/lpcraft:snaps-key-improved-to-specify-channel-and-classic-parameters into lpcraft:main

 

Simone Pelosi has proposed merging ~pelpsi/lpcraft:snaps-key-improved-to-specify-channel-and-classic-parameters into lpcraft:main.

Commit message:
Added support for channel and classic parameters
    
Snap keys now support channel and classic parameters.
Snap key new syntax <name>:<channel>:<classic>

LP: #1995101


Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #1995101 in lpcraft: "snaps key doesn't allow to specify which channel to use for a snap"
  https://bugs.launchpad.net/lpcraft/+bug/1995101

For more details, see:
https://code.launchpad.net/~pelpsi/lpcraft/+git/lpcraft/+merge/440175
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~pelpsi/lpcraft:snaps-key-improved-to-specify-channel-and-classic-parameters into lpcraft:main.
diff --git a/docs/configuration.rst b/docs/configuration.rst
index d25c96d..549d6d6 100644
--- a/docs/configuration.rst
+++ b/docs/configuration.rst
@@ -63,6 +63,13 @@ Job definitions
 
 ``snaps`` (optional)
     Snaps to install as dependencies of this job.
+    Snap syntax <name>:<channel (default: latest/stable)>:<classic (default: not classic)>
+    Example:
+        .. code:: yaml
+            snaps:
+                - black:22/stable:classic
+                - vim
+                - firefox::classic
 
 ``environment`` (optional)
     A mapping of environment variable names to values, to be set while
diff --git a/lpcraft/commands/run.py b/lpcraft/commands/run.py
index c0e00d9..26a2071 100644
--- a/lpcraft/commands/run.py
+++ b/lpcraft/commands/run.py
@@ -543,12 +543,27 @@ def _run_job(
     ) as instance:
         snaps = list(itertools.chain(*pm.hook.lpcraft_install_snaps()))
         for snap in snaps:
-            emit.progress(f"Running `snap install {snap}`")
+            snap_unpacked = snap.split(":")
+            snap = snap_unpacked[0]
+            channel = (
+                snap_unpacked[1]
+                if len(snap_unpacked) > 1 and snap_unpacked[1].strip() != ""
+                else "latest/stable"
+            )
+            classic = (
+                snap_unpacked[2] == "classic"
+                if len(snap_unpacked) > 2
+                else False
+            )
+            classic_string = "classic" if classic else ""
+            emit.progress(
+                f"Running `snap install {snap} {channel} {classic_string}`"
+            )
             install_from_store(
                 executor=instance,
                 snap_name=snap,
-                channel="latest/stable",
-                classic=True,
+                channel=channel,
+                classic=classic,
             )
         packages = list(itertools.chain(*pm.hook.lpcraft_install_packages()))
         if packages:
diff --git a/lpcraft/commands/tests/test_run.py b/lpcraft/commands/tests/test_run.py
index 4466295..f6ab514 100644
--- a/lpcraft/commands/tests/test_run.py
+++ b/lpcraft/commands/tests/test_run.py
@@ -1985,7 +1985,7 @@ class TestRun(RunBaseTestCase):
                     series: focal
                     architectures: amd64
                     run: tox
-                    snaps: [chromium, firefox]
+                    snaps: [chromium::classic, firefox::classic]
             """
         )
         Path(".launchpad.yaml").write_text(config)