The first patch makes our use of the reduce function Python 3 compatible (yes, we DO use reduce!) and the second patch makes the next() generator calls Python compatible.
I've done some simple Python 3 compatibility scanning by running the Anaconda source through python3 -m compileall and 2to3 (lives in python-tools BTW).
From the output it looks like that most of the stuff that can be easily
changed to work in both 2 & 3 without special compatibility machinery has been already done.
The remaining changes are what I would call "flag day changes" as they either can degrade performance in Python 2 (using items() in place of iteritems(), etc.) or are outright Python 2 incompatible without additional Python 3 compatibility machinery (mostly standard library module renames and reorganizations).
As I don't think maintaining compatibility with Python 2 is needed once Anaconda works with Python 3 (unlike for Pykickstart & Blivet),so the remaining changes should be done once the Python 3 "flag day" comes without regard for Python 2 compatibility.
Martin Kolman (2): Make reduce function usage Python 3 compatible Use the built-in next() function for generators
pyanaconda/addons.py | 5 +++-- pyanaconda/anaconda_argparse.py | 2 +- pyanaconda/bootloader.py | 2 +- pyanaconda/ui/gui/hubs/progress.py | 2 +- pyanaconda/ui/tui/simpleline/base.py | 3 ++- scripts/anaconda-yum | 4 ++-- 6 files changed, 10 insertions(+), 8 deletions(-)
The built-in reduce function has been removed in Python 3, but in both Python 2.7 and Python 3+ the reduce function is available from the functools module.
Signed-off-by: Martin Kolman mkolman@redhat.com --- pyanaconda/addons.py | 5 +++-- pyanaconda/ui/tui/simpleline/base.py | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/pyanaconda/addons.py b/pyanaconda/addons.py index da80958..c95f41a 100644 --- a/pyanaconda/addons.py +++ b/pyanaconda/addons.py @@ -22,6 +22,7 @@ __all__ = ["AddonSection", "AddonRegistry", "AddonData", "collect_addon_paths"]
import os +import functools from pykickstart.sections import Section from pykickstart.errors import KickstartParseError, formatErrorMsg from pyanaconda.i18n import _ @@ -75,8 +76,8 @@ class AddonRegistry(object): self.__dict__ = dictionary
def __str__(self): - return reduce(lambda acc,(id, addon): acc + str(addon), - self.__dict__.iteritems(), "") + return functools.reduce(lambda acc, (id, addon): acc + str(addon), + self.__dict__.iteritems(), "")
def execute(self, storage, ksdata, instClass, users): """This method calls execute on all the registered addons.""" diff --git a/pyanaconda/ui/tui/simpleline/base.py b/pyanaconda/ui/tui/simpleline/base.py index 0ae0f57..fefbf80 100644 --- a/pyanaconda/ui/tui/simpleline/base.py +++ b/pyanaconda/ui/tui/simpleline/base.py @@ -25,6 +25,7 @@ import sys import Queue import getpass import threading +import functools from pyanaconda.threads import threadMgr, AnacondaThread from pyanaconda.ui.communication import hubQ from pyanaconda import constants @@ -653,7 +654,7 @@ class Widget(object): def width(self): """The current width of the internal buffer (id of the first empty column).""" - return reduce(lambda acc,l: max(acc, len(l)), self._buffer, 0) + return functools.reduce(lambda acc, l: max(acc, len(l)), self._buffer, 0)
def clear(self): """Clears this widgets buffer and resets cursor."""
The next() function of the generator object has been removed in Python 3 but the equivalent built-in next() function is available in both Python 2 and 3.
Signed-off-by: Martin Kolman mkolman@redhat.com --- pyanaconda/anaconda_argparse.py | 2 +- pyanaconda/bootloader.py | 2 +- pyanaconda/ui/gui/hubs/progress.py | 2 +- scripts/anaconda-yum | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/pyanaconda/anaconda_argparse.py b/pyanaconda/anaconda_argparse.py index d9a58ee..b8242e0 100644 --- a/pyanaconda/anaconda_argparse.py +++ b/pyanaconda/anaconda_argparse.py @@ -281,7 +281,7 @@ def name_path_pairs(image_specs):
if name in names_seen: names = ("%s_%d" % (name, n) for n in itertools.count()) - name = itertools.dropwhile(lambda n: n in names_seen, names).next() + name = next(itertools.dropwhile(lambda n: n in names_seen, names)) names_seen.append(name)
yield name, path diff --git a/pyanaconda/bootloader.py b/pyanaconda/bootloader.py index c0e34da..493b935 100644 --- a/pyanaconda/bootloader.py +++ b/pyanaconda/bootloader.py @@ -2322,7 +2322,7 @@ def writeSysconfigKernel(storage, version, instClass): ts = rpm.TransactionSet(iutil.getSysroot()) mi = ts.dbMatch('basenames', kernel_file) try: - h = mi.next() + h = next(mi) except StopIteration: log.error("failed to get package name for default kernel") return diff --git a/pyanaconda/ui/gui/hubs/progress.py b/pyanaconda/ui/gui/hubs/progress.py index 0dd0ef8..1c33abd 100644 --- a/pyanaconda/ui/gui/hubs/progress.py +++ b/pyanaconda/ui/gui/hubs/progress.py @@ -191,7 +191,7 @@ class ProgressHub(Hub): # image's filename. Note that self._rnotesPages is an infinite list, # so this will cycle through the images indefinitely. try: - nxt = self._rnotesPages.next() + nxt = next(self._rnotesPages) except StopIteration: # there are no rnotes pass diff --git a/scripts/anaconda-yum b/scripts/anaconda-yum index e041b90..77067c7 100755 --- a/scripts/anaconda-yum +++ b/scripts/anaconda-yum @@ -132,7 +132,7 @@ def run_yum_transaction(release, arch, yum_conf, install_root, ts_file, script_l # retry count > 0 -> retry if retry_count: # retry after waiting a bit - time.sleep(xdelay.next()) + time.sleep(next(xdelay)) print("PROGRESS_INSTALL: error populating transaction, retrying (%d/%d)" % (retry_count, MAX_DOWNLOAD_RETRIES)) try: @@ -296,7 +296,7 @@ class RPMCallback(object): # retry count == 0 -> first attempt # retry count > 0 -> retry if retry_count and retry_message: - time.sleep(xdelay.next()) # wait a bit before retry + time.sleep(next(xdelay)) # wait a bit before retry print("PROGRESS_INSTALL: %s (%d/%d)" % (retry_message, retry_count, MAX_DOWNLOAD_RETRIES))
try:
On 06/27/2014 09:17 AM, Martin Kolman wrote:
The first patch makes our use of the reduce function Python 3 compatible (yes, we DO use reduce!) and the second patch makes the next() generator calls Python compatible.
I've done some simple Python 3 compatibility scanning by running the Anaconda source through python3 -m compileall and 2to3 (lives in python-tools BTW). From the output it looks like that most of the stuff that can be easily changed to work in both 2 & 3 without special compatibility machinery has been already done.
The remaining changes are what I would call "flag day changes" as they either can degrade performance in Python 2 (using items() in place of iteritems(), etc.) or are outright Python 2 incompatible without additional Python 3 compatibility machinery (mostly standard library module renames and reorganizations).
As I don't think maintaining compatibility with Python 2 is needed once Anaconda works with Python 3 (unlike for Pykickstart & Blivet),so the remaining changes should be done once the Python 3 "flag day" comes without regard for Python 2 compatibility.
Martin Kolman (2): Make reduce function usage Python 3 compatible Use the built-in next() function for generators
pyanaconda/addons.py | 5 +++-- pyanaconda/anaconda_argparse.py | 2 +- pyanaconda/bootloader.py | 2 +- pyanaconda/ui/gui/hubs/progress.py | 2 +- pyanaconda/ui/tui/simpleline/base.py | 3 ++- scripts/anaconda-yum | 4 ++-- 6 files changed, 10 insertions(+), 8 deletions(-)
These both look good.
anaconda-patches@lists.fedorahosted.org