flake8: apply W rules (prefering W503)

This commit is contained in:
Yuming Zhu 2020-02-27 23:11:49 +08:00
parent c5db34a8e1
commit 2a2c5cb729
8 changed files with 35 additions and 31 deletions

10
.flake8
View file

@ -1,6 +1,12 @@
[flake8]
select = I,C,F,E
ignore = E266,E731
select = E,F,W,C,I
ignore =
# too many leading # for block comment
E266,
# do not assign a lambda expression, use a def
E731,
# line break after binary operator
W504
max_line_length = 99
exclude =
.git,

View file

@ -1046,8 +1046,8 @@ class BuildTask(BaseTaskHandler):
# scratch builds do not get imported
build_id = self.session.host.initBuild(data)
# (initBuild raises an exception if there is a conflict)
failany = (self.opts.get('fail_fast', False)
or not getattr(self.options, 'build_arch_can_fail', False))
failany = (self.opts.get('fail_fast', False) or
not getattr(self.options, 'build_arch_can_fail', False))
try:
self.extra_information = {"src": src, "data": data, "target": target}
srpm, rpms, brmap, logs = self.runBuilds(srpm, build_tag, archlist,
@ -1691,8 +1691,8 @@ class BuildMavenTask(BaseBuildTask):
# Apply patches, if present
if self.opts.get('patches'):
# filter out directories and files beginning with . (probably scm metadata)
patches = [patch for patch in os.listdir(patchcheckoutdir) if
os.path.isfile(os.path.join(patchcheckoutdir, patch)) and
patches = [patch for patch in os.listdir(patchcheckoutdir)
if os.path.isfile(os.path.join(patchcheckoutdir, patch)) and
patch.endswith('.patch')]
if not patches:
raise koji.BuildError('no patches found at %s' % self.opts.get('patches'))
@ -1818,7 +1818,7 @@ class WrapperRPMTask(BaseBuildTask):
if re.match("%s:" % tag, spec, re.M):
raise koji.BuildError("%s is not allowed to be set in spec file" % tag)
for tag in ("packager", "distribution", "vendor"):
if re.match("%%define\s+%s\s+" % tag, spec, re.M):
if re.match(r"%%define\s+%s\s+" % tag, spec, re.M):
raise koji.BuildError("%s is not allowed to be defined in spec file" % tag)
def checkHost(self, hostdata):
@ -4563,8 +4563,8 @@ class BuildIndirectionImageTask(OzImageTask):
if re.search(namere, filename):
return filename
build_diskimage = _match_name(buildfiles, ".*%s\.qcow2$" % (arch))
build_tdl = _match_name(buildfiles, "tdl.%s\.xml" % (arch))
build_diskimage = _match_name(buildfiles, r".*%s\.qcow2$" % (arch))
build_tdl = _match_name(buildfiles, r"tdl.%s\.xml" % (arch))
diskimage_full = os.path.join(builddir, build_diskimage)
tdl_full = os.path.join(builddir, build_tdl)
@ -4859,7 +4859,7 @@ class BuildSRPMFromSCMTask(BaseBuildTask):
if re.match("%s:" % tag, spec, re.M):
raise koji.BuildError("%s is not allowed to be set in spec file" % tag)
for tag in ("packager", "distribution", "vendor"):
if re.match("%%define\s+%s\s+" % tag, spec, re.M):
if re.match(r"%%define\s+%s\s+" % tag, spec, re.M):
raise koji.BuildError("%s is not allowed to be defined in spec file" % tag)
def patch_scm_source(self, sourcedir, logfile, opts):
@ -5188,8 +5188,10 @@ Build Info: %(weburl)s/buildinfo?buildID=%(build_id)i\r
return
build_pkg_name = build['package_name']
build_pkg_evr = '%s%s-%s' % ((build['epoch'] and str(build['epoch']) +
':' or ''), build['version'], build['release'])
build_pkg_evr = '%s%s-%s' % \
((build['epoch'] and str(build['epoch']) + ':' or ''),
build['version'],
build['release'])
build_nvr = koji.buildLabel(build)
build_id = build['id']
build_owner = build['owner_name']
@ -6131,8 +6133,8 @@ enabled=1
avail = to_list(rpm_idx.get(rpm_id, {}).keys())
outfile.write('%s: %r\n' % (fname, avail))
self.session.uploadWrapper(missing_log, self.uploadpath)
if (not opts['skip_missing_signatures']
and not opts['allow_missing_signatures']):
if (not opts['skip_missing_signatures'] and
not opts['allow_missing_signatures']):
raise koji.GenericError('Unsigned packages found. See '
'missing_signatures.log')

View file

@ -2676,8 +2676,7 @@ def anon_handle_list_groups(goptions, session, args):
for x in [x[1] for x in groups]:
x['tag_name'] = get_cached_tag(x['tag_id'])
print_group_list_req_group(x)
pkgs = [(x['package'], x) for x in group['packagelist']]
pkgs.sort()
pkgs = sorted([(x['package'], x) for x in group['packagelist']])
for x in [x[1] for x in pkgs]:
x['tag_name'] = get_cached_tag(x['tag_id'])
print_group_list_req_package(x)
@ -6935,7 +6934,7 @@ def anon_handle_download_task(options, session, args):
base_task = session.getTaskInfo(base_task_id)
if not base_task:
error(_('No such task: #%i') % base_task_id)
def check_downloadable(task):
return task["method"] == "buildArch"

View file

@ -988,11 +988,9 @@ def get_header_field(hdr, name, src_arch=False):
if not SUPPORTED_OPT_DEP_HDRS.get(name, True):
return []
if (src_arch and name == "ARCH"
and get_header_field(hdr, "sourcepackage")):
if src_arch and name == "ARCH" and get_header_field(hdr, "sourcepackage"):
# return "src" or "nosrc" arch instead of build arch for src packages
if (get_header_field(hdr, "nosource")
or get_header_field(hdr, "nopatch")):
if get_header_field(hdr, "nosource") or get_header_field(hdr, "nopatch"):
return "nosrc"
return "src"
@ -2172,8 +2170,8 @@ def is_requests_cert_error(e):
# are way more ugly.
errstr = str(e)
if ('Permission denied' in errstr or # certificate not readable
'certificate revoked' in errstr or
'certificate expired' in errstr or
'certificate revoked' in errstr or
'certificate expired' in errstr or
'certificate verify failed' in errstr):
return True

View file

@ -118,8 +118,7 @@ def parse_task_params(method, params):
"""
# check for new style
if (len(params) == 1 and isinstance(params[0], dict)
and '__method__' in params[0]):
if len(params) == 1 and isinstance(params[0], dict) and '__method__' in params[0]:
ret = params[0].copy()
del ret['__method__']
return ret

View file

@ -83,7 +83,7 @@ class RunRootTask(koji.tasks.BaseTaskHandler):
# path section are in form 'path%d' while order is important as some
# paths can be mounted inside other mountpoints
path_sections = [p for p in cp.sections() if re.match('path\d+', p)]
path_sections = [p for p in cp.sections() if re.match(r'path\d+', p)]
for section_name in sorted(path_sections, key=lambda x: int(x[4:])):
try:
self.config['paths'].append({

View file

@ -550,8 +550,7 @@ class RepoManager(object):
stats = self.tagUseStats(entry['taginfo']['id'])
# normalize use count
max_n = max([t.get('n_recent', 0) for t in self.needed_tags.values()]
or [1])
max_n = max([t.get('n_recent', 0) for t in self.needed_tags.values()] or [1])
if max_n == 0:
# no recent use or missing data
max_n = 1
@ -756,8 +755,7 @@ class RepoManager(object):
if running_tasks >= self.options.max_repo_tasks:
self.logger.info("Maximum number of repo tasks reached")
return
elif (len(self.tasks) + len(self.other_tasks)
>= self.options.repo_tasks_limit):
elif len(self.tasks) + len(self.other_tasks) >= self.options.repo_tasks_limit:
self.logger.info("Repo task limit reached")
return
tagname = tag['taginfo']['name']

View file

@ -316,7 +316,9 @@ class DaemonXMLRPCServer(six.moves.xmlrpc_server.SimpleXMLRPCServer):
except BaseException:
# report exception back to server
response = six.moves.xmlrpc_client.dumps(
six.moves.xmlrpc_client.Fault(1, "%s:%s" % (sys.exc_type, sys.exc_value))
six.moves.xmlrpc_client.Fault(
1, "%s:%s" %
(sys.exc_info()[0], sys.exc_info()[1]))
)
return response