Skip to content

Commit

Permalink
feat(print_dept: pformat_sysupgrade; core: install_info; install_info…
Browse files Browse the repository at this point in the history
…_fetcher): split `required_by_installed` and `optional_for_installed` in pkg InstallInfo object
  • Loading branch information
actionless committed Aug 21, 2024
1 parent f7a3c4a commit e3e5576
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
6 changes: 5 additions & 1 deletion pikaur/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,15 @@ class InstallInfo(DataType):
provided_by: list["pyalpm.Package | AURPackageInfo"] | None = None
required_by: list["InstallInfo"] | None = None
required_by_installed: list[str] | None = None
optional_for_installed: list[str] | None = None
members_of: list[str] | None = None
replaces: list[str] | None = None
pkgbuild_path: str | None = None

__ignore_in_eq__ = ("package", "provided_by", "pkgbuild_path", "required_by_installed")
__ignore_in_eq__ = (
"package", "provided_by", "pkgbuild_path",
"required_by_installed", "optional_for_installed",
)

@property
def package_source(self) -> PackageSource:
Expand Down
3 changes: 2 additions & 1 deletion pikaur/install_info_fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,8 @@ def mark_dependent(self) -> None:
):
req = local_pkg.compute_requiredby()
opt = local_pkg.compute_optionalfor()
pkg_install_info.required_by_installed = (req or []) + (opt or [])
pkg_install_info.required_by_installed = req or []
pkg_install_info.optional_for_installed = opt or []

logger.debug("== marked dependant pkgs.")

Expand Down
33 changes: 20 additions & 13 deletions pikaur/print_department.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,14 @@ def pretty_format( # pylint:disable=R0912 # noqa: PLR0914
elif print_repo:
pkg_name = f"{_color_line('aur/', ColorsHighlight.red)}{pkg_name}"

def pformat_deps(required_by_names: list[str], dep_color: int) -> str:
def pformat_deps(
required_by_names: list[str],
dep_color: int,
template: str = translate("for {pkg}"),
) -> str:
if not required_by_names:
return ""
required_for_formatted = translate("for {pkg}").format(
required_for_formatted = template.format(
pkg=_color_line(", ", dep_color).join([
_color_line(name, dep_color + 8) for name in required_by_names
]) + _color_line("", dep_color, reset=False),
Expand Down Expand Up @@ -321,18 +325,21 @@ def pformat_deps(required_by_names: list[str], dep_color: int) -> str:
else f"\n{format_paragraph(pkg_update.description)}"
),
required_by_installed=(
"" if not (required_by_installed and pkg_update.required_by_installed)
else "".join(("\n", format_paragraph(
pformat_deps(
required_by_names=(
pkg_update.required_by_installed
if (required_by_installed and pkg_update.required_by_installed)
else []
"".join((
"".join(("\n", format_paragraph(
pformat_deps(
required_by_names=items or [],
dep_color=color,
template=template,
),
dep_color=Colors.cyan,
),
padding=2,
)))
padding=2,
)))
for template, color, items in (
("required by {pkg}", Colors.cyan, pkg_update.required_by_installed),
("optional for {pkg}", Colors.purple, pkg_update.optional_for_installed),
)
if (required_by_installed and items)
))
),
), sort_by

Expand Down

0 comments on commit e3e5576

Please sign in to comment.