changeset 207:b3b5ed34d180

Handle most flake8 errors and warnings. NOTE: E265 "block comment should start with '# ' ist not yet handled. We would need to adjust our Python style.
author Franz Glasner <fzglas.hg@dom66.de>
date Sun, 05 May 2019 18:29:47 +0200
parents 5064e3a2e54a
children bbe8513ea649
files configmix/__init__.py configmix/compat.py configmix/config.py configmix/ini.py configmix/json.py configmix/py.py configmix/toml.py configmix/variables.py configmix/yaml.py setup.cfg
diffstat 10 files changed, 41 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/configmix/__init__.py	Sun May 05 16:53:13 2019 +0200
+++ b/configmix/__init__.py	Sun May 05 18:29:47 2019 +0200
@@ -34,8 +34,9 @@
 from .config import Configuration
 
 
-COMMENTS = [u("__comment"),
-            u("__doc"),
+COMMENTS = [
+    u("__comment"),
+    u("__doc"),
 ]
 """Prefixes for comment configuration keys that are to be handled as
 comments
@@ -312,12 +313,12 @@
 
         if not isinstance(b, dict):
             return b
-        result = deepcopy(a)
+        result = deepcopy(a)                     # noqa
         for k, v in b.iteritems():
             if k in result and isinstance(result[k], dict):
                 result[k] = dict_merge(result[k], v)
             else:
-                result[k] = deepcopy(v)
+                result[k] = deepcopy(v)          # noqa
         return result
 
 
--- a/configmix/compat.py	Sun May 05 16:53:13 2019 +0200
+++ b/configmix/compat.py	Sun May 05 18:29:47 2019 +0200
@@ -9,11 +9,6 @@
 
 from __future__ import division, absolute_import, print_function
 
-import sys
-import os
-import locale
-
-
 __all__ = ["PY2",
            "text_to_native_os_str",
            "native_os_str_to_text",
@@ -21,6 +16,11 @@
            "u2fs"]
 
 
+import sys
+import os
+import locale
+
+
 PY2 = sys.version_info[0] <= 2
 
 
@@ -32,7 +32,7 @@
 
 
     def text_to_native_os_str(s, encoding=None):
-        if isinstance(s, unicode):
+        if isinstance(s, unicode):                       # noqa: F821
             return s.encode(encoding or _OS_ENCODING)
         else:
             return s
@@ -43,7 +43,7 @@
 
 
     def u(s, encoding="utf-8"):
-        if isinstance(s, unicode):
+        if isinstance(s, unicode):                       # noqa: F821
             return s
         else:
             return s.decode(encoding)
--- a/configmix/config.py	Sun May 05 16:53:13 2019 +0200
+++ b/configmix/config.py	Sun May 05 18:29:47 2019 +0200
@@ -114,7 +114,7 @@
         s = self.getvar_s(varname, default)
         if isinstance(s, self._TEXTTYPE):
             sl = s.strip().lower()
-            if not sl in self._BOOL_CVT:
+            if sl not in self._BOOL_CVT:
                 raise ValueError("Not a boolean: %r" % s)
             return self._BOOL_CVT[sl]
         else:
@@ -161,7 +161,9 @@
             for p in parts[1:]:
                 v = v[p]
         except TypeError:
-            raise KeyError("Configuration variable %r not found (missing intermediate keys?)" % key)
+            raise KeyError(
+                "Configuration variable %r not found"
+                "(missing intermediate keys?)" % key)
         except KeyError:
             if default is _MARKER:
                 raise KeyError("Configuration variable %r not found" % key)
--- a/configmix/ini.py	Sun May 05 16:53:13 2019 +0200
+++ b/configmix/ini.py	Sun May 05 18:29:47 2019 +0200
@@ -32,7 +32,7 @@
     except ImportError:
         DictImpl = dict
 
-from .compat import PY2, u, u2fs
+from .compat import u, u2fs
 
 
 __all__ = ["INIConfigParser", "NoSectionError", "NoOptionError",
@@ -182,7 +182,7 @@
                 value = ini.getx(sect, option)
                 conf[option] = value
     # try to read "<extract>.xxx" sections as tree
-    for treemarker in [ e + '.' for e in extract ]:
+    for treemarker in [e + '.' for e in extract]:
         sections = list(ini.sections())
         sections.sort()
         for section in sections:
--- a/configmix/json.py	Sun May 05 16:53:13 2019 +0200
+++ b/configmix/json.py	Sun May 05 18:29:47 2019 +0200
@@ -19,7 +19,7 @@
     except ImportError:
         DictImpl = dict
 
-from .compat import u2fs        
+from .compat import u2fs
 
 
 __all__ = ["load"]
--- a/configmix/py.py	Sun May 05 16:53:13 2019 +0200
+++ b/configmix/py.py	Sun May 05 18:29:47 2019 +0200
@@ -9,7 +9,6 @@
 
 from __future__ import division, absolute_import, print_function
 
-import locale
 try:
     from collections import OrderedDict as DictImpl
 except ImportError:
@@ -43,7 +42,7 @@
     gcontext = DictImpl()
     lcontext = DictImpl()
     if PY2:
-        execfile(u2fs(filename, True), gcontext, lcontext)
+        execfile(u2fs(filename, True), gcontext, lcontext)      # noqa: F821
     else:
         # "rb" mode allows Python to derive the encoding automatically
         with open(filename, "rb") as vf:
--- a/configmix/toml.py	Sun May 05 16:53:13 2019 +0200
+++ b/configmix/toml.py	Sun May 05 18:29:47 2019 +0200
@@ -30,7 +30,7 @@
 def load(filename, encoding="utf-8"):
     """Load a single TOML file with name `filename` and encoding `encoding`.
 
-    .. note:: The TOML standard requires that all TOML files are UTF-8 
+    .. note:: The TOML standard requires that all TOML files are UTF-8
               encoded.
 
     """
--- a/configmix/variables.py	Sun May 05 16:53:13 2019 +0200
+++ b/configmix/variables.py	Sun May 05 18:29:47 2019 +0200
@@ -12,7 +12,7 @@
 import os
 from functools import wraps
 
-from .compat import PY2, text_to_native_os_str, native_os_str_to_text, u
+from .compat import PY2, native_os_str_to_text, u
 
 
 __all__ = []
@@ -45,7 +45,7 @@
     if name == "version":
         return u(platform.python_version())
     elif name == "implementation":
-        return  u(platform.python_implementation())
+        return u(platform.python_implementation())
     elif name == "version_maj_min":
         t = platform.python_version_tuple()
         return u('.'.join(t[:2]))
--- a/configmix/yaml.py	Sun May 05 16:53:13 2019 +0200
+++ b/configmix/yaml.py	Sun May 05 18:29:47 2019 +0200
@@ -61,7 +61,9 @@
             if isinstance(node, yaml.MappingNode):
                 self.flatten_mapping(node)
             else:
-                raise yaml.constructor.ConstructorError(None, None,
+                raise yaml.constructor.ConstructorError(
+                    None,
+                    None,
                     'expected a mapping node, but found %s' % node.id,
                     node.start_mark)
 
@@ -73,7 +75,9 @@
                 except TypeError as err:
                     raise yaml.constructor.ConstructorError(
                         'while constructing a mapping', node.start_mark,
-                        'found unacceptable key (%s)' % err, key_node.start_mark)
+                        'found unacceptable key (%s)' % (err,
+                                                         key_node.start_mark)
+                    )
                 value = self.construct_object(value_node, deep=deep)
                 mapping[key] = value
             return mapping
@@ -123,7 +127,9 @@
             if isinstance(node, yaml.MappingNode):
                 self.flatten_mapping(node)
             else:
-                raise yaml.constructor.ConstructorError(None, None,
+                raise yaml.constructor.ConstructorError(
+                    None,
+                    None,
                     'expected a mapping node, but found %s' % node.id,
                     node.start_mark)
 
@@ -135,7 +141,9 @@
                 except TypeError as err:
                     raise yaml.constructor.ConstructorError(
                         'while constructing a mapping', node.start_mark,
-                        'found unacceptable key (%s)' % err, key_node.start_mark)
+                        'found unacceptable key (%s)' % (err,
+                                                         key_node.start_mark)
+                    )
                 value = self.construct_object(value_node, deep=deep)
                 mapping[key] = value
             return mapping
--- a/setup.cfg	Sun May 05 16:53:13 2019 +0200
+++ b/setup.cfg	Sun May 05 18:29:47 2019 +0200
@@ -2,7 +2,7 @@
 license_file = LICENSE.txt
 
 [egg_info]
-tag_build = 
+tag_build =
 tag_date = 0
 tag_svn_revision = 0
 
@@ -11,3 +11,8 @@
 
 [sdist]
 formats = gztar
+
+[flake8]
+per-file-ignores =
+    # Ignore "too many blank lines"
+    configmix/compat.py:E303