Skip to content

Commit ada5b2c

Browse files
committed
portage.dep.Atom: remove str subtyping
1 parent 86153d6 commit ada5b2c

24 files changed

Lines changed: 306 additions & 176 deletions

bin/quickpkg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ def quickpkg_atom(options, infos, arg, eout):
7171
eout.eerror(f"Invalid atom: {arg}")
7272
infos["missing"].append(arg)
7373
return 1
74-
if atom[:1] == "=" and arg[:1] != "=":
74+
# Check if dep_expand added an operator that wasn't in the original arg
75+
if atom.operator == "=" and not str(arg).startswith("="):
7576
# dep_expand() allows missing '=' but it's really invalid
7677
eout.eerror(f"Invalid atom: {arg}")
7778
infos["missing"].append(arg)

lib/_emerge/BlockerCache.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Distributed under the terms of the GNU General Public License v2
33

44
import errno
5+
from portage.dep import Atom
56
from portage.util import writemsg
67
from portage.data import secpass
78
import portage
@@ -99,10 +100,10 @@ def _load(self):
99100
continue
100101
invalid_atom = False
101102
for atom in atoms:
102-
if not isinstance(atom, str):
103+
if not isinstance(atom, (str, Atom)):
103104
invalid_atom = True
104105
break
105-
if atom[:1] != "!" or not portage.isvalidatom(
106+
if str(atom)[:1] != "!" or not portage.isvalidatom(
106107
atom, allow_blockers=True
107108
):
108109
invalid_atom = True

lib/_emerge/BlockerDB.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ def findInstalledBlockers(self, new_pkg):
7676
)
7777
continue
7878

79-
blocker_atoms = [atom for atom in atoms if atom.startswith("!")]
80-
blocker_atoms.sort()
79+
blocker_atoms = [atom for atom in atoms if atom.blocker]
80+
blocker_atoms.sort(key=str)
8181
blocker_cache[inst_pkg.cpv] = blocker_cache.BlockerData(
8282
inst_pkg.counter, blocker_atoms
8383
)
@@ -113,7 +113,7 @@ def findInstalledBlockers(self, new_pkg):
113113
show_invalid_depstring_notice(new_pkg, atoms)
114114
assert False
115115

116-
blocker_atoms = [atom.lstrip("!") for atom in atoms if atom[:1] == "!"]
116+
blocker_atoms = [str(atom).lstrip("!") for atom in atoms if atom.blocker]
117117
if blocker_atoms:
118118
blocker_atoms = InternalPackageSet(initial_atoms=blocker_atoms)
119119
for inst_pkg in installed_pkgs:

lib/_emerge/actions.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,16 +1753,16 @@ def action_deselect(settings, trees, opts, atoms):
17531753
expanded_atoms = set(atoms)
17541754

17551755
for atom in atoms:
1756-
if not atom.startswith(SETPREFIX):
1757-
if atom.cp.startswith("null/"):
1756+
if not str(atom).startswith(SETPREFIX):
1757+
if atom.category == "null":
17581758
# try to expand category from world set
17591759
null_cat, pn = portage.catsplit(atom.cp)
17601760
for world_atom in world_atoms:
17611761
cat, world_pn = portage.catsplit(world_atom.cp)
17621762
if pn == world_pn:
17631763
expanded_atoms.add(
17641764
Atom(
1765-
atom.replace("null", cat, 1),
1765+
str(atom).replace("null", cat, 1),
17661766
allow_repo=True,
17671767
allow_wildcard=True,
17681768
)
@@ -1775,27 +1775,27 @@ def action_deselect(settings, trees, opts, atoms):
17751775
discard_atoms = set()
17761776
for atom in world_set:
17771777
for arg_atom in expanded_atoms:
1778-
if arg_atom.startswith(SETPREFIX):
1779-
if atom.startswith(SETPREFIX) and arg_atom == atom:
1778+
if str(arg_atom).startswith(SETPREFIX):
1779+
if str(atom).startswith(SETPREFIX) and arg_atom == atom:
17801780
discard_atoms.add(atom)
17811781
break
17821782
else:
17831783
if (
1784-
not atom.startswith(SETPREFIX)
1784+
not str(atom).startswith(SETPREFIX)
17851785
and arg_atom.intersects(atom)
17861786
and not (arg_atom.slot and not atom.slot)
17871787
and not (arg_atom.repo and not atom.repo)
17881788
):
17891789
discard_atoms.add(atom)
17901790
break
17911791
if discard_atoms:
1792-
for atom in sorted(discard_atoms):
1792+
for atom in sorted(discard_atoms, key=str):
17931793
if pretend:
17941794
action_desc = "Would remove"
17951795
else:
17961796
action_desc = "Removing"
17971797

1798-
if atom.startswith(SETPREFIX):
1798+
if str(atom).startswith(SETPREFIX):
17991799
filename = "world_sets"
18001800
else:
18011801
filename = "world"
@@ -2095,7 +2095,7 @@ def action_info(settings, trees, myopts, myfiles):
20952095
if not atom.blocker:
20962096
atoms.append((x, atom))
20972097

2098-
myvars = sorted(set(atoms))
2098+
myvars = sorted(set(atoms), key=lambda t: str(t[0]))
20992099

21002100
cp_map = {}
21012101
cp_max_len = 0
@@ -3956,11 +3956,11 @@ def emergeexitsig(signum, frame):
39563956
# look at the ebuilds, since EAPI 4 allows running pkg_info
39573957
# on non-installed packages
39583958
valid_atom = dep_expand(x, mydb=vardb)
3959-
if valid_atom.cp.split("/")[0] == "null":
3959+
if valid_atom.category == "null":
39603960
valid_atom = dep_expand(x, mydb=portdb)
39613961

39623962
if (
3963-
valid_atom.cp.split("/")[0] == "null"
3963+
valid_atom.category == "null"
39643964
and "--usepkg" in emerge_config.opts
39653965
):
39663966
valid_atom = dep_expand(x, mydb=bindb)

lib/_emerge/create_world_atom.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def create_world_atom(pkg, args_set, root_config, before_install=False):
113113
# gcc for example.
114114
system_atom = sets["system"].findAtomForPackage(pkg)
115115
if system_atom:
116-
if not system_atom.cp.startswith("virtual/"):
116+
if system_atom.category != "virtual":
117117
return None
118118
# System virtuals aren't safe to exclude from world since they can
119119
# match multiple old-style virtuals but only one of them will be

lib/_emerge/depgraph.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3663,7 +3663,7 @@ def _add_pkg_soname_deps(self, pkg, allow_unsatisfied=False):
36633663
continue
36643664
dep = Dependency(
36653665
atom=atom,
3666-
blocker=False,
3666+
blocker=None,
36673667
depth=depth,
36683668
parent=pkg,
36693669
priority=self._priority(cross=self._cross(pkg.root), runtime=True),
@@ -4700,7 +4700,7 @@ def _queue_disjunctive_deps(
47004700
# Note: Eventually this will check for PROPERTIES=virtual
47014701
# or whatever other metadata gets implemented for this
47024702
# purpose.
4703-
if x.cp.startswith("virtual/"):
4703+
if x.category == "virtual":
47044704
disjunctions.append(x)
47054705
else:
47064706
yield x
@@ -5121,8 +5121,10 @@ def _select_files(self, myfiles):
51215121
if len(expanded_atoms) > 1:
51225122
number_of_virtuals = 0
51235123
for expanded_atom in expanded_atoms:
5124-
if expanded_atom.cp.startswith(
5125-
("acct-group/", "acct-user/", "virtual/")
5124+
if expanded_atom.category in (
5125+
"acct-group",
5126+
"acct-user",
5127+
"virtual",
51265128
):
51275129
number_of_virtuals += 1
51285130
else:
@@ -5152,7 +5154,8 @@ def _select_files(self, myfiles):
51525154
if virts_p:
51535155
# Allow the depgraph to choose which virtual.
51545156
atom = Atom(
5155-
null_atom.replace("null/", "virtual/", 1), allow_repo=True
5157+
str(null_atom).replace("null/", "virtual/", 1),
5158+
allow_repo=True,
51565159
)
51575160
else:
51585161
atom = null_atom
@@ -5304,7 +5307,7 @@ def _resolve(self, myfavorites):
53045307
pprovideddict = pkgsettings.pprovideddict
53055308
virtuals = pkgsettings.getvirtuals()
53065309

5307-
for atom in sorted(arg.pset.getAtoms()):
5310+
for atom in sorted(arg.pset.getAtoms(), key=str):
53085311
self._spinner_update()
53095312
dep = Dependency(atom=atom, onlydeps=onlydeps, root=myroot, parent=arg)
53105313
try:
@@ -5353,7 +5356,7 @@ def _resolve(self, myfavorites):
53535356
pprovided_match = False
53545357
for virt_choice in virtuals.get(atom.cp, []):
53555358
expanded_atom = portage.dep.Atom(
5356-
atom.replace(atom.cp, virt_choice.cp, 1)
5359+
str(atom).replace(atom.cp, virt_choice.cp, 1)
53575360
)
53585361
pprovided = pprovideddict.get(expanded_atom.cp)
53595362
if pprovided and portage.match_from_list(
@@ -5393,7 +5396,7 @@ def _resolve(self, myfavorites):
53935396
if atom.cp != pkg.cp:
53945397
# For old-style virtuals, we need to repeat the
53955398
# package.provided check against the selected package.
5396-
expanded_atom = atom.replace(atom.cp, pkg.cp)
5399+
expanded_atom = str(atom).replace(atom.cp, pkg.cp)
53975400
pprovided = pprovideddict.get(pkg.cp)
53985401
if pprovided and portage.match_from_list(
53995402
expanded_atom, pprovided
@@ -5955,7 +5958,7 @@ def _expand_virt_from_graph(self, root, atom):
59555958
if not isinstance(atom, Atom):
59565959
atom = Atom(atom)
59575960

5958-
if not atom.cp.startswith("virtual/"):
5961+
if atom.category != "virtual":
59595962
yield atom
59605963
return
59615964

@@ -6783,7 +6786,7 @@ def _show_unsatisfied_dep(
67836786
mask_docs = True
67846787
else:
67856788
cp_exists = False
6786-
if atom.package and not atom.cp.startswith("null/"):
6789+
if atom.package and atom.category != "null":
67876790
for pkg in self._iter_match_pkgs_any(root_config, Atom(atom.cp)):
67886791
cp_exists = True
67896792
break
@@ -8453,7 +8456,7 @@ def _complete_graph(self, required_sets=None):
84538456

84548457
self._set_args(args)
84558458
for arg in self._expand_set_args(args, add_to_digraph=True):
8456-
for atom in sorted(arg.pset.getAtoms()):
8459+
for atom in sorted(arg.pset.getAtoms(), key=str):
84578460
if not self._add_dep(
84588461
Dependency(
84598462
atom=atom,
@@ -8766,7 +8769,7 @@ def _validate_blockers(self):
87668769
show_invalid_depstring_notice(pkg, atoms)
87678770
return False
87688771
blocker_atoms = [myatom for myatom in atoms if myatom.blocker]
8769-
blocker_atoms.sort()
8772+
blocker_atoms.sort(key=str)
87708773
blocker_cache[cpv] = blocker_cache.BlockerData(
87718774
pkg.counter, blocker_atoms
87728775
)
@@ -11193,7 +11196,7 @@ def _loadResumeCommand(self, resume_data, skip_masked=True, skip_missing=True):
1119311196
# added via _add_pkg() so that they are included in the
1119411197
# digraph (needed at least for --tree display).
1119511198
for arg in self._expand_set_args(args, add_to_digraph=True):
11196-
for atom in sorted(arg.pset.getAtoms()):
11199+
for atom in sorted(arg.pset.getAtoms(), key=str):
1119711200
pkg, existing_node = self._select_package(
1119811201
arg.root_config.root, atom
1119911202
)
@@ -11495,7 +11498,7 @@ def match_pkgs(self, atom):
1149511498
if (
1149611499
pkg is not None
1149711500
and atom.sub_slot is None
11498-
and pkg.cp.startswith("virtual/")
11501+
and pkg.category == "virtual"
1149911502
and (
1150011503
(
1150111504
"remove" not in self._depgraph._dynamic_config.myparams
@@ -11587,7 +11590,7 @@ def _visible(self, pkg, atom_set, avoid_slot_conflict=True, probe_virt_update=Tr
1158711590
if not self._depgraph._equiv_ebuild_visible(pkg):
1158811591
return False
1158911592

11590-
if pkg.cp.startswith("virtual/"):
11593+
if pkg.category == "virtual":
1159111594
if not self._depgraph._virt_deps_visible(pkg, ignore_use=True):
1159211595
return False
1159311596

lib/_emerge/resolver/output.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# Copyright 2010-2020 Gentoo Authors
22
# Distributed under the terms of the GNU General Public License v2
33

4-
"""Resolver output display operation.
5-
"""
4+
"""Resolver output display operation."""
65

76
__all__ = (
87
"Display",
@@ -951,7 +950,7 @@ def format_unmatched_atom(pkg, atom, pkg_use_enabled):
951950
def perform_coloring():
952951
atom_str = ""
953952
marker_str = ""
954-
for ii, x in enumerate(atom):
953+
for ii, x in enumerate(str(atom)):
955954
if ii in highlight:
956955
atom_str += colorize("BAD", x)
957956
marker_str += "^"
@@ -962,7 +961,7 @@ def perform_coloring():
962961

963962
if atom.cp != pkg.cp:
964963
# Highlight the cp part only.
965-
ii = atom.find(atom.cp)
964+
ii = str(atom).find(atom.cp)
966965
highlight.update(range(ii, ii + len(atom.cp)))
967966
return perform_coloring()
968967

@@ -992,7 +991,7 @@ def perform_coloring():
992991
highlight.update(range(len(op)))
993992

994993
if ver is not None:
995-
start = atom.rfind(ver)
994+
start = str(atom).rfind(ver)
996995
end = start + len(ver)
997996
highlight.update(range(start, end))
998997

@@ -1002,7 +1001,7 @@ def perform_coloring():
10021001
slot_str += "/" + atom.sub_slot
10031002
if atom.slot_operator:
10041003
slot_str += atom.slot_operator
1005-
start = atom.find(slot_str)
1004+
start = str(atom).find(slot_str)
10061005
end = start + len(slot_str)
10071006
highlight.update(range(start, end))
10081007

@@ -1025,7 +1024,7 @@ def perform_coloring():
10251024
)
10261025

10271026
if highlight_use:
1028-
ii = atom.find("[") + 1
1027+
ii = str(atom).find("[") + 1
10291028
for token in atom.use.tokens:
10301029
if token.lstrip("-!").rstrip("=?") in highlight_use:
10311030
highlight.update(range(ii, ii + len(token)))

lib/_emerge/unmerge.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,9 @@ def _pkg(cpv):
122122
print(f"\nNo packages to {unmerge_action} have been provided.\n")
123123
return 1, {}
124124
for x in unmerge_files:
125-
arg_parts = x.split("/")
126-
if x[0] not in [".", "/"] and arg_parts[-1][-7:] != ".ebuild":
125+
x_str = str(x) # this could be an Atom, stringify
126+
arg_parts = x_str.split("/")
127+
if x_str[0] not in [".", "/"] and arg_parts[-1][-7:] != ".ebuild":
127128
# possible cat/pkg or dep; treat as such
128129
candidate_catpkgs.append(x)
129130
elif unmerge_action in ["prune", "clean"]:

lib/portage/_sets/ProfilePackageSet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def load(self):
4040
],
4141
incremental=1,
4242
)
43-
if x[:1] != "*"
43+
if str(x)[:1] != "*"
4444
)
4545

4646
def singleBuilder(self, options, settings, trees):

lib/portage/_sets/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def findAtomForPackage(self, pkg, modified_use=None):
129129
else:
130130
rev_transform[
131131
Atom(
132-
atom.replace(atom.cp, pkg.cp, 1),
132+
str(atom).replace(atom.cp, pkg.cp, 1),
133133
allow_wildcard=True,
134134
allow_repo=True,
135135
)

0 commit comments

Comments
 (0)