Skip to content

Commit f6b9f40

Browse files
committed
refactor(pikatypes: InstallInfo): initialize values based on pkg info
1 parent 10df8fa commit f6b9f40

File tree

6 files changed

+54
-87
lines changed

6 files changed

+54
-87
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ MANIFEST
1212
pikaur.1
1313
aur_db.dump*
1414
pikaur_static/pikaur/**
15+
pikaur_rust/pikaur/**
1516
docker_ci/

pikaur/install_info_fetcher.py

+6-21
Original file line numberDiff line numberDiff line change
@@ -285,12 +285,8 @@ def _get_pkg_install_infos(results: "list[PacmanPrint]") -> list[RepoInstallInfo
285285
pkg = all_repo_pkgs[pkg_print.full_name]
286286
local_pkg = all_local_pkgs.get(pkg.name)
287287
install_info = RepoInstallInfo(
288-
name=pkg.name,
289-
current_version=local_pkg.version if local_pkg else "",
290-
new_version=pkg.version,
291-
description=pkg.desc,
292-
repository=pkg.db.name,
293288
package=pkg,
289+
current_version=local_pkg.version if local_pkg else "",
294290
)
295291

296292
groups = install_info.package.groups
@@ -389,12 +385,8 @@ def get_upgradeable_repo_pkgs_info(self) -> list[RepoInstallInfo]:
389385
):
390386
local_pkg = all_local_pkgs.get(pkg.name)
391387
install_info = RepoInstallInfo(
392-
name=pkg.name,
393-
current_version=local_pkg.version if local_pkg else "",
394-
new_version=pkg.version,
395-
description=pkg.desc,
396-
repository=pkg.db.name,
397388
package=pkg,
389+
current_version=local_pkg.version if local_pkg else "",
398390
)
399391
pkg_install_infos.append(install_info)
400392
return pkg_install_infos
@@ -525,12 +517,8 @@ def get_aur_pkgs_info( # pylint: disable=too-many-branches
525517
continue
526518
local_pkg = local_pkgs.get(pkg_name)
527519
aur_updates_install_info_by_name[pkg_name] = AURInstallInfo(
528-
name=pkg_name,
529-
current_version=local_pkg.version if local_pkg else " ",
530-
new_version=aur_pkg.version,
531-
description=aur_pkg.desc,
532-
maintainer=aur_pkg.maintainer,
533520
package=aur_pkg,
521+
current_version=local_pkg.version if local_pkg else " ",
534522
)
535523
for pkg_name in list(aur_updates_install_info_by_name.keys())[:]:
536524
if pkg_name not in aur_updates_install_info_by_name:
@@ -571,12 +559,13 @@ def get_info_from_pkgbuilds(self) -> None:
571559
raise RuntimeError(translate(f"{pkg_name} already added to the list"))
572560
local_pkg = local_pkgs.get(pkg_name)
573561
info = AURInstallInfo(
562+
# @TODO: use data from srcinfo here?
563+
package=aur_pkg,
574564
name=pkg_name,
575565
current_version=local_pkg.version if local_pkg else " ",
576566
new_version=aur_pkg.version,
577567
description=aur_pkg.desc,
578568
maintainer="local user",
579-
package=aur_pkg,
580569
pkgbuild_path=path,
581570
)
582571
logger.debug(" 3 {} {} {}", info, info.package, info.package.packagebase)
@@ -640,12 +629,8 @@ def get_aur_deps_info(self) -> None:
640629
continue
641630
local_pkg = local_pkgs.get(pkg_name)
642631
self.aur_deps_install_info.append(AURInstallInfo(
643-
name=aur_pkg.name,
644-
current_version=local_pkg.version if local_pkg else " ",
645-
new_version=aur_pkg.version,
646-
description=aur_pkg.desc,
647-
maintainer=aur_pkg.maintainer,
648632
package=aur_pkg,
633+
current_version=local_pkg.version if local_pkg else " ",
649634
))
650635
added_pkg_names.append(aur_pkg.name)
651636

pikaur/pikatypes.py

+40-4
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ class PackageSource(enum.Enum):
6363
LOCAL = enum.auto()
6464

6565

66-
@dataclass(eq=False)
66+
@dataclass(eq=False, kw_only=True)
6767
class InstallInfo(ComparableType):
68-
name: str
6968
package: "pyalpm.Package | AURPackageInfo"
70-
new_version: str
71-
current_version: str
69+
name: str = ""
70+
new_version: str = ""
71+
current_version: str = ""
7272

7373
description: str | None = None
7474
maintainer: str | None = None
@@ -103,6 +103,42 @@ def __repr__(self) -> str:
103103
f"{self.current_version} -> {self.new_version}>"
104104
)
105105

106+
def __post_init__(self) -> None:
107+
pkg_type = (
108+
"aur"
109+
if isinstance(self.package, AURPackageInfo)
110+
else (
111+
"local"
112+
if self.package.db.name == "local"
113+
else "repo"
114+
)
115+
)
116+
if not self.name:
117+
self.name = self.package.name
118+
if not self.description:
119+
self.description = self.package.desc
120+
if pkg_type == "local":
121+
if not self.current_version:
122+
self.current_version = self.package.version
123+
if self.repository is None:
124+
self.repository = cast("pyalpm.Package", self.package).db.name
125+
if self.required_by_installed is None:
126+
self.required_by_installed = \
127+
cast("pyalpm.Package", self.package).compute_requiredby()
128+
if self.optional_for_installed is None:
129+
self.optional_for_installed = \
130+
cast("pyalpm.Package", self.package).compute_optionalfor()
131+
if self.installed_as_dependency is None:
132+
self.installed_as_dependency = \
133+
cast(bool, cast("pyalpm.Package", self.package).reason)
134+
else:
135+
if not self.new_version:
136+
self.new_version = self.package.version
137+
if pkg_type == "aur" and not self.maintainer:
138+
self.maintainer = cast(AURPackageInfo, self.package).maintainer
139+
if pkg_type == "repo" and not self.repository:
140+
self.repository = cast("pyalpm.Package", self.package).db.name
141+
106142

107143
@dataclass(eq=False)
108144
class RepoInstallInfo(InstallInfo):

pikaur/updates.py

+3-14
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,8 @@ def find_repo_upgradeable() -> list[RepoInstallInfo]:
8484
local_pkg = all_local_pkgs[repo_pkg.name]
8585
repo_packages_updates.append(
8686
RepoInstallInfo(
87-
name=local_pkg.name,
88-
new_version=repo_pkg.version,
89-
current_version=local_pkg.version,
90-
description=repo_pkg.desc,
91-
repository=repo_pkg.db.name,
9287
package=repo_pkg,
88+
current_version=local_pkg.version,
9389
),
9490
)
9591
return repo_packages_updates
@@ -113,13 +109,10 @@ def find_aur_devel_updates(
113109
pkg_age_days = (now - pkg_install_datetime).days
114110
if pkg_age_days >= package_ttl_days:
115111
aur_updates.append(AURInstallInfo(
116-
name=pkg_name,
112+
package=aur_pkg,
117113
current_version=local_pkg.version,
118114
new_version=VERSION_DEVEL,
119-
description=aur_pkg.desc,
120115
devel_pkg_age_days=pkg_age_days,
121-
maintainer=aur_pkg.maintainer,
122-
package=aur_pkg,
123116
))
124117
return aur_updates
125118

@@ -143,12 +136,8 @@ def find_aur_updates() -> tuple[list[AURInstallInfo], list[str]]:
143136
compare_aur_pkg = compare_versions(current_version, aur_version)
144137
if compare_aur_pkg < 0:
145138
pkg_install_info = AURInstallInfo(
146-
name=pkg_name,
147-
new_version=aur_version,
148-
current_version=current_version,
149-
description=aur_pkg.desc,
150-
maintainer=aur_pkg.maintainer,
151139
package=aur_pkg,
140+
current_version=current_version,
152141
)
153142
if args.ignore_outofdate and aur_pkg.outofdate:
154143
print_ignoring_outofdate_upgrade(pkg_install_info)

pikaur_meta_helpers/dep_tree.py

+2-44
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,14 @@
11
import sys
2-
from dataclasses import dataclass
3-
from typing import NamedTuple, cast
2+
from typing import NamedTuple
43

54
import pyalpm
65

76
from pikaur.pacman import PackageDB
87
from pikaur.pikaprint import ColorsHighlight, color_line, format_paragraph, get_term_width
9-
from pikaur.pikatypes import AURPackageInfo
10-
from pikaur.pikatypes import InstallInfo as InstallInfoOld
8+
from pikaur.pikatypes import InstallInfo
119
from pikaur.print_department import pretty_format_upgradeable
1210

1311

14-
@dataclass(eq=False, kw_only=True)
15-
class InstallInfo(InstallInfoOld):
16-
# @TODO: move it to the main module?
17-
name: str = ""
18-
new_version: str = ""
19-
current_version: str = ""
20-
21-
def __post_init__(self) -> None:
22-
pkg_type = (
23-
"aur"
24-
if isinstance(self.package, AURPackageInfo)
25-
else (
26-
"local"
27-
if self.package.db.name == "local"
28-
else "repo"
29-
)
30-
)
31-
if pkg_type == "local":
32-
if not self.current_version:
33-
self.current_version = self.package.version
34-
if self.required_by_installed is None:
35-
self.required_by_installed = \
36-
cast("pyalpm.Package", self.package).compute_requiredby()
37-
if self.optional_for_installed is None:
38-
self.optional_for_installed = \
39-
cast("pyalpm.Package", self.package).compute_optionalfor()
40-
if self.installed_as_dependency is None:
41-
self.installed_as_dependency = \
42-
cast(bool, cast("pyalpm.Package", self.package).reason)
43-
if not self.name:
44-
self.name = self.package.name
45-
if (
46-
(not self.new_version)
47-
and (pkg_type in {"aur", "repo"})
48-
):
49-
self.new_version = self.package.version
50-
if not self.description:
51-
self.description = self.package.desc
52-
53-
5412
class StackItem(NamedTuple):
5513
item_type: str # 'pkg' or 'title'
5614
content: str # Package name or title text

pikaur_test/test_unit_pikatypes.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,15 @@ class InstallInfoTest(PikaurTestCase):
115115
def setUpClass(cls):
116116
repo_pkg = PackageDB.get_repo_list()[0]
117117
cls.repo_install_info = InstallInfo(
118-
name=repo_pkg.name,
118+
package=repo_pkg,
119119
current_version=repo_pkg.version,
120120
new_version="420",
121-
package=repo_pkg,
122121
)
123122
aur_pkg = find_aur_packages(["pikaur"])[0][0]
124123
cls.aur_install_info = InstallInfo(
125-
name=aur_pkg.name,
124+
package=aur_pkg,
126125
current_version=aur_pkg.version,
127126
new_version="420",
128-
package=aur_pkg,
129127
)
130128

131129
def test_basic(self):

0 commit comments

Comments
 (0)