Skip to content

Commit

Permalink
deps: be verbose when installing snaps
Browse files Browse the repository at this point in the history
Otherwise things might look like they're hanging.
  • Loading branch information
Saviq committed Dec 9, 2024
1 parent 9ebe15c commit 95958fe
Showing 1 changed file with 29 additions and 12 deletions.
41 changes: 29 additions & 12 deletions mir-ci/mir_ci/conftest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import functools
import os
import pathlib
import re
import shutil
import subprocess
import time
import warnings
from collections.abc import Iterator
from typing import Any, Generator, List, Mapping, Optional, Union
Expand Down Expand Up @@ -48,6 +50,25 @@ def _deps_skip(request: pytest.FixtureRequest) -> None:
pytest.skip("dependency-only run")


def _snap_install(snap: str, channel: str, classic: bool):
"""
Install the (optionally classic) snap from the given channel. Tracks the change and prints
all changes in `Doing` state, raising an error if the change fails.
"""
_classic = ("--classic",) if classic else ()

Check warning on line 58 in mir-ci/mir_ci/conftest.py

View check run for this annotation

Codecov / codecov/patch

mir-ci/mir_ci/conftest.py#L58

Added line #L58 was not covered by tests
if change := subprocess.check_output(
("sudo", "snap", "install", "--no-wait", snap, "--channel", channel, *_classic),
text=True,
).strip():
while output := subprocess.check_output(("snap", "changes"), text=True):
if re.search(rf"^{change}\s+Done\s", output, re.MULTILINE):
return

Check warning on line 65 in mir-ci/mir_ci/conftest.py

View check run for this annotation

Codecov / codecov/patch

mir-ci/mir_ci/conftest.py#L65

Added line #L65 was not covered by tests
if re.search(rf"^{change}\s+Error\s", output, re.MULTILINE):
raise RuntimeError(subprocess.check_output(("snap", "tasks", change), text=True))
print("\n".join(line for line in output.splitlines() if "Doing" in line), flush=True)
time.sleep(10)

Check warning on line 69 in mir-ci/mir_ci/conftest.py

View check run for this annotation

Codecov / codecov/patch

mir-ci/mir_ci/conftest.py#L67-L69

Added lines #L67 - L69 were not covered by tests


def _deps_install(request: pytest.FixtureRequest, spec: Union[str, Mapping[str, Any]]) -> app.App:
"""
Install dependencies for the command spec provided. If `spec` is a string, it's assumed
Expand Down Expand Up @@ -100,18 +121,14 @@ def _deps_install(request: pytest.FixtureRequest, spec: Union[str, Mapping[str,
if snap:
checked_snaps = request.session.keywords.setdefault("snaps", set())
if snap not in checked_snaps:
try:
subprocess.check_call(("snap", "list", snap), stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
except subprocess.CalledProcessError:
_classic = ("--classic",) if classic else ()
subprocess.check_call(("sudo", "snap", "install", snap, "--channel", channel, *_classic))
if shutil.which(f"/snap/{snap}/current/bin/setup.sh"):
subprocess.check_call(("sudo", f"/snap/{snap}/current/bin/setup.sh"))
subprocess.call(
("sudo", "snap", "connect", f"{snap}:login-session-control"),
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
_snap_install(snap, channel, classic)

Check warning on line 124 in mir-ci/mir_ci/conftest.py

View check run for this annotation

Codecov / codecov/patch

mir-ci/mir_ci/conftest.py#L124

Added line #L124 was not covered by tests
if shutil.which(f"/snap/{snap}/current/bin/setup.sh"):
subprocess.check_call(("sudo", f"/snap/{snap}/current/bin/setup.sh"))
subprocess.call(

Check warning on line 127 in mir-ci/mir_ci/conftest.py

View check run for this annotation

Codecov / codecov/patch

mir-ci/mir_ci/conftest.py#L126-L127

Added lines #L126 - L127 were not covered by tests
("sudo", "snap", "connect", f"{snap}:login-session-control"),
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
if "MIR_CI_SNAP" in os.environ:
subprocess.call(
("sudo", "snap", "connect", f"{snap}:wayland", os.environ["MIR_CI_SNAP"]),
Expand Down

0 comments on commit 95958fe

Please sign in to comment.