Subject: [pgAdmin4][Patch]: PEP-8 issue fixes

From: Khushboo Vashi <[email-masked]>
Date: Mon, 26 Feb 2018 17:34:24 +0530

Hi,

Please find the attached patch to fix PEP-8 issues in the below modules:

1. about
2. feature_tests
3. misc
4. utils

Thanks,
Khushboo
diff --git a/web/pgadmin/about/__init__.py b/web/pgadmin/about/__init__.py
index 98a4dd6..6d1e0b2 100644
--- a/web/pgadmin/about/__init__.py
+++ b/web/pgadmin/about/__init__.py
@@ -8,7 +8,6 @@
 ##########################################################################
 
 """A blueprint module implementing the about box."""
-MODULE_NAME = 'about'
 
 import sys
 from flask import Response, render_template, __version__, url_for
@@ -18,6 +17,8 @@ from pgadmin.utils import PgAdminModule
 from pgadmin.utils.menu import MenuItem
 import config
 
+MODULE_NAME = 'about'
+
 
 class AboutModule(PgAdminModule):
     def get_own_menuitems(self):
diff --git a/web/pgadmin/feature_tests/keyboard_shortcut_test.py b/web/pgadmin/feature_tests/keyboard_shortcut_test.py
index b83457c..443eff6 100644
--- a/web/pgadmin/feature_tests/keyboard_shortcut_test.py
+++ b/web/pgadmin/feature_tests/keyboard_shortcut_test.py
@@ -65,7 +65,8 @@ class KeyboardShortcutFeatureTest(BaseFeatureTest):
                 Keys.ALT
             ).perform()
 
-            print("Executing shortcut: " + self.new_shortcuts[s]['locator'] + "...", file=sys.stderr, end="")
+            print("Executing shortcut: " + self.new_shortcuts[s]['locator'] +
+                  "...", file=sys.stderr, end="")
 
             self.wait.until(
                 EC.presence_of_element_located(
diff --git a/web/pgadmin/feature_tests/view_data_dml_queries.py b/web/pgadmin/feature_tests/view_data_dml_queries.py
index aa75b6e..12e4295 100644
--- a/web/pgadmin/feature_tests/view_data_dml_queries.py
+++ b/web/pgadmin/feature_tests/view_data_dml_queries.py
@@ -100,7 +100,7 @@ CREATE TABLE public.defaults_{0}
         test_utils.create_database(self.server, "acceptance_test_db")
 
         # Create pre-requisite table
-        for k, v in { 1: 'id', 2:'"ID"' }.items():
+        for k, v in {1: 'id', 2: '"ID"'}.items():
             test_utils.create_table_with_query(
                 self.server,
                 "acceptance_test_db",
@@ -114,7 +114,7 @@ CREATE TABLE public.defaults_{0}
         self.page.add_server(self.server)
         self._tables_node_expandable()
         # iterate on both tables
-        for cnt in (1,2):
+        for cnt in (1, 2):
             self.page.select_tree_item('defaults_{0}'.format(str(cnt)))
             # Open Object -> View/Edit data
             self._view_data_grid()
diff --git a/web/pgadmin/misc/bgprocess/processes.py b/web/pgadmin/misc/bgprocess/processes.py
index 0c4112a..02b953d 100644
--- a/web/pgadmin/misc/bgprocess/processes.py
+++ b/web/pgadmin/misc/bgprocess/processes.py
@@ -21,10 +21,6 @@ from subprocess import Popen
 
 from pgadmin.utils import IS_PY2, u, file_quote, fs_encoding
 
-if IS_PY2:
-    from StringIO import StringIO
-else:
-    from io import StringIO
 import pytz
 from dateutil import parser
 from flask import current_app
@@ -33,6 +29,10 @@ from flask_security import current_user
 
 import config
 from pgadmin.model import Process, db
+if IS_PY2:
+    from StringIO import StringIO
+else:
+    from io import StringIO

 def get_current_time(format='%Y-%m-%d %H:%M:%S.%f %z'):
diff --git a/web/pgadmin/utils/__init__.py b/web/pgadmin/utils/__init__.py
index 198553e..5f81e09 100644
--- a/web/pgadmin/utils/__init__.py
+++ b/web/pgadmin/utils/__init__.py
@@ -7,6 +7,8 @@
 #
 ##########################################################################
 
+import os
+import sys
 from collections import defaultdict
 from operator import attrgetter
 
@@ -152,9 +154,6 @@ class PgAdminModule(Blueprint):
         return res

-import os
-import sys
-
 IS_PY2 = (sys.version_info[0] == 2)
 IS_WIN = (os.name == 'nt')
 
diff --git a/web/pgadmin/utils/compile_template_name.py b/web/pgadmin/utils/compile_template_name.py
index 28b5bf8..49c7b6a 100644
--- a/web/pgadmin/utils/compile_template_name.py
+++ b/web/pgadmin/utils/compile_template_name.py
@@ -9,8 +9,14 @@
 import os

-def compile_template_name(template_prefix, template_file_name, server_type, version):
-    return os.path.join(compile_template_path(template_prefix, server_type, version), template_file_name)
+def compile_template_name(
+    template_prefix,
+    template_file_name,
+    server_type, version
+):
+    return os.path.join(
+        compile_template_path(template_prefix, server_type, version),
+        template_file_name)

 def compile_template_path(template_prefix, server_type, version):
diff --git a/web/pgadmin/utils/javascript/tests/test_javascript_bundler.py b/web/pgadmin/utils/javascript/tests/test_javascript_bundler.py
index f946cb8..7030703 100644
--- a/web/pgadmin/utils/javascript/tests/test_javascript_bundler.py
+++ b/web/pgadmin/utils/javascript/tests/test_javascript_bundler.py
@@ -9,16 +9,15 @@

 import sys
+from pgadmin.utils.route import BaseTestGenerator
+from pgadmin.utils.javascript.javascript_bundler import JavascriptBundler
+from pgadmin.utils.javascript.javascript_bundler import JsState
 
 if sys.version_info < (3, 3):
     from mock import patch
 else:
     from unittest.mock import patch
 
-from pgadmin.utils.route import BaseTestGenerator
-from pgadmin.utils.javascript.javascript_bundler import JavascriptBundler
-from pgadmin.utils.javascript.javascript_bundler import JsState
-
 
 class JavascriptBundlerTestCase(BaseTestGenerator):
     """This tests that the javascript bundler tool causes the application to
diff --git a/web/pgadmin/utils/route.py b/web/pgadmin/utils/route.py
index 4103e87..379ef75 100644
--- a/web/pgadmin/utils/route.py
+++ b/web/pgadmin/utils/route.py
@@ -9,16 +9,16 @@
 
 import traceback
 import sys
-if sys.version_info < (2, 7):
-    import unittest2 as unittest
-else:
-    import unittest
-
 from abc import ABCMeta, abstractmethod
 from importlib import import_module
 from werkzeug.utils import find_modules
-
 import config
+import six
+
+if sys.version_info < (2, 7):
+    import unittest2 as unittest
+else:
+    import unittest

 class TestsGeneratorRegistry(ABCMeta):
@@ -76,9 +76,6 @@ class TestsGeneratorRegistry(ABCMeta):
                 traceback.print_exc(file=sys.stderr)

-import six
-
-
 @six.add_metaclass(TestsGeneratorRegistry)
 class BaseTestGenerator(unittest.TestCase):
     # Defining abstract method which will override by individual testcase.
diff --git a/web/pgadmin/utils/tests/test_compile_template_name.py b/web/pgadmin/utils/tests/test_compile_template_name.py
index 97f1b05..3f4ceb2 100644
--- a/web/pgadmin/utils/tests/test_compile_template_name.py
+++ b/web/pgadmin/utils/tests/test_compile_template_name.py
@@ -12,23 +12,27 @@ from pgadmin.utils.route import BaseTestGenerator
 
 class StartRunningQueryTest(BaseTestGenerator):
     """
-    Check that the apply_explain_plan_weapper_if_needed method works as intended
+    Check that the apply_explain_plan_weapper_if_needed method
+    works as intended
     """
     scenarios = [
-        ('When server is Postgres and version is 10, it returns the path to the postgres template', dict(
-            server_type='pg',
-            version=100000,
-
-            expected_return_value='some/prefix/#100000#/some_file.sql'
-        )),
-        ('When server is GreenPlum and version is 5, it returns the path to the GreenPlum template', dict(
-            server_type='gpdb',
-            version=80323,
-
-            expected_return_value='some/prefix/#gpdb#80323#/some_file.sql'
-        )),
+        ('When server is Postgres and version is 10, it returns the path'
+         ' to the postgres template',
+         dict(
+             server_type='pg',
+             version=100000,
+             expected_return_value='some/prefix/#100000#/some_file.sql'
+         )),
+        ('When server is GreenPlum and version is 5, it returns the path'
+         ' to the GreenPlum template',
+         dict(
+             server_type='gpdb',
+             version=80323,
+             expected_return_value='some/prefix/#gpdb#80323#/some_file.sql'
+         )),
     ]
 
     def runTest(self):
-        result = compile_template_name('some/prefix', 'some_file.sql', self.server_type, self.version)
+        result = compile_template_name(
+            'some/prefix', 'some_file.sql', self.server_type, self.version)
         self.assertEquals(result, self.expected_return_value)

---

From: Dave Page <[email-masked]>
Date: Mon, 26 Feb 2018 15:49:15 +0000

Can you rebase this please? It doesn't apply against master.

-- 
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

---

From: Khushboo Vashi <[email-masked]>
Date: Wed, 28 Feb 2018 09:49:21 +0530

On Mon, Feb 26, 2018 at 9:19 PM, Dave Page <[email-masked]> wrote:

> Please find the updated patch excluding utils module as it is already
done.

 
 import sys
 
+MODULE_NAME = 'about'
+

 
             self.wait.until(

 
-if IS_PY2:
 
 import config

index 631e981..c87a045 100644
 
+import os
+import sys
 
@@ -153,9 +155,6 @@ class PgAdminModule(Blueprint):
         return res

-import os
-import sys
-
 
@@ -316,4 +315,3 @@ SHORTCUT_FIELDS = [
         'label': gettext('Alt/Option')
     }
 ]
-
diff --git a/web/pgadmin/utils/javascript/tests/test_javascript_bundler.py b/web/pgadmin/utils/javascript/tests/test_javascript_bundler.py
index f946cb8..7030703 100644
--- a/web/pgadmin/utils/javascript/tests/test_javascript_bundler.py
+++ b/web/pgadmin/utils/javascript/tests/test_javascript_bundler.py
@@ -9,16 +9,15 @@

 import sys

 
 
 import traceback
 import sys

-import six
-
-

---

From: Dave Page <[email-masked]>
Date: Fri, 2 Mar 2018 09:37:21 +0000

Thanks, applied.