aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlec Warner <antarus@gentoo.org>2020-07-29 11:27:16 -0700
committerZac Medico <zmedico@gentoo.org>2020-07-29 21:05:06 -0700
commit709826c0896120e8b3d9995d71678c0b9b290e4c (patch)
treea1864886deaa849c8391dbc4427a2b6ede74a589 /lib/_emerge
parentSilence 'mixed-indentation' warning. (diff)
downloadportage-709826c0896120e8b3d9995d71678c0b9b290e4c.tar.gz
portage-709826c0896120e8b3d9995d71678c0b9b290e4c.tar.bz2
portage-709826c0896120e8b3d9995d71678c0b9b290e4c.zip
Fix R1705.
The codebase appears to have this pattern like: if foo == bar: return a elif foo == baz: return b else: return c This can often be rewritten as: if foo == bar: return a if foo == baz: return b return c Closes: https://github.com/gentoo/portage/pull/592 Signed-off-by: Alec Warner <antarus@gentoo.org> Signed-off-by: Zac Medico <zmedico@gentoo.org>
Diffstat (limited to 'lib/_emerge')
-rw-r--r--lib/_emerge/EbuildBuild.py24
-rw-r--r--lib/_emerge/MergeListItem.py2
-rw-r--r--lib/_emerge/Package.py3
-rw-r--r--lib/_emerge/actions.py11
-rw-r--r--lib/_emerge/depgraph.py131
-rw-r--r--lib/_emerge/main.py4
-rw-r--r--lib/_emerge/resolver/backtracking.py3
-rw-r--r--lib/_emerge/resolver/output.py34
-rw-r--r--lib/_emerge/resolver/slot_collision.py32
-rw-r--r--lib/_emerge/unmerge.py4
10 files changed, 119 insertions, 129 deletions
diff --git a/lib/_emerge/EbuildBuild.py b/lib/_emerge/EbuildBuild.py
index a575835b7..4da815988 100644
--- a/lib/_emerge/EbuildBuild.py
+++ b/lib/_emerge/EbuildBuild.py
@@ -159,18 +159,18 @@ class EbuildBuild(CompositeTask):
settings=self.settings),
self._default_final_exit)
return
- else:
- fetcher = EbuildFetcher(
- config_pool=self.config_pool,
- ebuild_path=self._ebuild_path,
- fetchall=self.opts.fetch_all_uri,
- fetchonly=self.opts.fetchonly,
- background=False,
- logfile=None,
- pkg=self.pkg,
- scheduler=self.scheduler)
- self._start_task(fetcher, self._fetchonly_exit)
- return
+
+ fetcher = EbuildFetcher(
+ config_pool=self.config_pool,
+ ebuild_path=self._ebuild_path,
+ fetchall=self.opts.fetch_all_uri,
+ fetchonly=self.opts.fetchonly,
+ background=False,
+ logfile=None,
+ pkg=self.pkg,
+ scheduler=self.scheduler)
+ self._start_task(fetcher, self._fetchonly_exit)
+ return
self._build_dir = EbuildBuildDir(
scheduler=self.scheduler, settings=settings)
diff --git a/lib/_emerge/MergeListItem.py b/lib/_emerge/MergeListItem.py
index 938f8014a..3b65b16a2 100644
--- a/lib/_emerge/MergeListItem.py
+++ b/lib/_emerge/MergeListItem.py
@@ -85,7 +85,7 @@ class MergeListItem(CompositeTask):
self._start_task(build, self._default_final_exit)
return
- elif pkg.type_name == "binary":
+ if pkg.type_name == "binary":
binpkg = Binpkg(background=self.background,
find_blockers=find_blockers,
diff --git a/lib/_emerge/Package.py b/lib/_emerge/Package.py
index bf75fd97f..00d250125 100644
--- a/lib/_emerge/Package.py
+++ b/lib/_emerge/Package.py
@@ -724,7 +724,8 @@ class Package(Task):
"""
if flag in self.all:
return flag
- elif flag in self.all_aliases:
+
+ if flag in self.all_aliases:
for k, v in self.alias_mapping.items():
if flag in v:
return k
diff --git a/lib/_emerge/actions.py b/lib/_emerge/actions.py
index 2cbca99d8..ab614d641 100644
--- a/lib/_emerge/actions.py
+++ b/lib/_emerge/actions.py
@@ -1072,10 +1072,9 @@ def _calc_depclean(settings, trees, ldpath_mtimes,
"""Sort Package instances by cpv."""
if pkg1.cpv > pkg2.cpv:
return 1
- elif pkg1.cpv == pkg2.cpv:
+ if pkg1.cpv == pkg2.cpv:
return 0
- else:
- return -1
+ return -1
def create_cleanlist():
@@ -2984,7 +2983,7 @@ def run_action(emerge_config):
emerge_config.target_config.trees['vartree'].dbapi) + '\n',
noiselevel=-1)
return 0
- elif emerge_config.action == 'help':
+ if emerge_config.action == 'help':
emerge_help()
return 0
@@ -3018,7 +3017,7 @@ def run_action(emerge_config):
writemsg_stdout("".join("%s\n" % s for s in
sorted(emerge_config.target_config.sets)))
return os.EX_OK
- elif emerge_config.action == "check-news":
+ if emerge_config.action == "check-news":
news_counts = count_unread_news(
emerge_config.target_config.trees["porttree"].dbapi,
emerge_config.target_config.trees["vartree"].dbapi)
@@ -3241,7 +3240,7 @@ def run_action(emerge_config):
if "sync" == emerge_config.action:
return action_sync(emerge_config)
- elif "metadata" == emerge_config.action:
+ if "metadata" == emerge_config.action:
action_metadata(emerge_config.target_config.settings,
emerge_config.target_config.trees['porttree'].dbapi,
emerge_config.opts)
diff --git a/lib/_emerge/depgraph.py b/lib/_emerge/depgraph.py
index 3ff90190d..04b824ab9 100644
--- a/lib/_emerge/depgraph.py
+++ b/lib/_emerge/depgraph.py
@@ -262,7 +262,7 @@ class _rebuild_config:
if self._needs_rebuild(dep_pkg):
self.rebuild_list.add(root_slot)
return True
- elif ("--usepkg" in self._frozen_config.myopts and
+ if ("--usepkg" in self._frozen_config.myopts and
(dep_root_slot in self.reinstall_list or
dep_root_slot in self.rebuild_list or
not dep_pkg.installed)):
@@ -296,7 +296,7 @@ class _rebuild_config:
# built without dep_pkg. Force rebuild.
self.rebuild_list.add(root_slot)
return True
- elif (parent.installed and
+ if (parent.installed and
root_slot not in self.reinstall_list):
try:
bin_build_time, = bindb.aux_get(parent.cpv,
@@ -2566,14 +2566,14 @@ class depgraph:
Atom("=%s" % inst_pkg.cpv)):
if not pkg.built:
return pkg.slot_atom
- elif not pkg.installed:
+ if not pkg.installed:
# avoid using SLOT from a built instance
built_pkgs.append(pkg)
for pkg in self._iter_similar_available(inst_pkg, inst_pkg.slot_atom):
if not pkg.built:
return pkg.slot_atom
- elif not pkg.installed:
+ if not pkg.installed:
# avoid using SLOT from a built instance
built_pkgs.append(pkg)
@@ -2899,58 +2899,58 @@ class depgraph:
self._slot_operator_unsatisfied_probe(dep)):
self._slot_operator_unsatisfied_backtrack(dep)
return 1
- else:
- # This is for backward-compatibility with previous
- # behavior, so that installed packages with unsatisfied
- # dependencies trigger an error message but do not
- # cause the dependency calculation to fail. Only do
- # this if the parent is already in the runtime package
- # mask, since otherwise we need to backtrack.
- if (dep.parent.installed and
- dep.parent in self._dynamic_config._runtime_pkg_mask and
- not any(self._iter_match_pkgs_any(
- dep.parent.root_config, dep.atom))):
- self._dynamic_config._initially_unsatisfied_deps.append(dep)
- return 1
-
- # Do not backtrack if only USE have to be changed in
- # order to satisfy the dependency. Note that when
- # want_restart_for_use_change sets the need_restart
- # flag, it causes _select_pkg_highest_available to
- # return None, and eventually we come through here
- # and skip the "missing dependency" backtracking path.
- dep_pkg, existing_node = \
- self._select_package(dep.root,
- dep.atom.without_use if dep.atom.package
- else dep.atom, onlydeps=dep.onlydeps)
- if dep_pkg is None:
-
- # In order to suppress the sort of aggressive
- # backtracking that can trigger undesirable downgrades
- # as in bug 693836, do not backtrack if there's an
- # available package which was involved in a slot
- # conflict and satisfied all involved parent atoms.
- for dep_pkg, reasons in self._dynamic_config._runtime_pkg_mask.items():
- if (dep.atom.match(dep_pkg) and
- len(reasons) == 1 and
- not reasons.get("slot conflict", True)):
- self._dynamic_config._skip_restart = True
- return 0
- self._dynamic_config._backtrack_infos["missing dependency"] = dep
- self._dynamic_config._need_restart = True
- if debug:
- msg = []
- msg.append("")
- msg.append("")
- msg.append("backtracking due to unsatisfied dep:")
- msg.append(" parent: %s" % dep.parent)
- msg.append(" priority: %s" % dep.priority)
- msg.append(" root: %s" % dep.root)
- msg.append(" atom: %s" % dep.atom)
- msg.append("")
- writemsg_level("".join("%s\n" % l for l in msg),
- noiselevel=-1, level=logging.DEBUG)
+ # This is for backward-compatibility with previous
+ # behavior, so that installed packages with unsatisfied
+ # dependencies trigger an error message but do not
+ # cause the dependency calculation to fail. Only do
+ # this if the parent is already in the runtime package
+ # mask, since otherwise we need to backtrack.
+ if (dep.parent.installed and
+ dep.parent in self._dynamic_config._runtime_pkg_mask and
+ not any(self._iter_match_pkgs_any(
+ dep.parent.root_config, dep.atom))):
+ self._dynamic_config._initially_unsatisfied_deps.append(dep)
+ return 1
+
+ # Do not backtrack if only USE have to be changed in
+ # order to satisfy the dependency. Note that when
+ # want_restart_for_use_change sets the need_restart
+ # flag, it causes _select_pkg_highest_available to
+ # return None, and eventually we come through here
+ # and skip the "missing dependency" backtracking path.
+ dep_pkg, existing_node = \
+ self._select_package(dep.root,
+ dep.atom.without_use if dep.atom.package
+ else dep.atom, onlydeps=dep.onlydeps)
+ if dep_pkg is None:
+
+ # In order to suppress the sort of aggressive
+ # backtracking that can trigger undesirable downgrades
+ # as in bug 693836, do not backtrack if there's an
+ # available package which was involved in a slot
+ # conflict and satisfied all involved parent atoms.
+ for dep_pkg, reasons in self._dynamic_config._runtime_pkg_mask.items():
+ if (dep.atom.match(dep_pkg) and
+ len(reasons) == 1 and
+ not reasons.get("slot conflict", True)):
+ self._dynamic_config._skip_restart = True
+ return 0
+
+ self._dynamic_config._backtrack_infos["missing dependency"] = dep
+ self._dynamic_config._need_restart = True
+ if debug:
+ msg = []
+ msg.append("")
+ msg.append("")
+ msg.append("backtracking due to unsatisfied dep:")
+ msg.append(" parent: %s" % dep.parent)
+ msg.append(" priority: %s" % dep.priority)
+ msg.append(" root: %s" % dep.root)
+ msg.append(" atom: %s" % dep.atom)
+ msg.append("")
+ writemsg_level("".join("%s\n" % l for l in msg),
+ noiselevel=-1, level=logging.DEBUG)
return 0
@@ -3190,7 +3190,7 @@ class depgraph:
dep_stack = self._dynamic_config._dep_stack
if "recurse" not in self._dynamic_config.myparams:
return 1
- elif pkg.installed and not recurse:
+ if pkg.installed and not recurse:
dep_stack = self._dynamic_config._ignored_deps
self._spinner_update()
@@ -5656,9 +5656,8 @@ class depgraph:
if atom.package:
return self._iter_match_pkgs_atom(root_config, pkg_type,
atom, onlydeps=onlydeps)
- else:
- return self._iter_match_pkgs_soname(root_config, pkg_type,
- atom, onlydeps=onlydeps)
+ return self._iter_match_pkgs_soname(root_config, pkg_type,
+ atom, onlydeps=onlydeps)
def _iter_match_pkgs_soname(self, root_config, pkg_type, atom,
onlydeps=False):
@@ -5873,12 +5872,11 @@ class depgraph:
deep = self._dynamic_config.myparams.get("deep", 0)
if depth is self._UNREACHABLE_DEPTH:
return True
- elif deep is True:
+ if deep is True:
return False
- else:
- # All non-integer cases are handled above,
- # so both values must be int type.
- return depth > deep
+ # All non-integer cases are handled above,
+ # so both values must be int type.
+ return depth > deep
def _depth_increment(self, depth, n=1):
"""
@@ -6161,8 +6159,7 @@ class depgraph:
if target_use is None:
if needed_use_config_change is None:
return pkg.use.enabled
- else:
- return needed_use_config_change[0]
+ return needed_use_config_change[0]
if needed_use_config_change is not None:
old_use = needed_use_config_change[0]
@@ -9747,7 +9744,7 @@ class _dep_check_composite_db(dbapi):
if not avoid_update:
if not use_ebuild_visibility and usepkgonly:
return False
- elif not self._depgraph._equiv_ebuild_visible(pkg):
+ if not self._depgraph._equiv_ebuild_visible(pkg):
return False
if pkg.cp.startswith("virtual/"):
diff --git a/lib/_emerge/main.py b/lib/_emerge/main.py
index 8228e0b41..12323b17e 100644
--- a/lib/_emerge/main.py
+++ b/lib/_emerge/main.py
@@ -1239,10 +1239,10 @@ def emerge_main(args=None):
if myaction == "help":
emerge_help()
return os.EX_OK
- elif myaction == "moo":
+ if myaction == "moo":
print(COWSAY_MOO % platform.system())
return os.EX_OK
- elif myaction == "sync":
+ if myaction == "sync":
# need to set this to True now in order for the repository config
# loading to allow new repos with non-existent directories
portage._sync_mode = True
diff --git a/lib/_emerge/resolver/backtracking.py b/lib/_emerge/resolver/backtracking.py
index 370b6b851..bc3fb3206 100644
--- a/lib/_emerge/resolver/backtracking.py
+++ b/lib/_emerge/resolver/backtracking.py
@@ -119,8 +119,7 @@ class Backtracker:
node = self._unexplored_nodes.pop()
self._current_node = node
return copy.deepcopy(node.parameter)
- else:
- return None
+ return None
def __len__(self):
diff --git a/lib/_emerge/resolver/output.py b/lib/_emerge/resolver/output.py
index b4faafd75..9483898de 100644
--- a/lib/_emerge/resolver/output.py
+++ b/lib/_emerge/resolver/output.py
@@ -260,26 +260,24 @@ class Display:
if pkg_info.built:
if pkg_info.system:
return colorize("PKG_BINARY_MERGE_SYSTEM", pkg_str)
- elif pkg_info.world:
+ if pkg_info.world:
return colorize("PKG_BINARY_MERGE_WORLD", pkg_str)
- else:
- return colorize("PKG_BINARY_MERGE", pkg_str)
- else:
- if pkg_info.system:
- return colorize("PKG_MERGE_SYSTEM", pkg_str)
- elif pkg_info.world:
- return colorize("PKG_MERGE_WORLD", pkg_str)
- else:
- return colorize("PKG_MERGE", pkg_str)
- elif pkg_info.operation == "uninstall":
- return colorize("PKG_UNINSTALL", pkg_str)
- else:
+ return colorize("PKG_BINARY_MERGE", pkg_str)
+
if pkg_info.system:
- return colorize("PKG_NOMERGE_SYSTEM", pkg_str)
- elif pkg_info.world:
- return colorize("PKG_NOMERGE_WORLD", pkg_str)
- else:
- return colorize("PKG_NOMERGE", pkg_str)
+ return colorize("PKG_MERGE_SYSTEM", pkg_str)
+ if pkg_info.world:
+ return colorize("PKG_MERGE_WORLD", pkg_str)
+ return colorize("PKG_MERGE", pkg_str)
+
+ if pkg_info.operation == "uninstall":
+ return colorize("PKG_UNINSTALL", pkg_str)
+
+ if pkg_info.system:
+ return colorize("PKG_NOMERGE_SYSTEM", pkg_str)
+ if pkg_info.world:
+ return colorize("PKG_NOMERGE_WORLD", pkg_str)
+ return colorize("PKG_NOMERGE", pkg_str)
def verbose_size(self, pkg, repoadd_set, pkg_info):
diff --git a/lib/_emerge/resolver/slot_collision.py b/lib/_emerge/resolver/slot_collision.py
index 05f4256ad..cc16287de 100644
--- a/lib/_emerge/resolver/slot_collision.py
+++ b/lib/_emerge/resolver/slot_collision.py
@@ -1065,8 +1065,7 @@ class slot_conflict_handler:
if is_valid_solution and required_changes:
return required_changes
- else:
- return None
+ return None
class _configuration_generator:
def __init__(self, conflict_pkgs):
@@ -1109,13 +1108,12 @@ class _configuration_generator:
if solution_ids[id] == len(conflict_pkgs[id])-1:
if id > 0:
return self._next(id=id-1)
- else:
- return False
- else:
- solution_ids[id] += 1
- for other_id in range(id+1, len(solution_ids)):
- solution_ids[other_id] = 0
- return True
+ return False
+
+ solution_ids[id] += 1
+ for other_id in range(id+1, len(solution_ids)):
+ solution_ids[other_id] = 0
+ return True
class _solution_candidate_generator:
class _value_helper:
@@ -1124,8 +1122,7 @@ class _solution_candidate_generator:
def __eq__(self, other):
if isinstance(other, str):
return self.value == other
- else:
- return self.value == other.value
+ return self.value == other.value
def __str__(self):
return "%s" % (self.value,)
@@ -1172,12 +1169,11 @@ class _solution_candidate_generator:
if values[id].value == "enabled":
if id > 0:
return self._next(id=id-1)
- else:
- return False
- else:
- values[id].value = "enabled"
- for other_id in range(id+1, len(values)):
- values[other_id].value = "disabled"
- return True
+ return False
+
+ values[id].value = "enabled"
+ for other_id in range(id+1, len(values)):
+ values[other_id].value = "disabled"
+ return True
diff --git a/lib/_emerge/unmerge.py b/lib/_emerge/unmerge.py
index 9c012e431..8de35a6ef 100644
--- a/lib/_emerge/unmerge.py
+++ b/lib/_emerge/unmerge.py
@@ -98,8 +98,8 @@ def _unmerge_display(root_config, myopts, unmerge_action,
" can only be used with specific package names")
print()
return 1, {}
- else:
- global_unmerge = 1
+
+ global_unmerge = 1
localtree = vartree
# process all arguments and add all