Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps: be verbose when installing snaps #155

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@
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
Loading