From b87c0698669d4fcdf48302cdae809f87464a049c Mon Sep 17 00:00:00 2001 From: Stefan Bühler Date: Jul 22 2017 09:16:42 +0000 Subject: Fix pep8 warnings in pagure/ folder Mostly W503 (line break before binary operator), and in comments E265 (block comment should start with '# '), E261 (at least two spaces before inline comment) and E501 (line too long). Also dropped some '# noqa' markers that didn't silence a warning. --- diff --git a/pagure/api/issue.py b/pagure/api/issue.py index d7bd0b3..1e06310 100644 --- a/pagure/api/issue.py +++ b/pagure/api/issue.py @@ -66,8 +66,8 @@ def _check_token(repo, project_token=True): if api_authenticated(): # if there is a project associated with the token, check it # if there is no project associated, check if it is required - if (flask.g.token.project is not None - and repo != flask.g.token.project) \ + if (flask.g.token.project is not None and + repo != flask.g.token.project) \ or (flask.g.token.project is None and project_token): raise pagure.exceptions.APIError( 401, error_code=APIERROR.EINVALIDTOK) @@ -97,11 +97,11 @@ def _check_private_issue_access(issue): :raises pagure.exceptions.APIError: when access denied """ if ( - issue.private - and not is_repo_committer(issue.project) - and ( - not api_authenticated() - or not issue.user.user == flask.g.fas_user.username + issue.private and + not is_repo_committer(issue.project) and + ( + not api_authenticated() or + not issue.user.user == flask.g.fas_user.username ) ): raise pagure.exceptions.APIError( diff --git a/pagure/forms.py b/pagure/forms.py index 2f35243..2e54bf3 100644 --- a/pagure/forms.py +++ b/pagure/forms.py @@ -42,8 +42,8 @@ class PagureForm(FlaskForm): delta = pagure.APP.config.get('WTF_CSRF_TIME_LIMIT', 3600) if delta \ and ( - not hasattr(wtf, '__version__') - or tuple( + not hasattr(wtf, '__version__') or + tuple( int(v) for v in wtf.__version__.split('.') ) < (0, 10, 0) ): diff --git a/pagure/hooks/__init__.py b/pagure/hooks/__init__.py index 62f214e..c9750c7 100644 --- a/pagure/hooks/__init__.py +++ b/pagure/hooks/__init__.py @@ -95,8 +95,8 @@ class BaseHook(object): os.makedirs(hookfolder) # Install the hook itself - hook_file = os.path.join(repopath, 'hooks', cls.hook_type + '.' - + hook_name) + hook_file = os.path.join(repopath, 'hooks', cls.hook_type + '.' + + hook_name) if not os.path.exists(hook_file): os.symlink( @@ -116,7 +116,7 @@ class BaseHook(object): if not os.path.exists(repopath): raise FileNotFoundException('Repo %s not found' % repopath) - hook_path = os.path.join(repopath, 'hooks', cls.hook_type + '.' - + hook_name) + hook_path = os.path.join(repopath, 'hooks', cls.hook_type + '.' + + hook_name) if os.path.exists(hook_path): os.unlink(hook_path) diff --git a/pagure/hooks/files/git_multimail.py b/pagure/hooks/files/git_multimail.py index e7aa9a5..69695dd 100755 --- a/pagure/hooks/files/git_multimail.py +++ b/pagure/hooks/files/git_multimail.py @@ -951,10 +951,10 @@ class ReferenceChange(Change): yield '\n' yield 'Detailed log of new commits:\n\n' for line in read_git_lines( - ['log', '--no-walk'] - + self.logopts - + new_commits_list - + ['--'], + ['log', '--no-walk'] + + self.logopts + + new_commits_list + + ['--'], keepends=True,): yield line @@ -1106,9 +1106,9 @@ class ReferenceChange(Change): yield '\n' yield 'Summary of changes:\n' for line in read_git_lines( - ['diff-tree'] - + self.diffopts - + ['%s..%s' % ( + ['diff-tree'] + + self.diffopts + + ['%s..%s' % ( self.old.commit_sha1, self.new.commit_sha1,)], keepends=True,): yield line @@ -1407,9 +1407,9 @@ class SendMailer(Mailer): p = subprocess.Popen(self.command, stdin=subprocess.PIPE) except OSError as e: sys.stderr.write( - '*** Cannot execute command: %s\n' % ' '.join(self.command) - + '*** %s\n' % str(e) - + '*** Try setting multimailhook.mailer to "smtp"\n' + '*** Cannot execute command: %s\n' % ' '.join(self.command) + + '*** %s\n' % str(e) + + '*** Try setting multimailhook.mailer to "smtp"\n' '*** to send emails without using the sendmail command.\n' ) sys.exit(1) @@ -1772,8 +1772,8 @@ class ConfigOptionsEnvironmentMixin(ConfigEnvironmentMixin): except ValueError: sys.stderr.write( '*** Malformed value for multimailhook.maxCommitEmails: ' - '%s\n' % maxcommitemails - + '*** Expected a number. Ignoring.\n' + '%s\n' % maxcommitemails + + '*** Expected a number. Ignoring.\n' ) diffopts = config.get('diffopts') @@ -1792,8 +1792,8 @@ class ConfigOptionsEnvironmentMixin(ConfigEnvironmentMixin): self.__reply_to_refchange = config.get( 'replyToRefchange', default=reply_to) if ( - self.__reply_to_refchange is not None - and self.__reply_to_refchange.lower() == 'author'): + self.__reply_to_refchange is not None and + self.__reply_to_refchange.lower() == 'author'): raise ConfigurationException( '"author" is not an allowed setting for replyToRefchange' ) @@ -1802,16 +1802,16 @@ class ConfigOptionsEnvironmentMixin(ConfigEnvironmentMixin): def get_administrator(self): return ( - self.config.get('administrator') - or self.get_sender() - or super( + self.config.get('administrator') or + self.get_sender() or + super( ConfigOptionsEnvironmentMixin, self).get_administrator() ) def get_repo_shortname(self): return ( - self.config.get('reponame') - or super( + self.config.get('reponame') or + super( ConfigOptionsEnvironmentMixin, self).get_repo_shortname() ) @@ -2021,9 +2021,9 @@ class StaticRecipientsEnvironmentMixin(Environment): # actual *contents* of the change being reported, we only # choose based on the *type* of the change. Therefore we can # compute them once and for all: - if not (refchange_recipients - or announce_recipients - or revision_recipients): + if not (refchange_recipients or + announce_recipients or + revision_recipients): raise ConfigurationException('No email recipients configured!') self.__refchange_recipients = refchange_recipients self.__announce_recipients = announce_recipients @@ -2129,8 +2129,8 @@ class GitoliteEnvironmentMixin(Environment): # repo_shortname (though it's probably not as good as a value # the user might have explicitly put in his config). return ( - self.osenv.get('GL_REPO', None) - or super(GitoliteEnvironmentMixin, self).get_repo_shortname() + self.osenv.get('GL_REPO', None) or + super(GitoliteEnvironmentMixin, self).get_repo_shortname() ) def get_pusher(self): @@ -2394,8 +2394,8 @@ class Push(object): if max_emails and len(sha1s) > max_emails: sys.stderr.write( '*** Too many new commits (%d), not sending commit ' - 'emails.\n' % len(sha1s) - + '*** Try setting multimailhook.maxCommitEmails to a ' + 'emails.\n' % len(sha1s) + + '*** Try setting multimailhook.maxCommitEmails to a ' 'greater value\n' '*** Currently, multimailhook.maxCommitEmails=%d\n' % max_emails @@ -2465,8 +2465,8 @@ def choose_mailer(config, environment): else: sys.stderr.write( 'fatal: multimailhook.mailer is set to an incorrect value: ' - '"%s"\n' % mailer - + 'please use one of "smtp" or "sendmail".\n' + '"%s"\n' % mailer + + 'please use one of "smtp" or "sendmail".\n' ) sys.exit(1) return mailer diff --git a/pagure/lib/git.py b/pagure/lib/git.py index dcf9fc3..1cb4d4e 100644 --- a/pagure/lib/git.py +++ b/pagure/lib/git.py @@ -1184,8 +1184,7 @@ def merge_pull_request( refname = '%s:refs/heads/%s' % (branch_ref.name, request.branch) if ( - (merge is not None and merge.is_uptodate) - or # noqa + (merge is not None and merge.is_uptodate) or (merge is None and mergecode & pygit2.GIT_MERGE_ANALYSIS_UP_TO_DATE)): @@ -1213,8 +1212,7 @@ def merge_pull_request( return 'NO_CHANGE' elif ( - (merge is not None and merge.is_fastforward) - or # noqa + (merge is not None and merge.is_fastforward) or (merge is None and mergecode & pygit2.GIT_MERGE_ANALYSIS_FASTFORWARD)): diff --git a/pagure/lib/git_auth.py b/pagure/lib/git_auth.py index 939e053..01faccf 100644 --- a/pagure/lib/git_auth.py +++ b/pagure/lib/git_auth.py @@ -214,8 +214,8 @@ class Gitolite2Auth(GitAuthHelper): output = [ row.rstrip() for row in config - if not row.startswith('@') - and row.strip() != '# end of groups'] + if not row.startswith('@') and + row.strip() != '# end of groups'] else: end_grp = None seen = False diff --git a/pagure/lib/notify.py b/pagure/lib/notify.py index 1337d61..670983f 100644 --- a/pagure/lib/notify.py +++ b/pagure/lib/notify.py @@ -59,8 +59,8 @@ def log(project, topic, msg, redis=None): ''' # Send fedmsg notification (if fedmsg is there and set-up) - if not project or (project.settings.get('fedmsg_notifications', True) - and not project.private): + if not project or (project.settings.get('fedmsg_notifications', True) and + not project.private): fedmsg_publish(topic, msg) if redis and project and not project.private: diff --git a/pagure/ui/diff_style.py b/pagure/ui/diff_style.py index 690165b..72d5b2a 100644 --- a/pagure/ui/diff_style.py +++ b/pagure/ui/diff_style.py @@ -23,87 +23,99 @@ class DiffStyle(Style): # flake8: noqa - Ignore this entire file styles = { # No corresponding class for the following: - #Text: "", # class: '' - Whitespace: "underline #f8f8f8", # class: 'w' - Error: "#a40000 border:#ef2929", # class: 'err' - Other: "#000000", # class 'x' - - Comment: "italic #8f5902", # class: 'c' - Comment.Multiline: "italic #8f5902", # class: 'cm' - Comment.Preproc: "italic #8f5902", # class: 'cp' - Comment.Single: "italic #8f5902", # class: 'c1' - Comment.Special: "italic #8f5902", # class: 'cs' - - Keyword: "bold #204a87", # class: 'k' - Keyword.Constant: "bold #204a87", # class: 'kc' - Keyword.Declaration: "bold #204a87", # class: 'kd' - Keyword.Namespace: "bold #204a87", # class: 'kn' - Keyword.Pseudo: "bold #204a87", # class: 'kp' - Keyword.Reserved: "bold #204a87", # class: 'kr' - Keyword.Type: "bold #204a87", # class: 'kt' - - Operator: "bold #ce5c00", # class: 'o' - Operator.Word: "bold #204a87", # class: 'ow' - like keywords - - Punctuation: "bold #000000", # class: 'p' + # Text: "", # class: '' + Whitespace: "underline #f8f8f8", # class: 'w' + Error: "#a40000 border:#ef2929", # class: 'err' + Other: "#000000", # class 'x' + + Comment: "italic #8f5902", # class: 'c' + Comment.Multiline: "italic #8f5902", # class: 'cm' + Comment.Preproc: "italic #8f5902", # class: 'cp' + Comment.Single: "italic #8f5902", # class: 'c1' + Comment.Special: "italic #8f5902", # class: 'cs' + + Keyword: "bold #204a87", # class: 'k' + Keyword.Constant: "bold #204a87", # class: 'kc' + Keyword.Declaration: "bold #204a87", # class: 'kd' + Keyword.Namespace: "bold #204a87", # class: 'kn' + Keyword.Pseudo: "bold #204a87", # class: 'kp' + Keyword.Reserved: "bold #204a87", # class: 'kr' + Keyword.Type: "bold #204a87", # class: 'kt' + + Operator: "bold #ce5c00", # class: 'o' + # like keywords: + Operator.Word: "bold #204a87", # class: 'ow' + + Punctuation: "bold #000000", # class: 'p' # Because special names such as Name.Class, Name.Function, etc. # are not recognized as such later in the parsing, we choose them # to look the same as ordinary variables. - Name: "#000000", # class: 'n' - Name.Attribute: "#c4a000", # class: 'na' - to be revised - Name.Builtin: "#204a87", # class: 'nb' - Name.Builtin.Pseudo: "#3465a4", # class: 'bp' - Name.Class: "#000000", # class: 'nc' - to be revised - Name.Constant: "#000000", # class: 'no' - to be revised - Name.Decorator: "bold #5c35cc", # class: 'nd' - to be revised - Name.Entity: "#ce5c00", # class: 'ni' - Name.Exception: "bold #cc0000", # class: 'ne' - Name.Function: "#000000", # class: 'nf' - Name.Property: "#000000", # class: 'py' - Name.Label: "#f57900", # class: 'nl' - Name.Namespace: "#000000", # class: 'nn' - to be revised - Name.Other: "#000000", # class: 'nx' - Name.Tag: "bold #204a87", # class: 'nt' - like a keyword - Name.Variable: "#000000", # class: 'nv' - to be revised - Name.Variable.Class: "#000000", # class: 'vc' - to be revised - Name.Variable.Global: "#000000", # class: 'vg' - to be revised - Name.Variable.Instance: "#000000", # class: 'vi' - to be revised + Name: "#000000", # class: 'n' + # to be revised: + Name.Attribute: "#c4a000", # class: 'na' + Name.Builtin: "#204a87", # class: 'nb' + Name.Builtin.Pseudo: "#3465a4", # class: 'bp' + # to be revised: + Name.Class: "#000000", # class: 'nc' + # to be revised: + Name.Constant: "#000000", # class: 'no' + # to be revised: + Name.Decorator: "bold #5c35cc", # class: 'nd' + Name.Entity: "#ce5c00", # class: 'ni' + Name.Exception: "bold #cc0000", # class: 'ne' + Name.Function: "#000000", # class: 'nf' + Name.Property: "#000000", # class: 'py' + Name.Label: "#f57900", # class: 'nl' + # to be revised: + Name.Namespace: "#000000", # class: 'nn' + Name.Other: "#000000", # class: 'nx' + # like a keyword: + Name.Tag: "bold #204a87", # class: 'nt' + # to be revised: + Name.Variable: "#000000", # class: 'nv' + # to be revised: + Name.Variable.Class: "#000000", # class: 'vc' + # to be revised: + Name.Variable.Global: "#000000", # class: 'vg' + # to be revised: + Name.Variable.Instance: "#000000", # class: 'vi' # since the tango light blue does not show up well in text, we choose # a pure blue instead. - Number: "bold #0000cf", # class: 'm' - Number.Float: "bold #0000cf", # class: 'mf' - Number.Hex: "bold #0000cf", # class: 'mh' - Number.Integer: "bold #0000cf", # class: 'mi' - Number.Integer.Long: "bold #0000cf", # class: 'il' - Number.Oct: "bold #0000cf", # class: 'mo' - - Literal: "#000000", # class: 'l' - Literal.Date: "#000000", # class: 'ld' - - String: "#4e9a06", # class: 's' - String.Backtick: "#4e9a06", # class: 'sb' - String.Char: "#4e9a06", # class: 'sc' - String.Doc: "italic #8f5902", # class: 'sd' - like a comment - String.Double: "#4e9a06", # class: 's2' - String.Escape: "#4e9a06", # class: 'se' - String.Heredoc: "#4e9a06", # class: 'sh' - String.Interpol: "#4e9a06", # class: 'si' - String.Other: "#4e9a06", # class: 'sx' - String.Regex: "#4e9a06", # class: 'sr' - String.Single: "#4e9a06", # class: 's1' - String.Symbol: "#4e9a06", # class: 'ss' - - Generic: "#000000", # class: 'g' + Number: "bold #0000cf", # class: 'm' + Number.Float: "bold #0000cf", # class: 'mf' + Number.Hex: "bold #0000cf", # class: 'mh' + Number.Integer: "bold #0000cf", # class: 'mi' + Number.Integer.Long: "bold #0000cf", # class: 'il' + Number.Oct: "bold #0000cf", # class: 'mo' + + Literal: "#000000", # class: 'l' + Literal.Date: "#000000", # class: 'ld' + + String: "#4e9a06", # class: 's' + String.Backtick: "#4e9a06", # class: 'sb' + String.Char: "#4e9a06", # class: 'sc' + # like a comment: + String.Doc: "italic #8f5902", # class: 'sd' + String.Double: "#4e9a06", # class: 's2' + String.Escape: "#4e9a06", # class: 'se' + String.Heredoc: "#4e9a06", # class: 'sh' + String.Interpol: "#4e9a06", # class: 'si' + String.Other: "#4e9a06", # class: 'sx' + String.Regex: "#4e9a06", # class: 'sr' + String.Single: "#4e9a06", # class: 's1' + String.Symbol: "#4e9a06", # class: 'ss' + + Generic: "#000000", # class: 'g' Generic.Deleted: 'bg:#ffdddd #a40000', # trac bg color Generic.Inserted: 'bg:#ddffdd #00A000', # trac bg color - Generic.Emph: "italic #000000", # class: 'ge' - Generic.Error: "#ef2929", # class: 'gr' - Generic.Heading: "bold #000080", # class: 'gh' - Generic.Output: "italic #000000", # class: 'go' - Generic.Prompt: "#8f5902", # class: 'gp' - Generic.Strong: "bold #000000", # class: 'gs' - Generic.Subheading: "bold #800080", # class: 'gu' - Generic.Traceback: "bold #a40000", # class: 'gt' + Generic.Emph: "italic #000000", # class: 'ge' + Generic.Error: "#ef2929", # class: 'gr' + Generic.Heading: "bold #000080", # class: 'gh' + Generic.Output: "italic #000000", # class: 'go' + Generic.Prompt: "#8f5902", # class: 'gp' + Generic.Strong: "bold #000000", # class: 'gs' + Generic.Subheading: "bold #800080", # class: 'gu' + Generic.Traceback: "bold #a40000", # class: 'gt' } diff --git a/pagure/ui/filters.py b/pagure/ui/filters.py index ae39f67..8119990 100644 --- a/pagure/ui/filters.py +++ b/pagure/ui/filters.py @@ -188,10 +188,10 @@ def format_loc(loc, commit=None, filename=None, tree_id=None, prequest=None, status = str(comment.parent.status).lower() if authenticated() and ( ( - status in ['true', 'open'] - and comment.user.user == flask.g.fas_user.username - ) - or is_repo_committer(comment.parent.project)): + status in ['true', 'open'] and + comment.user.user == flask.g.fas_user.username + ) or + is_repo_committer(comment.parent.project)): templ_delete = tpl_delete % ({'commentid': comment.id}) templ_edit = tpl_edit % ({ 'edit_url': flask.url_for( diff --git a/pagure/ui/fork.py b/pagure/ui/fork.py index 1b5111f..d9c1294 100644 --- a/pagure/ui/fork.py +++ b/pagure/ui/fork.py @@ -545,8 +545,8 @@ def pull_request_drop_comment( if comment is None or comment.pull_request.project != repo: flask.abort(404, 'Comment not found') - if (flask.g.fas_user.username != comment.user.username - or comment.parent.status is False) \ + if (flask.g.fas_user.username != comment.user.username or + comment.parent.status is False) \ and not flask.g.repo_committer: flask.abort( 403, @@ -605,8 +605,8 @@ def pull_request_edit_comment( if comment is None or comment.parent.project != project: flask.abort(404, 'Comment not found') - if (flask.g.fas_user.username != comment.user.username - or comment.parent.status != 'Open') \ + if (flask.g.fas_user.username != comment.user.username or + comment.parent.status != 'Open') \ and not flask.g.repo_committer: flask.abort(403, 'You are not allowed to edit the comment') diff --git a/pagure/ui/issues.py b/pagure/ui/issues.py index 47a4ede..7d8ef7d 100644 --- a/pagure/ui/issues.py +++ b/pagure/ui/issues.py @@ -133,8 +133,8 @@ def update_issue(repo, issueid, username=None, namespace=None): if comment is None or comment.issue.project != repo: flask.abort(404, 'Comment not found') - if (flask.g.fas_user.username != comment.user.username - or comment.parent.status != 'Open') \ + if (flask.g.fas_user.username != comment.user.username or + comment.parent.status != 'Open') \ and not flask.g.repo_committer: flask.abort( 403, @@ -480,9 +480,9 @@ def update_tags(repo, username=None, namespace=None): tags = [ tag.strip() for tag in flask.request.form.getlist('tag') - if tag.strip() - and tag.strip() not in seen # noqa - and not seen.add(tag.strip()) + if tag.strip() and + tag.strip() not in seen and + not seen.add(tag.strip()) ] tag_descriptions = [ @@ -495,9 +495,9 @@ def update_tags(repo, username=None, namespace=None): colors = [ col.strip() for col in flask.request.form.getlist('tag_color') - if col.strip() - and col.strip() not in seen - and not seen.add(col.strip()) + if col.strip() and + col.strip() not in seen and + not seen.add(col.strip()) ] color_pattern = re.compile('^#\w{3,6}$') @@ -1006,8 +1006,8 @@ def view_issue(repo, issueid, username=None, namespace=None): if issue.private: if not authenticated() or ( - not flask.g.repo_committer - and issue.user.user != flask.g.fas_user.username): + not flask.g.repo_committer and + issue.user.user != flask.g.fas_user.username): flask.abort(404, 'Issue not found') status = pagure.lib.get_issue_statuses(SESSION) @@ -1122,8 +1122,8 @@ def edit_issue(repo, issueid, username=None, namespace=None): if issue is None or issue.project != repo: flask.abort(404, 'Issue not found') - if not (flask.g.repo_committer - or flask.g.fas_user.username == issue.user.username): + if not (flask.g.repo_committer or + flask.g.fas_user.username == issue.user.username): flask.abort( 403, 'You are not allowed to edit issues for this project') @@ -1408,8 +1408,8 @@ def edit_comment_issue( if comment is None or comment.parent.project != project: flask.abort(404, 'Comment not found') - if (flask.g.fas_user.username != comment.user.username - or comment.parent.status != 'Open') \ + if (flask.g.fas_user.username != comment.user.username or + comment.parent.status != 'Open') \ and not flask.g.repo_user: flask.abort(403, 'You are not allowed to edit this comment')