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

Port over some changes from #798 #1478

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
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
21 changes: 12 additions & 9 deletions bin/lib/ce_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

from lib.amazon_properties import get_properties_compilers_and_libraries
from lib.config_safe_loader import ConfigSafeLoader
from lib.installable.installable import Installable
from lib.installation import installers_for
from lib.installation_context import InstallationContext
from lib.installable.installable import Installable
from lib.library_yaml import LibraryYaml

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -91,10 +91,10 @@ def filter_aggregate(filters: list, installable: Installable, filter_match_all:
return all(filter_generator) if filter_match_all else any(filter_generator)


def squash_mount_check(rootfolder, subdir, context):
for filename in os.listdir(os.path.join(rootfolder, subdir)):
def squash_mount_check(rootfolder: Path, subdir: str, context: CliContext) -> None:
for filename in os.listdir(rootfolder / subdir):
if filename.endswith(".img"):
checkdir = Path(os.path.join("/opt/compiler-explorer/", subdir, filename[:-4]))
checkdir = Path("/opt/compiler-explorer/") / subdir / filename[:-4]
if not checkdir.exists():
_LOGGER.error("Missing mount point %s", checkdir)
else:
Expand Down Expand Up @@ -215,7 +215,7 @@ def cli(
file_handler.setFormatter(formatter)
root_logger.addHandler(file_handler)
if not log or log_to_console:
console_handler = logging.StreamHandler(sys.stdout)
console_handler = logging.StreamHandler(sys.stderr)
console_handler.setFormatter(formatter)
root_logger.addHandler(console_handler)
context = InstallationContext(
Expand All @@ -242,12 +242,15 @@ def cli(

@cli.command(name="list")
@click.pass_obj
@click.option("--json", is_flag=True, help="Output in JSON format")
@click.option("--installed-only", is_flag=True, help="Only output installed targets")
@click.argument("filter_", metavar="FILTER", nargs=-1)
def list_cmd(context: CliContext, filter_: List[str]):
def list_cmd(context: CliContext, filter_: List[str], json: bool, installed_only: bool):
"""List installation targets matching FILTER."""
print("Installation candidates:")
for installable in context.get_installables(filter_):
print(installable.name)
if installed_only and not installable.is_installed():
continue
print(installable.to_json() if json else installable.name)
_LOGGER.debug(installable)


Expand Down Expand Up @@ -385,7 +388,7 @@ def squash_check(context: CliContext, filter_: List[str], image_dir: Path):
exit(1)

for installable in context.get_installables(filter_):
destination = Path(image_dir / f"{installable.install_path}.img")
destination = image_dir / f"{installable.install_path}.img"
if installable.nightly_like:
if destination.exists():
_LOGGER.error("Found squash: %s for nightly", installable.name)
Expand Down
9 changes: 9 additions & 0 deletions bin/lib/installable/installable.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import json
import logging
import os
import re
Expand All @@ -24,6 +25,8 @@

nightlies: NightlyVersions = NightlyVersions(_LOGGER)

SimpleJsonType = (int, float, str, bool)


class Installable:
_check_link: Optional[Callable[[], bool]]
Expand Down Expand Up @@ -60,6 +63,12 @@ def __init__(self, install_context: InstallationContext, config: Dict[str, Any])
self._logger = logging.getLogger(self.name)
self.install_path_symlink = self.config_get("symlink", False)

def to_json_dict(self) -> Dict[str, Any]:
return {key: value for key, value in self.__dict__.items() if isinstance(value, SimpleJsonType)}

def to_json(self) -> str:
return json.dumps(self.to_json_dict())

def _resolve(self, all_installables: Dict[str, Installable]):
try:
self.depends = [all_installables[dep] for dep in self.depends_by_name]
Expand Down