From bb96e13ef74bfb60c6a0239c6a8b912555bfd413 Mon Sep 17 00:00:00 2001
From: Andreas Kloeckner <inform@tiker.net>
Date: Tue, 8 Sep 2020 23:30:49 -0500
Subject: [PATCH] Revert aksetup_helper.py to pre-pyupgrade version

---
 aksetup_helper.py | 35 ++++++++++++++++++-----------------
 configure.py      |  1 +
 2 files changed, 19 insertions(+), 17 deletions(-)

diff --git a/aksetup_helper.py b/aksetup_helper.py
index 584f4bf9..a168adf7 100644
--- a/aksetup_helper.py
+++ b/aksetup_helper.py
@@ -104,7 +104,8 @@ def flatten(lst):
     Example: Turn [[a,b,c],[d,e,f]] into [a,b,c,d,e,f].
     """
     for sublist in lst:
-        yield from sublist
+        for j in sublist:
+            yield j
 
 
 def humanize(sym_str):
@@ -243,13 +244,13 @@ def expand_value(v, options):
 
 
 def expand_options(options):
-    return {
-            k: expand_value(v, options) for k, v in options.items()}
+    return dict(
+            (k, expand_value(v, options)) for k, v in options.items())
 
 
 class ConfigSchema:
     def __init__(self, options, conf_file="siteconf.py", conf_dir="."):
-        self.optdict = {opt.name: opt for opt in options}
+        self.optdict = dict((opt.name, opt) for opt in options)
         self.options = options
         self.conf_dir = conf_dir
         self.conf_file = conf_file
@@ -270,12 +271,12 @@ class ConfigSchema:
         self.conf_dir = conf_dir
 
     def get_default_config(self):
-        return {opt.name: opt.default for opt in self.options}
+        return dict((opt.name, opt.default) for opt in self.options)
 
     def read_config_from_pyfile(self, filename):
         result = {}
         filevars = {}
-        infile = open(filename)
+        infile = open(filename, "r")
         try:
             contents = infile.read()
         finally:
@@ -294,8 +295,8 @@ class ConfigSchema:
         filevars = {}
 
         try:
-            exec(compile(open(filename).read(), filename, "exec"), filevars)
-        except OSError:
+            exec(compile(open(filename, "r").read(), filename, "exec"), filevars)
+        except IOError:
             pass
 
         if "__builtins__" in filevars:
@@ -310,7 +311,7 @@ class ConfigSchema:
 
         outf = open(filename, "w")
         for key in keys:
-            outf.write("{} = {}\n".format(key, repr(filevars[key])))
+            outf.write("%s = %s\n" % (key, repr(filevars[key])))
         outf.close()
 
         return result
@@ -361,7 +362,7 @@ class ConfigSchema:
             elif key == "__builtins__":
                 pass
             else:
-                raise KeyError("invalid config key in {}: {}".format(
+                raise KeyError("invalid config key in %s: %s" % (
                         filename, key))
 
     def update_config_from_and_modify_command_line(self, config, argv):
@@ -386,7 +387,7 @@ class ConfigSchema:
 
         result = self.get_default_config_with_files()
         if os.access(cfile, os.R_OK):
-            with open(cfile) as inf:
+            with open(cfile, "r") as inf:
                 py_snippet = inf.read()
             self.update_from_python_snippet(result, py_snippet, cfile)
 
@@ -411,15 +412,15 @@ class ConfigSchema:
         for opt in self.options:
             value = config[opt.name]
             if value is not None:
-                outf.write("{} = {}\n".format(opt.name, repr(config[opt.name])))
+                outf.write("%s = %s\n" % (opt.name, repr(config[opt.name])))
         outf.close()
 
     def make_substitutions(self, config):
-        return {opt.name: opt.value_to_str(config[opt.name])
-                for opt in self.options}
+        return dict((opt.name, opt.value_to_str(config[opt.name]))
+                for opt in self.options)
 
 
-class Option:
+class Option(object):
     def __init__(self, name, default=None, help=None):
         self.name = name
         self.default = default
@@ -715,7 +716,7 @@ def substitute(substitutions, fname):
     string_var_re = re.compile(r"\$str\{([A-Za-z_0-9]+)\}")
 
     fname_in = fname+".in"
-    lines = open(fname_in).readlines()
+    lines = open(fname_in, "r").readlines()
     new_lines = []
     for line in lines:
         made_change = True
@@ -887,7 +888,7 @@ def check_pybind11():
 
 # {{{ (modified) boilerplate from https://github.com/pybind/python_example/blob/2ed5a68759cd6ff5d2e5992a91f08616ef457b5c/setup.py  # noqa
 
-class get_pybind_include:  # noqa: N801
+class get_pybind_include(object):  # noqa: N801
     """Helper class to determine the pybind11 include path
 
     The purpose of this class is to postpone importing pybind11
diff --git a/configure.py b/configure.py
index c5512822..63edd4b9 100755
--- a/configure.py
+++ b/configure.py
@@ -1,5 +1,6 @@
 #! /usr/bin/env python
 
+from __future__ import absolute_import
 
 from aksetup_helper import configure_frontend
 configure_frontend()
-- 
GitLab