From 65aa8fde2f6426011fb4856c47d61e60c1e3a956 Mon Sep 17 00:00:00 2001 From: Haibo Lin Date: Fri, 7 Feb 2020 10:50:25 +0800 Subject: [PATCH] Fix other flake8 complaints E231 missing whitespace after ',' E265 block comment should start with '# ' E266 too many leading '#' for block comment E302 expected 2 blank lines, found 1 E501 line too long (115 > 88 characters) E713 test for membership should be 'not in' E722 do not use bare 'except' F812 list comprehension redefines 'g' from line 1499 F821 undefined name 'cmp' F841 local variable 'ex' is assigned to but never used JIRA: COMPOSE-4108 Signed-off-by: Haibo Lin --- pungi/arch_utils.py | 8 ++++---- pungi/compose.py | 6 +++--- pungi/gather.py | 22 +++++++++++----------- pungi/scripts/pungi.py | 2 +- pungi/util.py | 2 +- pungi_utils/orchestrator.py | 2 +- setup.py | 6 +++--- tests/test_checks.py | 1 + 8 files changed, 25 insertions(+), 24 deletions(-) diff --git a/pungi/arch_utils.py b/pungi/arch_utils.py index c951ef2c..c78082f0 100644 --- a/pungi/arch_utils.py +++ b/pungi/arch_utils.py @@ -136,7 +136,7 @@ def _try_read_cpuinfo(): # pragma: no cover try: with open("/proc/cpuinfo", "r") as f: return f.readlines() - except: + except Exception: return [] @@ -147,7 +147,7 @@ def _parse_auxv(): # pragma: no cover try: with open("/proc/self/auxv", "rb") as f: data = f.read() - except: + except Exception: return # Define values from /usr/include/elf.h @@ -223,7 +223,7 @@ def getCanonPPCArch(arch): # pragma: no cover try: if platform.startswith("power") and int(platform[5:].rstrip("+")) >= 7: return "ppc64p7" - except: + except Exception: pass if machine is None: @@ -290,7 +290,7 @@ def getCanonArch(skipRpmPlatform=0): # pragma: no cover f.close() (arch, vendor, opersys) = line.split("-", 2) return arch - except: + except Exception: pass arch = os.uname()[4] diff --git a/pungi/compose.py b/pungi/compose.py index 8ca90a19..624484d7 100644 --- a/pungi/compose.py +++ b/pungi/compose.py @@ -310,9 +310,9 @@ class Compose(kobo.log.LoggingBase): self.all_variants[variant.uid] = variant # populate ci_base with variants - needed for layered-products (compose_id) - ####FIXME - compose_to_composeinfo is no longer needed and has been - #### removed, but I'm not entirely sure what this is needed for - #### or if it is at all + # FIXME - compose_to_composeinfo is no longer needed and has been + # removed, but I'm not entirely sure what this is needed for + # or if it is at all self.ci_base = compose_to_composeinfo(self) def get_variants(self, types=None, arch=None): diff --git a/pungi/gather.py b/pungi/gather.py index b2058d6c..2c4f7a80 100644 --- a/pungi/gather.py +++ b/pungi/gather.py @@ -450,7 +450,7 @@ class Pungi(PungiBase): # deal with our repos try: self.ksparser.handler.repo.methodToRepo() - except: + except Exception: pass for repo in self.ksparser.handler.repo.repoList: @@ -777,7 +777,7 @@ class Pungi(PungiBase): self.add_package(dep, msg) added.add(dep) - except (yum.Errors.InstallError, yum.Errors.YumBaseError) as ex: + except (yum.Errors.InstallError, yum.Errors.YumBaseError): self.logger.warning( "Unresolvable dependency %s in %s.%s (repo: %s)", r, @@ -1136,7 +1136,7 @@ class Pungi(PungiBase): if self.is_resolve_deps: # get conditional deps (defined in comps) for txmbr in self.ayum.tsInfo: - if not txmbr.po in self.po_list: + if txmbr.po not in self.po_list: if not is_package(txmbr.po): # we don't want sources which can be pulled in, # because 'src' arch is part of self.valid_arches @@ -1381,7 +1381,7 @@ class Pungi(PungiBase): # flags try: srpm_po = self.sourcerpm_srpmpo_map[po.sourcerpm] - except: + except Exception: self.logger.warning("Failed to find source for %s", po.sourcerpm) srpm_po = None if srpm_po in self.input_packages: @@ -1461,7 +1461,7 @@ class Pungi(PungiBase): try: pungi.util._link(local, target, self.logger, force=True) continue - except: + except Exception: self.logger.error("Unable to link %s from the yum cache." % po.name) sys.exit(1) @@ -1492,9 +1492,9 @@ class Pungi(PungiBase): # Filter out things we don't include ourgroups = [] for item in self.ksparser.handler.packages.groupList: - g = self.ayum.comps.return_group(item.name) - if g: - ourgroups.append(g.groupid) + grp = self.ayum.comps.return_group(item.name) + if grp: + ourgroups.append(grp.groupid) allgroups = [g.groupid for g in self.ayum.comps.get_groups()] for group in allgroups: if ( @@ -1595,7 +1595,7 @@ class Pungi(PungiBase): "flags": sorted(flags), } ) - result.sort(lambda x, y: cmp(x["path"], y["path"])) + result.sort(lambda x, y: cmp(x["path"], y["path"])) # noqa: F821 (py2 only) return result def list_packages(self): @@ -1796,7 +1796,7 @@ class Pungi(PungiBase): try: # Convert url method to a repo self.ksparser.handler.repo.methodToRepo() - except: + except Exception: pass for repo in self.ksparser.handler.repo.repoList: @@ -2028,7 +2028,7 @@ class Pungi(PungiBase): stderr=subprocess.PIPE, universal_newlines=True, ).communicate() - except: + except Exception: self.logger.error("Got an error from rpm2cpio") self.logger.error(err) raise diff --git a/pungi/scripts/pungi.py b/pungi/scripts/pungi.py index 4978a7a6..59b96ddc 100644 --- a/pungi/scripts/pungi.py +++ b/pungi/scripts/pungi.py @@ -336,7 +336,7 @@ def main(): if opts.do_all or opts.do_buildinstall: try: enforcing = selinux.security_getenforce() - except: + except Exception: print("INFO: selinux disabled") enforcing = False if enforcing: diff --git a/pungi/util.py b/pungi/util.py index b62ddd0f..76073c3e 100644 --- a/pungi/util.py +++ b/pungi/util.py @@ -543,7 +543,7 @@ def find_old_compose( with open(status_path, "r") as f: if f.read().strip() in allowed_statuses: composes.append((_sortable(i), os.path.abspath(path))) - except: + except Exception: continue if not composes: diff --git a/pungi_utils/orchestrator.py b/pungi_utils/orchestrator.py index c00d929e..5bf12a05 100644 --- a/pungi_utils/orchestrator.py +++ b/pungi_utils/orchestrator.py @@ -514,7 +514,7 @@ def get_compose_data(compose_path): } ) return data - except Exception as exc: + except Exception: return {} diff --git a/setup.py b/setup.py index eded5e6b..bb444415 100755 --- a/setup.py +++ b/setup.py @@ -49,7 +49,7 @@ setup( "pungi-config-validate = pungi.scripts.config_validate:cli_main", ] }, - scripts=["contrib/yum-dnf-compare/pungi-compare-depsolving",], + scripts=["contrib/yum-dnf-compare/pungi-compare-depsolving"], data_files=[ ("/usr/share/pungi", glob.glob("share/*.xsl")), ("/usr/share/pungi", glob.glob("share/*.ks")), @@ -65,6 +65,6 @@ setup( "six", "dogpile.cache", ], - extras_require={':python_version=="2.7"': ["enum34", "lockfile", "dict.sorted",]}, - tests_require=["mock", "nose", "nose-cov",], + extras_require={':python_version=="2.7"': ["enum34", "lockfile", "dict.sorted"]}, + tests_require=["mock", "nose", "nose-cov"], ) diff --git a/tests/test_checks.py b/tests/test_checks.py index 20c2da39..93ee0a29 100644 --- a/tests/test_checks.py +++ b/tests/test_checks.py @@ -602,6 +602,7 @@ class TestSchemaValidator(unittest.TestCase): {'enum': ['git://localhost/pungi-fedora.git'], 'type': 'string'}) self.assertEqual(scm_dict_properties["file"], {"type": "string"}) + class TestUmask(unittest.TestCase): def setUp(self): self.orig_umask = os.umask(0)