Skip to content

Commit

Permalink
feat(updates, install_info_fetcher, print_dept): show warning if dev'…
Browse files Browse the repository at this point in the history
…s package stable release have newer version (fixes: #666)
  • Loading branch information
actionless committed Sep 18, 2024
1 parent 04b9554 commit c25d9cb
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 26 deletions.
21 changes: 16 additions & 5 deletions pikaur/install_info_fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,22 @@
AURInstallInfo,
AURPackageInfo,
ComparableType,
InstallInfo,
PackageSource,
RepoInstallInfo,
)
from .print_department import print_ignored_package, print_not_found_packages
from .prompt import ask_to_continue
from .replacements import find_replacements
from .srcinfo import SrcInfo
from .updates import find_aur_updates, print_upgradeable
from .updates import convert_devel_pgnames_to_stable, find_aur_updates, print_upgradeable
from .version import VersionMatcher

if TYPE_CHECKING:
from collections.abc import Sequence

from .args import PikaurArgs
from .pacman import PacmanPrint
from .pikatypes import InstallInfo

logger = create_logger("install_info_fetcher")

Expand All @@ -55,6 +55,7 @@ class InstallInfoFetcher(ComparableType): # noqa: PLR0904
aur_updates_install_info: list[AURInstallInfo]
aur_deps_install_info: list[AURInstallInfo]
_all_aur_updates_raw: list[AURInstallInfo]
_stable_versions_updates: dict[str, InstallInfo]

args: "PikaurArgs"
aur_deps_relations: dict[str, list[str]]
Expand Down Expand Up @@ -100,6 +101,7 @@ def __init__(
print_upgradeable(
ignored_only=True,
aur_install_infos=self._all_aur_updates_raw,
stable_versions_updates=self._stable_versions_updates,
)

def package_is_ignored(self, package_name: str) -> bool:
Expand Down Expand Up @@ -471,16 +473,22 @@ def get_aur_pkgs_info( # pylint: disable=too-many-branches
strip_aur_repo_name(version_matcher.pkg_name): version_matcher
for version_matcher in [VersionMatcher(name) for name in aur_packages_versionmatchers]
}
local_pkgs = PackageDB.get_local_dict()
local_pkg_names = PackageDB.get_local_pkgnames()
stable_names_of_devel_pkgs = convert_devel_pgnames_to_stable(
local_pkg_names,
)
logger.debug(
"gonna get AUR pkgs install info for:\n"
" aur_packages_versionmatchers={}\n"
" self.aur_updates_install_info={}\n"
" aur_packages_names_to_versions={}",
" aur_packages_names_to_versions={}\n"
" stable_names_of_devel_pkgs={}",
aur_packages_versionmatchers,
self.aur_updates_install_info,
aur_packages_names_to_versions,
stable_names_of_devel_pkgs,
)
local_pkgs = PackageDB.get_local_dict()
aur_pkg_list, not_found_aur_pkgs = find_aur_packages(
list(aur_packages_names_to_versions.keys()),
)
Expand All @@ -504,7 +512,10 @@ def get_aur_pkgs_info( # pylint: disable=too-many-branches
raise SysExit(6)
aur_updates_install_info_by_name: dict[str, AURInstallInfo] = {}
if self.args.sysupgrade:
self._all_aur_updates_raw, not_found_aur_pkgs = find_aur_updates()
self._all_aur_updates_raw, not_found_aur_pkgs, self._stable_versions_updates = \
find_aur_updates(
stable_names_of_devel_pkgs=stable_names_of_devel_pkgs,
)
self.exclude_ignored_packages(not_found_aur_pkgs, print_packages=False)
if not_found_aur_pkgs:
logger.debug("error code: 789sdfgh789sd6")
Expand Down
24 changes: 24 additions & 0 deletions pikaur/print_department.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,30 @@ def print_ignoring_outofdate_upgrade(package_info: InstallInfo) -> None:
)


def print_stable_version_upgrades(stable_versions_updates: dict[str, InstallInfo]) -> None:
print_warning(
translate("Stable versions of the following devel packages have newer versions:"),
)
for og_name, stable_version_update in sorted(
stable_versions_updates.items(), key=operator.itemgetter(0),
):
line = f" {bold_line(og_name)} ({stable_version_update.name})"
spacing = " " * (38 - printable_length(line))
print_stdout(
pretty_format_upgradeable(
[stable_version_update],
template=(
f"{line}{spacing}"
" {current_version}{spacing2}"
"{version_separator}{new_version}{spacing3}"
"{pkg_size}{days_old}{out_of_date}"
"{required_by_installed}"
"{verbose}"
),
),
)


# pylint:disable=too-many-statements,too-many-branches
def print_package_search_results( # noqa: PLR0914,C901
repo_packages: "Iterable[pyalpm.Package]",
Expand Down
85 changes: 64 additions & 21 deletions pikaur/updates.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Licensed under GPLv3, see https://www.gnu.org/licenses/"""

from datetime import datetime
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, cast

from .alpm import PacmanConfig
from .args import parse_args
Expand All @@ -16,11 +16,12 @@
get_ignored_pkgnames_from_patterns,
)
from .pikaprint import print_stderr, print_stdout
from .pikatypes import AURInstallInfo, RepoInstallInfo
from .pikatypes import AURInstallInfo, InstallInfo, RepoInstallInfo
from .print_department import (
pretty_format_upgradeable,
print_ignored_package,
print_ignoring_outofdate_upgrade,
print_stable_version_upgrades,
)
from .version import VERSION_DEVEL, compare_versions

Expand All @@ -30,7 +31,7 @@

import pyalpm

from .pikatypes import AURPackageInfo, InstallInfo
from .pikatypes import AURPackageInfo


DEVEL_PKGS_POSTFIXES: "Final" = (
Expand All @@ -43,15 +44,19 @@
)


def is_devel_pkg(pkg_name: str) -> bool:
result = False
def devel_pkgname_to_stable(pkg_name: str) -> str | None:
result = None
for devel_pkg_postfix in DEVEL_PKGS_POSTFIXES:
if pkg_name.endswith(devel_pkg_postfix):
result = True
result = pkg_name[:-len(devel_pkg_postfix)]
break
return result


def is_devel_pkg(pkg_name: str) -> bool:
return bool(devel_pkgname_to_stable(pkg_name))


def get_remote_package(
new_pkg_name: str,
) -> "pyalpm.Package | AURPackageInfo | None":
Expand Down Expand Up @@ -117,34 +122,61 @@ def find_aur_devel_updates(
return aur_updates


def find_aur_updates() -> tuple[list[AURInstallInfo], list[str]]:
def find_aur_updates( # pylint: disable=too-many-branches # noqa: PLR0914
stable_names_of_devel_pkgs: dict[str, str] | None = None,
) -> tuple[list[AURInstallInfo], list[str], dict[str, InstallInfo]]:
args = parse_args()
package_names = find_packages_not_from_repo()
print_stderr(translate_many(
"Reading AUR package info...",
"Reading AUR packages info...",
len(package_names),
))
aur_pkgs_info, not_found_aur_pkgs = find_aur_packages(package_names)
stable_names_of_devel_pkgs_stable = list((stable_names_of_devel_pkgs or {}).keys())
aur_pkgs_info, not_found_aur_pkgs = find_aur_packages(
package_names + stable_names_of_devel_pkgs_stable,
)
stable_versions_pkgs: dict[str, pyalpm.Package | AURPackageInfo] = {}
repo_pkg_names = PackageDB.get_repo_pkgnames()
for pkg_name in stable_names_of_devel_pkgs_stable:
if pkg_name in not_found_aur_pkgs:
not_found_aur_pkgs.remove(pkg_name)
if pkg_name in repo_pkg_names:
og_name = cast(dict[str, str], stable_names_of_devel_pkgs)[pkg_name]
# @TODO: replace to get_repo_package():
stable_versions_pkgs[og_name] = PackageDB.find_repo_package(pkg_name)
local_packages = PackageDB.get_local_dict()
aur_updates = []
stable_versions_updates = {}
aur_pkgs_up_to_date = []
for aur_pkg in aur_pkgs_info:
pkg_name = aur_pkg.name
aur_version = aur_pkg.version
current_version = local_packages[pkg_name].version
compare_aur_pkg = compare_versions(current_version, aur_version)
if compare_aur_pkg < 0:
pkg_install_info = AURInstallInfo(
package=aur_pkg,
if pkg_name in stable_names_of_devel_pkgs_stable:
og_name = cast(dict[str, str], stable_names_of_devel_pkgs)[pkg_name]
stable_versions_pkgs[og_name] = aur_pkg
else:
current_version = local_packages[pkg_name].version
compare_aur_pkg = compare_versions(current_version, aur_version)
if compare_aur_pkg < 0:
pkg_install_info = AURInstallInfo(
package=aur_pkg,
current_version=current_version,
)
if args.ignore_outofdate and aur_pkg.outofdate:
print_ignoring_outofdate_upgrade(pkg_install_info)
continue
aur_updates.append(pkg_install_info)
else:
aur_pkgs_up_to_date.append(aur_pkg)
for og_name, pkg in stable_versions_pkgs.items():
current_version = local_packages[og_name].version
compare_pkg = compare_versions(current_version, pkg.version)
if compare_pkg < 0:
stable_versions_updates[og_name] = InstallInfo(
package=pkg,
current_version=current_version,
)
if args.ignore_outofdate and aur_pkg.outofdate:
print_ignoring_outofdate_upgrade(pkg_install_info)
continue
aur_updates.append(pkg_install_info)
else:
aur_pkgs_up_to_date.append(aur_pkg)
if aur_pkgs_up_to_date:
sync_config = PikaurConfig().sync
devel_packages_expiration = sync_config.DevelPkgsExpiration.get_int()
Expand All @@ -155,11 +187,20 @@ def find_aur_updates() -> tuple[list[AURInstallInfo], list[str]]:
aur_pkgs_up_to_date,
package_ttl_days=devel_packages_expiration,
)
return aur_updates, not_found_aur_pkgs
return aur_updates, not_found_aur_pkgs, stable_versions_updates


def convert_devel_pgnames_to_stable(pkgs: list[str]) -> dict[str, str]:
return {
stable_name: pkg
for pkg in pkgs
if (stable_name := devel_pkgname_to_stable(pkg))
}


def print_upgradeable(
aur_install_infos: "Sequence[InstallInfo] | None" = None,
stable_versions_updates: dict[str, InstallInfo] | None = None,
*,
ignored_only: bool = False,
) -> None:
Expand All @@ -168,10 +209,12 @@ def print_upgradeable(
if aur_install_infos is not None:
updates += aur_install_infos
elif not args.repo:
aur_updates, _not_found_aur_pkgs = find_aur_updates()
aur_updates, _not_found_aur_pkgs, stable_versions_updates = find_aur_updates()
updates += aur_updates
if not args.aur:
updates += find_repo_upgradeable()
if stable_versions_updates:
print_stable_version_upgrades(stable_versions_updates)
if not updates:
return
pkg_names = [pkg.name for pkg in updates]
Expand Down

0 comments on commit c25d9cb

Please sign in to comment.