Browse Source

style: set 'black' target version = py39

'black' behave differently depending on the used version, especially if no python target version is set.
To avoid failed style tests caused by auto discovery, target version was set to py39 and files adjusted accordingly.
Two files required individual excludes ('# fmt: skip' and '# fmt: off|on') to get them passing the tests with different 'black' versions.
Dominik Wombacher 1 year ago
parent
commit
5eb40d6138

+ 9 - 6
pagure/hooks/files/git_multimail_upstream.py

@@ -84,6 +84,7 @@ def is_ascii(s):
     return all(ord(c) < 128 and ord(c) > 0 for c in s)
 
 
+# fmt: off
 if PYTHON3:
 
     def is_string(s):
@@ -114,7 +115,9 @@ if PYTHON3:
         except UnicodeEncodeError:
             return out.decode(ENCODING)
 
+
 else:
+# fmt: on
 
     def is_string(s):
         try:
@@ -471,7 +474,7 @@ def read_output(cmd, input=None, keepends=False, **kw):
         stdin=stdin,
         stdout=subprocess.PIPE,
         stderr=subprocess.PIPE,
-        **kw
+        **kw,
     )
     (out, err) = p.communicate(input)
     out = bytes_to_str(out, errors=errors)
@@ -2939,7 +2942,7 @@ class FilterLinesEnvironmentMixin(Environment):
         strict_utf8=True,
         email_max_line_length=500,
         max_subject_length=500,
-        **kw
+        **kw,
     ):
         super(FilterLinesEnvironmentMixin, self).__init__(**kw)
         self.__strict_utf8 = strict_utf8
@@ -3076,7 +3079,7 @@ class StaticRecipientsEnvironmentMixin(Environment):
         announce_recipients,
         revision_recipients,
         scancommitforcc,
-        **kw
+        **kw,
     ):
         super(StaticRecipientsEnvironmentMixin, self).__init__(**kw)
 
@@ -3171,7 +3174,7 @@ class ConfigRecipientsEnvironmentMixin(
                 config, "commitlist", "mailinglist"
             ),
             scancommitforcc=config.get("scancommitforcc"),
-            **kw
+            **kw,
         )
 
     def _get_recipients(self, config, *names):
@@ -3206,7 +3209,7 @@ class StaticRefFilterEnvironmentMixin(Environment):
         ref_filter_excl_regex,
         ref_filter_do_send_regex,
         ref_filter_dont_send_regex,
-        **kw
+        **kw,
     ):
         super(StaticRefFilterEnvironmentMixin, self).__init__(**kw)
 
@@ -3293,7 +3296,7 @@ class ConfigRefFilterEnvironmentMixin(
             ref_filter_dont_send_regex=self._get_regex(
                 config, "refFilterDontSendRegex"
             ),
-            **kw
+            **kw,
         )
 
 

+ 2 - 2
pagure/lib/git.py

@@ -1354,7 +1354,7 @@ def read_output(cmd, abspath, input=None, keepends=False, error=False, **kw):
         stdout=subprocess.PIPE,
         stderr=subprocess.PIPE,
         cwd=abspath,
-        **kw
+        **kw,
     )
     (out, err) = procs.communicate(input)
     retcode = procs.wait()
@@ -1386,7 +1386,7 @@ def read_git_output(
         input=input,
         keepends=keepends,
         error=error,
-        **kw
+        **kw,
     )
 
 

+ 1 - 1
pagure/lib/git_auth.py

@@ -880,7 +880,7 @@ class PagureGitAuth(GitAuthHelper):
         pull_request,
         repotype,
         is_internal,
-        **info
+        **info,
     ):
         if is_internal:
             self.info("Internal push allowed")

+ 4 - 4
pagure/lib/query.py

@@ -5524,7 +5524,7 @@ def get_pagination_metadata(
             flask_request.endpoint,
             per_page=per_page,
             _external=True,
-            **request_args_wo_page
+            **request_args_wo_page,
         )
 
     prev_page = None
@@ -5534,7 +5534,7 @@ def get_pagination_metadata(
             flask_request.endpoint,
             per_page=per_page,
             _external=True,
-            **request_args_wo_page
+            **request_args_wo_page,
         )
 
     request_args_wo_page.update({key_page: 1})
@@ -5542,7 +5542,7 @@ def get_pagination_metadata(
         flask_request.endpoint,
         per_page=per_page,
         _external=True,
-        **request_args_wo_page
+        **request_args_wo_page,
     )
 
     request_args_wo_page.update({key_page: pages})
@@ -5550,7 +5550,7 @@ def get_pagination_metadata(
         flask_request.endpoint,
         per_page=per_page,
         _external=True,
-        **request_args_wo_page
+        **request_args_wo_page,
     )
 
     return {

+ 1 - 1
pagure/lib/tasks.py

@@ -932,7 +932,7 @@ def update_checksums_file(self, session, folder, filenames):
         # for each files computes the different algorythm supported
         with open(os.path.join(folder, filename), "rb") as stream:
             while True:
-                buf = stream.read(2 * 2**10)
+                buf = stream.read(2 * 2**10)  # fmt: skip
                 if buf:
                     for hasher in algos.values():
                         hasher.update(buf)

+ 1 - 1
pagure/ui/clone.py

@@ -267,7 +267,7 @@ def proxy_repospanner(project, service):
             "x-Extra-project_user": project.user if project.is_fork else "",
             "X-Extra-project_namespace": project.namespace,
         },
-        **streamargs
+        **streamargs,
     )
 
     # Strip out any headers that cause problems

+ 8 - 8
pagure/ui/issues.py

@@ -634,7 +634,7 @@ def view_issues(repo, username=None, namespace=None):
                 no_milestones=no_stone,
                 count=True,
                 status=status,
-                **fields
+                **fields,
             )
         else:
             if status.lower() in ["open", "true"]:
@@ -658,7 +658,7 @@ def view_issues(repo, username=None, namespace=None):
             order=order,
             order_key=order_key,
             status=status,
-            **fields
+            **fields,
         )
         issues_cnt = pagure.lib.query.search_issues(
             flask.g.session,
@@ -669,7 +669,7 @@ def view_issues(repo, username=None, namespace=None):
             no_milestones=no_stone,
             count=True,
             status=status_count,
-            **fields
+            **fields,
         )
         oth_issues_cnt = pagure.lib.query.search_issues(
             flask.g.session,
@@ -680,7 +680,7 @@ def view_issues(repo, username=None, namespace=None):
             no_milestones=no_stone,
             count=True,
             status=other_status_count,
-            **fields
+            **fields,
         )
     else:
         issues = pagure.lib.query.search_issues(
@@ -693,7 +693,7 @@ def view_issues(repo, username=None, namespace=None):
             custom_search=custom_search,
             order=order,
             order_key=order_key,
-            **fields
+            **fields,
         )
         issues_cnt = pagure.lib.query.search_issues(
             flask.g.session,
@@ -702,7 +702,7 @@ def view_issues(repo, username=None, namespace=None):
             search_pattern=search_pattern,
             custom_search=custom_search,
             count=True,
-            **fields
+            **fields,
         )
         oth_issues_cnt = pagure.lib.query.search_issues(
             flask.g.session,
@@ -713,7 +713,7 @@ def view_issues(repo, username=None, namespace=None):
             no_milestones=no_stone,
             count=True,
             status="Open",
-            **fields
+            **fields,
         )
     tag_list = pagure.lib.query.get_tags_of_project(flask.g.session, repo)
 
@@ -745,7 +745,7 @@ def view_issues(repo, username=None, namespace=None):
         total_open=total_open,
         total_closed=total_closed,
         no_milestones=no_stone,
-        **fields
+        **fields,
     )
 
 

+ 1 - 0
pyproject.toml

@@ -1,5 +1,6 @@
 [tool.black]
 line-length = 79
+target-version = ['py39']
 include = '\.py?$'
 exclude = '''
 /(

+ 2 - 0
tests/test_style.py

@@ -102,6 +102,8 @@ class TestStyle(unittest.TestCase):
             "--diff",
             "--exclude",
             '"/(.eggs|.git|.hg|.mypy_cache|.nox|.tox|.venv|_build|buck-out|build|dist)/"',
+            "--target-version",
+            "py39",
             REPO_PATH,
             TESTS_PATH,
         ]