[pitivi/sdk: 1/7] Check code style with flake8



commit 4c6b69110a06204a39e316b3224e0bdcaa080b0e
Author: Alexandru Băluț <alexandru balut gmail com>
Date:   Fri Jan 17 17:58:52 2020 +0100

    Check code style with flake8
    
    flake8 runs super fast. As it's a wrapper for pycodestyle (former pep8
    tool), we use it to check for things pylint will never check, like the
    number of empty lines between the methods.
    
    We should never have to add #noqa lines to the code. Either we fix the
    warning/error, or we add it to flake8's ignore list.

 .pre-commit-config.yaml       | 8 ++++++++
 pitivi/application.py         | 3 +--
 pitivi/configure.py.in        | 4 ++++
 pitivi/greeterperspective.py  | 3 +--
 pitivi/timeline/elements.py   | 6 +++---
 pitivi/utils/loggable.py      | 8 ++++----
 tests/validate-tests/runtests | 1 +
 7 files changed, 22 insertions(+), 11 deletions(-)
---
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 88da45ed..f9148d48 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -25,6 +25,14 @@ repos:
         args:
         # http://www.pydocstyle.org/en/latest/error_codes.html
         -   --ignore=D1,D203,D213,D401,D406,D407,D413
+-   repo: https://gitlab.com/PyCQA/flake8
+    rev: 3.7.9
+    hooks:
+    -   id: flake8
+        args:
+        # http://flake8.pycqa.org/en/latest/user/error-codes.html
+        # https://pycodestyle.readthedocs.io/en/latest/intro.html#error-codes
+        -   --ignore=E402,E501,E722,F401,F841,W504
 -   repo: local
     hooks:
     -   id: pylint
diff --git a/pitivi/application.py b/pitivi/application.py
index e40e36ca..c6d85097 100644
--- a/pitivi/application.py
+++ b/pitivi/application.py
@@ -69,8 +69,7 @@ class Pitivi(Gtk.Application, Loggable):
     def __init__(self):
         Gtk.Application.__init__(self,
                                  application_id="org.pitivi.Pitivi",
-                                 flags=Gio.ApplicationFlags.NON_UNIQUE |
-                                 Gio.ApplicationFlags.HANDLES_OPEN)
+                                 flags=Gio.ApplicationFlags.NON_UNIQUE | Gio.ApplicationFlags.HANDLES_OPEN)
         Loggable.__init__(self)
 
         self.settings = None
diff --git a/pitivi/configure.py.in b/pitivi/configure.py.in
index 8c1da3b3..7d96a93d 100644
--- a/pitivi/configure.py.in
+++ b/pitivi/configure.py.in
@@ -32,6 +32,7 @@ def in_devel():
     """Returns whether the app is run from a git checkout."""
     return os.environ.get("PITIVI_DEVELOPMENT", "0") != "0"
 
+
 LIBDIR = '@LIBDIR@'
 PKGDATADIR = '@DATADIR@/@PACKAGE@'
 GITVERSION = '@GITVERSION@'
@@ -79,14 +80,17 @@ def get_videopresets_dir():
     """Returns our directory with Video Presets files."""
     return os.path.join(get_data_dir(), 'videopresets')
 
+
 def get_gstpresets_dir():
     """Returns our directory with Gst Presets files."""
     return os.path.join(get_data_dir(), 'gstpresets')
 
+
 def get_plugins_dir():
     """Returns our default directory to store official plugins."""
     return os.path.join(_get_root_dir(), 'plugins')
 
+
 def get_user_plugins_dir():
     """Returns our default directory to store non-official plugins."""
     user_data_dir = GLib.get_user_data_dir()
diff --git a/pitivi/greeterperspective.py b/pitivi/greeterperspective.py
index 75455733..2182446d 100644
--- a/pitivi/greeterperspective.py
+++ b/pitivi/greeterperspective.py
@@ -170,8 +170,7 @@ class GreeterPerspective(Perspective):
             self.__recent_projects_listbox.remove(child)
 
         recent_items = [item for item in self.app.recent_manager.get_items()
-                        if item.get_display_name().endswith(self.__project_filter)
-                        and item.exists()]
+                        if item.get_display_name().endswith(self.__project_filter) and item.exists()]
 
         # If there are recent projects, display them, else display welcome screen.
         if recent_items:
diff --git a/pitivi/timeline/elements.py b/pitivi/timeline/elements.py
index 293791a6..41a379ec 100644
--- a/pitivi/timeline/elements.py
+++ b/pitivi/timeline/elements.py
@@ -710,9 +710,8 @@ class TimelineElement(Gtk.Layout, Zoomable, Loggable):
 
         if len(values) < 2:
             source.unset_all()
-            val = float(self.__controlled_property.default_value) / \
-                  (self.__controlled_property.maximum -
-                   self.__controlled_property.minimum)
+            values_range = self.__controlled_property.maximum - self.__controlled_property.minimum
+            val = float(self.__controlled_property.default_value) / values_range
             inpoint = self._ges_elem.props.in_point
             res = source.set(inpoint, val)
             assert res
@@ -995,6 +994,7 @@ class VideoUriSource(VideoSource):
                 return spec
         return None
 
+
 class AudioBackground(Gtk.Box):
 
     def __init__(self):
diff --git a/pitivi/utils/loggable.py b/pitivi/utils/loggable.py
index 95b4670a..9ae91f41 100644
--- a/pitivi/utils/loggable.py
+++ b/pitivi/utils/loggable.py
@@ -426,10 +426,10 @@ def get_format_args(start_format, start_args, end_format, end_args, args, kwargs
         debug_args.extend(items)
     debug_args.extend(end_args)
     fmt = start_format \
-          + ', '.join(('%s', ) * len(args)) \
-          + (kwargs and ', ' or '') \
-          + ', '.join(('%s=%r', ) * len(kwargs)) \
-          + end_format
+        + ', '.join(('%s', ) * len(args)) \
+        + (kwargs and ', ' or '') \
+        + ', '.join(('%s=%r', ) * len(kwargs)) \
+        + end_format
     return fmt, debug_args
 
 
diff --git a/tests/validate-tests/runtests b/tests/validate-tests/runtests
index c906ef03..a6e457d9 100755
--- a/tests/validate-tests/runtests
+++ b/tests/validate-tests/runtests
@@ -24,5 +24,6 @@ def main():
     command.extend(sys.argv[1:])
     sys.exit(subprocess.call(command))
 
+
 if __name__ == "__main__":
     main()


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]