From 642508ccf6ad2c966e730809e4a6dbaf1364f381 Mon Sep 17 00:00:00 2001 From: Yuming Zhu Date: Mar 03 2020 13:35:08 +0000 Subject: flake8: follow all F rules --- diff --git a/.flake8 b/.flake8 index 65dba9a..0a8cb0c 100644 --- a/.flake8 +++ b/.flake8 @@ -1,6 +1,5 @@ [flake8] -select = I,C,F4 -ignore = F +select = I,C,F exclude = .git, __pycache__, tests, diff --git a/cli/koji_cli/commands.py b/cli/koji_cli/commands.py index 08c9544..bc7d76c 100644 --- a/cli/koji_cli/commands.py +++ b/cli/koji_cli/commands.py @@ -1369,7 +1369,7 @@ def _import_comps(session, filename, tag, options): if pkg.type == libcomps.PACKAGE_TYPE_CONDITIONAL: pkgopts['requires'] = pkg.requires for k in pkgopts.keys(): - if six.PY2 and isinstance(pkgopts[k], unicode): + if six.PY2 and isinstance(pkgopts[k], unicode): # noqa: F821 pkgopts[k] = str(pkgopts[k]) s_opts = ', '.join(["'%s': %r" % (k, pkgopts[k]) for k in sorted(pkgopts.keys())]) print(" Package: %s: {%s}" % (pkg.name, s_opts)) @@ -1402,7 +1402,7 @@ def _import_comps_alt(session, filename, tag, options): # no cover 3.x if ptype == 'conditional': pkgopts['requires'] = pdata[pkg] for k in pkgopts.keys(): - if six.PY2 and isinstance(pkgopts[k], unicode): + if six.PY2 and isinstance(pkgopts[k], unicode): # noqa: F821 pkgopts[k] = str(pkgopts[k]) s_opts = ', '.join(["'%s': %r" % (k, pkgopts[k]) for k in sorted(pkgopts.keys())]) print(" Package: %s: {%s}" % (pkg, s_opts)) diff --git a/hub/kojihub.py b/hub/kojihub.py index 4eb7f84..55184a8 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -3041,7 +3041,7 @@ def lookup_name(table, info, strict=False, create=False): q = """SELECT id,name FROM %s WHERE id=%%(info)d""" % table elif isinstance(info, str): q = """SELECT id,name FROM %s WHERE name=%%(info)s""" % table - elif six.PY2 and isinstance(info, unicode): + elif six.PY2 and isinstance(info, unicode): # noqa: F821 info = koji.fixEncoding(info) q = """SELECT id,name FROM %s WHERE name=%%(info)s""" % table else: diff --git a/hub/kojixmlrpc.py b/hub/kojixmlrpc.py index e615be0..8515a1a 100644 --- a/hub/kojixmlrpc.py +++ b/hub/kojixmlrpc.py @@ -395,7 +395,6 @@ def load_config(environ): - all PythonOptions (except ConfigFile) are now deprecated and support for them will disappear in a future version of Koji """ - logger = logging.getLogger("koji") #get our config file(s) cf = environ.get('koji.hub.ConfigFile', '/etc/koji-hub/hub.conf') cfdir = environ.get('koji.hub.ConfigDir', '/etc/koji-hub/hub.conf.d') diff --git a/koji/__init__.py b/koji/__init__.py index 1ddf48b..16720f5 100644 --- a/koji/__init__.py +++ b/koji/__init__.py @@ -521,7 +521,7 @@ def ensuredir(directory): # note: if head is blank, then we've reached the top of a relative path try: os.mkdir(directory) - except OSError as e: + except OSError: # do not thrown when dir already exists (could happen in a race) if not os.path.isdir(directory): # something else must have gone wrong @@ -3458,7 +3458,7 @@ def fix_encoding(value, fallback='iso8859-15', remove_nonprintable=False): # play encoding tricks for py2 strings if six.PY2: - if isinstance(value, unicode): + if isinstance(value, unicode): # noqa: F821 # just convert it to a utf8-encoded str value = value.encode('utf8') elif isinstance(value, str): diff --git a/koji/arch.py b/koji/arch.py index dc1fde8..431c9bc 100644 --- a/koji/arch.py +++ b/koji/arch.py @@ -176,8 +176,6 @@ def getBestArchFromList(archlist, myarch=None): if myarch is None: myarch = canonArch - mybestarch = getBestArch(myarch) - bestarch = getBestArch(myarch) if bestarch != myarch: bestarchchoice = getBestArchFromList(archlist, bestarch) diff --git a/koji/daemon.py b/koji/daemon.py index e7775cc..8bb3a2e 100644 --- a/koji/daemon.py +++ b/koji/daemon.py @@ -398,7 +398,7 @@ class SCM(object): def _run(cmd, chdir=None, fatal=False, log=True, _count=[0]): if globals().get('KOJIKAMID'): #we've been inserted into kojikamid, use its run() - return run(cmd, chdir=chdir, fatal=fatal, log=log) + return run(cmd, chdir=chdir, fatal=fatal, log=log) # noqa: F821 else: append = (_count[0] > 0) _count[0] += 1 diff --git a/koji/xmlrpcplus.py b/koji/xmlrpcplus.py index e24d415..279d3ab 100644 --- a/koji/xmlrpcplus.py +++ b/koji/xmlrpcplus.py @@ -52,7 +52,7 @@ class ExtendedMarshaller(xmlrpc_client.Marshaller): if six.PY2: - ExtendedMarshaller.dispatch[long] = ExtendedMarshaller.dump_int + ExtendedMarshaller.dispatch[long] = ExtendedMarshaller.dump_int # noqa: F821 diff --git a/vm/kojikamid.py b/vm/kojikamid.py index f4f26ae..311b2e6 100755 --- a/vm/kojikamid.py +++ b/vm/kojikamid.py @@ -61,8 +61,8 @@ class fakemodule(object): #make parts of the above insert accessible as koji.X koji = fakemodule() -koji.GenericError = GenericError -koji.BuildError = BuildError +koji.GenericError = GenericError # noqa: F821 +koji.BuildError = BuildError # noqa: F821 def encode_int(n): """If n is too large for a 32bit signed, convert it to a string""" @@ -88,9 +88,9 @@ class WindowsBuild(object): else: self.task_opts = {} self.workdir = '/tmp/build' - ensuredir(self.workdir) + ensuredir(self.workdir) # noqa: F821 self.buildreq_dir = os.path.join(self.workdir, 'buildreqs') - ensuredir(self.buildreq_dir) + ensuredir(self.buildreq_dir) # noqa: F821 self.source_dir = None self.spec_dir = None self.patches_dir = None @@ -148,20 +148,20 @@ class WindowsBuild(object): else: self.logger.info('file %s exists', entry) if errors: - raise BuildError('error validating build environment: %s' % \ - ', '.join(errors)) + raise BuildError('error validating build environment: %s' % # noqa: F821 + ', '.join(errors)) def updateClam(self): """update ClamAV virus definitions""" ret, output = run(['/bin/freshclam', '--quiet']) if ret: - raise BuildError('could not update ClamAV database: %s' % output) + raise BuildError('could not update ClamAV database: %s' % output) # noqa: F821 def checkEnv(self): """make the environment is fit for building in""" for tool in ['/bin/freshclam', '/bin/clamscan', '/bin/patch']: if not os.path.isfile(tool): - raise BuildError('%s is missing from the build environment' % tool) + raise BuildError('%s is missing from the build environment' % tool) # noqa: F821 def zipDir(self, rootdir, filename): rootbase = os.path.basename(rootdir) @@ -178,18 +178,18 @@ class WindowsBuild(object): def checkout(self): """Checkout sources, winspec, and patches, and apply patches""" - src_scm = SCM(self.source_url) - self.source_dir = src_scm.checkout(ensuredir(os.path.join(self.workdir, 'source'))) + src_scm = SCM(self.source_url) # noqa: F821 + self.source_dir = src_scm.checkout(ensuredir(os.path.join(self.workdir, 'source'))) # noqa: F821 self.zipDir(self.source_dir, os.path.join(self.workdir, 'sources.zip')) if 'winspec' in self.task_opts: - spec_scm = SCM(self.task_opts['winspec']) - self.spec_dir = spec_scm.checkout(ensuredir(os.path.join(self.workdir, 'spec'))) + spec_scm = SCM(self.task_opts['winspec']) # noqa: F821 + self.spec_dir = spec_scm.checkout(ensuredir(os.path.join(self.workdir, 'spec'))) # noqa: F821 self.zipDir(self.spec_dir, os.path.join(self.workdir, 'spec.zip')) else: self.spec_dir = self.source_dir if 'patches' in self.task_opts: - patch_scm = SCM(self.task_opts['patches']) - self.patches_dir = patch_scm.checkout(ensuredir(os.path.join(self.workdir, 'patches'))) + patch_scm = SCM(self.task_opts['patches']) # noqa: F821 + self.patches_dir = patch_scm.checkout(ensuredir(os.path.join(self.workdir, 'patches'))) # noqa: F821 self.zipDir(self.patches_dir, os.path.join(self.workdir, 'patches.zip')) self.applyPatches(self.source_dir, self.patches_dir) self.virusCheck(self.workdir) @@ -200,7 +200,7 @@ class WindowsBuild(object): os.path.isfile(os.path.join(patchdir, patch)) and \ patch.endswith('.patch')] if not patches: - raise BuildError('no patches found at %s' % patchdir) + raise BuildError('no patches found at %s' % patchdir) # noqa: F821 patches.sort() for patch in patches: cmd = ['/bin/patch', '--verbose', '-d', sourcedir, '-p1', '-i', os.path.join(patchdir, patch)] @@ -210,9 +210,9 @@ class WindowsBuild(object): """Load build configuration from the spec file.""" specfiles = [spec for spec in os.listdir(self.spec_dir) if spec.endswith('.ini')] if len(specfiles) == 0: - raise BuildError('No .ini file found') + raise BuildError('No .ini file found') # noqa: F821 elif len(specfiles) > 1: - raise BuildError('Multiple .ini files found') + raise BuildError('Multiple .ini files found') # noqa: F821 if six.PY2: conf = SafeConfigParser() @@ -306,7 +306,7 @@ class WindowsBuild(object): """Create the buildroot object on the hub.""" repo_id = self.task_opts.get('repo_id') if not repo_id: - raise BuildError('repo_id must be specified') + raise BuildError('repo_id must be specified') # noqa: F821 self.buildroot_id = self.server.initBuildroot(repo_id, self.platform) def expireBuildroot(self): @@ -316,9 +316,9 @@ class WindowsBuild(object): def fetchFile(self, basedir, buildinfo, fileinfo, brtype): """Download the file from buildreq, at filepath, into the basedir""" destpath = os.path.join(basedir, fileinfo['localpath']) - ensuredir(os.path.dirname(destpath)) + ensuredir(os.path.dirname(destpath)) # noqa: F821 if 'checksum_type' in fileinfo: - checksum_type = CHECKSUM_TYPES[fileinfo['checksum_type']] + checksum_type = CHECKSUM_TYPES[fileinfo['checksum_type']] # noqa: F821 if checksum_type == 'sha1': checksum = hashlib.sha1() elif checksum_type == 'sha256': @@ -326,7 +326,7 @@ class WindowsBuild(object): elif checksum_type == 'md5': checksum = hashlib.md5() else: - raise BuildError('Unknown checksum type %s for %s' % ( + raise BuildError('Unknown checksum type %s for %s' % ( # noqa: F821 checksum_type, os.path.basename(fileinfo['localpath']))) with open(destpath, 'w') as destfile: @@ -345,7 +345,7 @@ class WindowsBuild(object): if 'checksum_type' in fileinfo: digest = checksum.hexdigest() if fileinfo['checksum'] != digest: - raise BuildError('checksum validation failed for %s, %s (computed) != %s (provided)' % \ + raise BuildError('checksum validation failed for %s, %s (computed) != %s (provided)' % # noqa: F821 (destpath, digest, fileinfo['checksum'])) self.logger.info('Retrieved %s (%s bytes, %s: %s)', destpath, offset, checksum_type, digest) else: @@ -361,7 +361,7 @@ class WindowsBuild(object): buildinfo = self.server.getLatestBuild(self.build_tag, buildreq, self.task_opts.get('repo_id')) br_dir = os.path.join(self.buildreq_dir, buildreq, brtype) - ensuredir(br_dir) + ensuredir(br_dir) # noqa: F821 brinfo['dir'] = br_dir brfiles = [] brinfo['files'] = brfiles @@ -438,7 +438,7 @@ class WindowsBuild(object): cmd = ['cmd.exe', '/C', 'C:\\Windows\\Temp\\' + os.path.basename(tmpname)] ret, output = run(cmd, chdir=self.source_dir) if ret: - raise BuildError('build command failed, see build.log for details') + raise BuildError('build command failed, see build.log for details') # noqa: F821 def bashBuild(self): """Do the build: run the execute line(s) with bash""" @@ -470,7 +470,7 @@ class WindowsBuild(object): cmd = ['/bin/bash', '-e', '-x', tmpname] ret, output = run(cmd, chdir=self.source_dir) if ret: - raise BuildError('build command failed, see build.log for details') + raise BuildError('build command failed, see build.log for details') # noqa: F821 def checkBuild(self): """Verify that the build completed successfully.""" @@ -497,13 +497,13 @@ class WindowsBuild(object): errors.append('file %s does not exist' % entry) self.virusCheck(self.workdir) if errors: - raise BuildError('error validating build output: %s' % \ + raise BuildError('error validating build output: %s' % # noqa: F821 ', '.join(errors)) def virusCheck(self, path): """ensure a path is virus free with ClamAV. path should be absolute""" if not path.startswith('/'): - raise BuildError('Invalid path to scan for viruses: ' + path) + raise BuildError('Invalid path to scan for viruses: ' + path) # noqa: F821 run(['/bin/clamscan', '--quiet', '--recursive', path], fatal=True) def gatherResults(self): @@ -555,7 +555,7 @@ def run(cmd, chdir=None, fatal=False, log=True): msg += ', see %s for details' % (os.path.basename(logfd.name)) else: msg += ', output: %s' % output - raise BuildError(msg) + raise BuildError(msg) # noqa: F821 return ret, output def find_net_info(): diff --git a/vm/kojivmd b/vm/kojivmd index c926fa2..c0fa3ff 100755 --- a/vm/kojivmd +++ b/vm/kojivmd @@ -995,7 +995,7 @@ class VMTaskManager(TaskManager): task_info = self.session.getTaskInfo(task['id'], request=True) vm_name = task_info['request'][0] try: - vm = self.libvirt_conn.lookupByName(vm_name) + self.libvirt_conn.lookupByName(vm_name) except libvirt.libvirtError: # if this builder does not have the requested VM, # we can't handle the task