From d37c32b2d7b798bcd19bd3f075f465f5b4d10e1d Mon Sep 17 00:00:00 2001 From: Jeremy Cline Date: Nov 03 2016 23:00:46 +0000 Subject: PEP8 the codebase and add a test suite PEP8 is a widely used and accepted Python style. This commit fixes any PEP8 violations and adds a unit test that automatically lints new code for PEP8. There were several places where variables were being used that did not exist. In those cases I took a guess at what was intended. Signed-off-by: Jeremy Cline --- diff --git a/fedbisect/bisect_state.py b/fedbisect/bisect_state.py index b1a0b91..aa64f52 100755 --- a/fedbisect/bisect_state.py +++ b/fedbisect/bisect_state.py @@ -10,30 +10,43 @@ import re import shutil import subprocess -patch_blacklist = [ \ + +patch_blacklist = [ "kbuild-AFTER_LINK.patch", - "compile-fixes.patch", - "upstream-reverts.patch", - "hibernate-freeze-filesystems.patch", - "weird-root-dentry-name-debug.patch" + "compile-fixes.patch", + "upstream-reverts.patch", + "hibernate-freeze-filesystems.patch", + "weird-root-dentry-name-debug.patch", ] + class BisectState: def __init__(self, target_dir): self.workdir = os.path.abspath(target_dir) - self.kdir = self.workdir+"/kernel" - self.pkggitdir = self.workdir+"/pkg-git" + self.kdir = self.workdir + "/kernel" + self.pkggitdir = self.workdir + "/pkg-git" if not os.path.exists(self.workdir): os.makedirs(self.workdir) print self.kdir if not os.path.exists(self.kdir): - k = Repo.clone_from("git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git", self.kdir) + k = Repo.clone_from( + "git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git", + self.kdir + ) self.kernel_git = k.git - self.kernel_git.remote('add', 'stable', 'git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git') - self.kernel_git.remote('add', 'fedora', 'git://git.kernel.org/pub/scm/linux/kernel/git/jwboyer/fedora.git') + self.kernel_git.remote( + 'add', + 'stable', + 'git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git' + ) + self.kernel_git.remote( + 'add', + 'fedora', + 'git://git.kernel.org/pub/scm/linux/kernel/git/jwboyer/fedora.git' + ) self.kernel_git.remote('update') else: k = Repo(self.kdir) @@ -46,21 +59,21 @@ class BisectState: pkg = Repo(self.pkggitdir) self.pkg_git = pkg.git - if not os.path.exists(self.workdir+"/bisect-step"): - bisectf = open(self.workdir+"/bisect-step","w") + if not os.path.exists(self.workdir + "/bisect-step"): + bisectf = open(self.workdir + "/bisect-step", "w") bisectf.write("0") bisectf.close() - revf = open(self.workdir+"/bisect-step") + revf = open(self.workdir + "/bisect-step") self.rev = revf.read().rstrip() revf.close() - if not os.path.exists(self.workdir+"/step-"+self.rev): - os.makedirs(self.workdir+"/step-"+self.rev) + if not os.path.exists(self.workdir + "/step-" + self.rev): + os.makedirs(self.workdir + "/step-" + self.rev) - rfile = open("/etc/fedora-release") - self.release = rfile.read().split(" ")[2].rstrip() - rfile.close() + rfile = open("/etc/fedora-release") + self.release = rfile.read().split(" ")[2].rstrip() + rfile.close() def tag_to_commit(self, tag): # is this a stable tag or rawhide? @@ -69,46 +82,46 @@ class BisectState: m = re.match("\d\.\d\d?\.\d\d?-[123]0\d", tag) if m is not None: result = tag.split("-")[0] - return "v"+result + return "v" + result else: l = self.get_build_list(tag) if not l: - print("tag "+tag+" can't be found in koji?") + print("tag " + tag + " can't be found in koji?") return None buildinfo = koji_cli.get_build_info(l[0]['id']) (pkg_hash, t) = buildinfo self.pkg_git.checkout(pkg_hash) - if not os.path.exists(self.pkggitdir+"/gitrev"): + if not os.path.exists(self.pkggitdir + "/gitrev"): print("This is an old rawhide kernel") print("Why are you still running an old rawhide kernel") print("Please test a newer one") return None - hashf = open(self.pkggitdir+"/gitrev") + hashf = open(self.pkggitdir + "/gitrev") ghash = hashf.read() hashf.close() ghash = ghash.rstrip() return ghash def start_bisect(self, good, bad): - if os.path.exists(self.kdir+"/.git/BISECT_LOG"): + if os.path.exists(self.kdir + "/.git/BISECT_LOG"): print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!") print("A bisect is already in progress!") return 1 ghash = self.tag_to_commit(good) if ghash is None: - print("Cannot get hash from "+good) + print("Cannot get hash from " + good) return 1 bhash = self.tag_to_commit(bad) if bhash is None: - print("Cannot get hash from "+bad) + print("Cannot get hash from " + bad) return 1 self.kernel_git.bisect("start", bhash, ghash) - bisectf = open(self.workdir+"/bisect-step","w") + bisectf = open(self.workdir + "/bisect-step", "w") bisectf.write("0") bisectf.close() return 0 @@ -119,7 +132,7 @@ class BisectState: if bisect_state != "good" and \ bisect_state != "bad" and \ bisect_state != "skip": - print("state "+bisect_state+" is not good for bisect") + print("state " + bisect_state + " is not good for bisect") return self.kernel_git.reset("--hard", "HEAD") @@ -131,7 +144,7 @@ class BisectState: step = str(int(self.rev) + 1) self.rev = step - stepf = open(self.workdir+"/bisect-step", "w") + stepf = open(self.workdir + "/bisect-step", "w") stepf.write(step) stepf.close() @@ -142,21 +155,19 @@ class BisectState: if literal: vstr = vstring else: - vstr = "kernel-"+vstring+".*" + vstr = "kernel-" + vstring + ".*" results = session.search(terms=vstr, type="build", matchType="glob") return results def gen_patch_list(self, sfile, PATCHF, patchf): - patches = [] for l in sfile.readlines(): if not re.match("Patch[0-9]", l) or re.search("%\{", l): continue name = l.split(" ")[1].rstrip() if name in patch_blacklist: continue - PATCHF.write(l+"\n") - patchf.write("ApplyPatch "+name+"\n\n") - + PATCHF.write(l + "\n") + patchf.write("ApplyPatch " + name + "\n\n") def try_build(self, b, apply_patches=True, command="local"): print command @@ -169,63 +180,82 @@ class BisectState: try: self.pkg_git.checkout(pkg_hash) except: - print("pkg git checkout failed: "+pkg_hash) + print("pkg git checkout failed: " + pkg_hash) return 1 - if os.path.exists(self.workdir+"/build"): - shutil.rmtree(self.workdir+"/build") - if os.path.exists(self.workdir+"/patches"): - shutil.rmtree(self.workdir+"/patches") - if os.path.exists(self.workdir+"/PatchF"): - os.remove(self.workdir+"/PatchF") - if os.path.exists(self.workdir+"patchf"): - os.remove(self.workdir+"patchf") - - os.makedirs(self.workdir+"/build") - os.system("cp "+self.pkggitdir+"/*.patch "+self.workdir+"/build") - os.system("cp "+self.pkggitdir+"/config-* "+self.workdir+"/build") - os.system("cp "+self.pkggitdir+"/Makefile.config "+self.workdir+"/build") - sfile = open(self.pkggitdir+"/kernel.spec") - PATCHF = open(self.workdir+"/PatchF","w+") - patchf = open(self.workdir+"/patchf","w+") + if os.path.exists(self.workdir + "/build"): + shutil.rmtree(self.workdir + "/build") + if os.path.exists(self.workdir + "/patches"): + shutil.rmtree(self.workdir + "/patches") + if os.path.exists(self.workdir + "/PatchF"): + os.remove(self.workdir + "/PatchF") + if os.path.exists(self.workdir + "patchf"): + os.remove(self.workdir + "patchf") + + os.makedirs(self.workdir + "/build") + os.system("cp " + self.pkggitdir + "/*.patch " + self.workdir + "/build") + os.system("cp " + self.pkggitdir + "/config-* " + self.workdir + "/build") + os.system("cp " + self.pkggitdir + "/Makefile.config " + self.workdir + "/build") + sfile = open(self.pkggitdir + "/kernel.spec") + PATCHF = open(self.workdir + "/PatchF", "w + ") + patchf = open(self.workdir + "/patchf", "w + ") if apply_patches: self.gen_patch_list(sfile, PATCHF, patchf) - patchf.flush() - PATCHF.flush() - patchf.close() - patchf.close() - - shutil.copy(os.path.dirname(__file__)+"/scripts/kernel.spec.template", self.workdir+"/build/kernel.spec") - shutil.copy(os.path.dirname(__file__)+"/scripts/merge.pl", self.workdir+"/build/") - shutil.copy(os.path.dirname(__file__)+"/scripts/Makefile.spec", self.workdir+"/build/Makefile") - shutil.copy(os.path.dirname(__file__)+"/scripts/x509.genkey", self.workdir+"/build/") - shutil.copy(os.path.dirname(__file__)+"/scripts/mod-sign.sh", self.workdir+"/build/") - shutil.copy(os.path.dirname(__file__)+"/scripts/Makefile.release", self.workdir+"/build/") - - tag = ktag.split("-")[1] + patchf.flush() + PATCHF.flush() + patchf.close() + patchf.close() + + shutil.copy( + os.path.dirname(__file__) + "/scripts/kernel.spec.template", + self.workdir + "/build/kernel.spec" + ) + shutil.copy(os.path.dirname(__file__) + "/scripts/merge.pl", self.workdir + "/build/") + shutil.copy( + os.path.dirname(__file__) + "/scripts/Makefile.spec", + self.workdir + "/build/Makefile" + ) + shutil.copy( + os.path.dirname(__file__) + "/scripts/x509.genkey", + self.workdir + "/build/" + ) + shutil.copy( + os.path.dirname(__file__) + "/scripts/mod-sign.sh", + self.workdir + "/build/" + ) + shutil.copy( + os.path.dirname(__file__) + "/scripts/Makefile.release", + self.workdir + "/build/" + ) + + tag = ktag.split("-")[1] act_version = tag.split(".")[0] act_patch = tag.split(".")[1] act_sublevel = tag.split(".")[2] - scommand = "s/%%BISECT_STEP%%/"+self.rev+"/\n"+ \ - "s/%%ACTUAL_VERSION%%/"+act_version+"."+act_patch+"."+act_sublevel+"/\n"+ \ - "/%%PATCH_LIST%%/r "+self.workdir+"/PatchF\n"+ \ - "/%%PATCH_LIST%%/d\n"+ \ - "/%%PATCH_APP%%/r "+self.workdir+"/patchf\n"+ \ - "/%%PATCH_APP%%/d" - - subprocess.call(["sed", "-i", "-e", scommand - , self.workdir+"/build/kernel.spec"]) - - self.kernel_git.archive("HEAD", "--output="+self.workdir+"/build/linux-snapshot.tar") - print("now calling building for "+ktag+". This may take a while...") - ret = subprocess.call(["fedpkg", "--dist", "f"+self.release, command], cwd=self.workdir+"/build") - if ret and command == "local": - print("well that didn't work...") - os.system("cp "+self.workdir+"/build/.build* "+self.workdir+"/step-"+self.rev+"/"+ktag+"-fail.txt") - return ret + scommand = ( + "s/%%BISECT_STEP%%/" + self.rev + "/\n" + "s/%%ACTUAL_VERSION%%/" + act_version + + "." + act_patch + "." + act_sublevel + "/\n" + "/%%PATCH_LIST%%/r " + self.workdir + + "/PatchF\n" + "/%%PATCH_LIST%%/d\n" + "/%%PATCH_APP%%/r " + self.workdir + + "/patchf\n" + "/%%PATCH_APP%%/d" + ) + + subprocess.call(["sed", "-i", "-e", scommand, + self.workdir + "/build/kernel.spec"]) + + self.kernel_git.archive("HEAD", "--output=" + self.workdir + "/build/linux-snapshot.tar") + print("now calling building for " + ktag + ". This may take a while...") + ret = subprocess.call( + ["fedpkg", "--dist", "f" + self.release, command], + cwd=self.workdir + "/build" + ) + if ret and command == "local": + print("well that didn't work...") + os.system("cp " + self.workdir + "/build/.build* " + self.workdir + "/step-" + + self.rev + "/" + ktag + "-fail.txt") + return ret def parse_vfield(self, v): s = v.split(" ") @@ -236,7 +266,7 @@ class BisectState: def parse_makefile(self): - makef = open(self.kdir+"/Makefile") + makef = open(self.kdir + "/Makefile") lines = makef.readlines() makef.close() diff --git a/fedbisect/koji_cli.py b/fedbisect/koji_cli.py index dce8320..a8f9065 100644 --- a/fedbisect/koji_cli.py +++ b/fedbisect/koji_cli.py @@ -1,4 +1,5 @@ -#! /usr/bin/env python +#!/usr/bin/env python +# -*- coding: utf-8 -*- # Code taken and modified from koji @@ -24,9 +25,13 @@ # Mike Bonnet # Cristian Balint +from gettext import gettext as _ import os import ConfigParser + import koji +import xmlrpclib + class Options: debug = False @@ -76,7 +81,7 @@ def get_options(): # note the defaults dictionary also serves to indicate which # options *can* be set via the config file. Such options should # not have a default value set in the option parser. - if defaults.has_key(name): + if name in defaults: if name in ('anon_retry', 'offline_retry'): defaults[name] = config.getboolean(progname, name) elif name in ('max_retries', 'retry_interval', @@ -84,8 +89,7 @@ def get_options(): try: defaults[name] = int(value) except ValueError: - parser.error( - "value for %s config option must be a valid integer" % name) + print("value for %s config option must be a valid integer" % name) assert False else: defaults[name] = value @@ -112,9 +116,9 @@ def ensure_connection(session): try: ret = session.getAPIVersion() except xmlrpclib.ProtocolError: - error(_("Error: Unable to connect to server")) + print(_("Error: Unable to connect to server")) if ret != koji.API_VERSION: - warn(_("WARNING: The server is at API version %d and the client is at %d" % ( + print(_("WARNING: The server is at API version %d and the client is at %d" % ( ret, koji.API_VERSION))) @@ -132,14 +136,12 @@ def activate_session(session): # authenticate using user/password session.login() if not options.noauth and options.authtype != "noauth" and not session.logged_in: - error(_("Unable to log in, no authentication methods available")) + print(_("Unable to log in, no authentication methods available")) ensure_connection(session) if options.debug: print "successfully connected to hub" -### -# Non-koji code below -### + def get_sha(tasklabel): sha = tasklabel.split(':')[1] @@ -157,6 +159,7 @@ def start_session(): return session + def get_build_info(build_id, nvr=False): session = start_session() @@ -167,7 +170,7 @@ def get_build_info(build_id, nvr=False): info = session.getBuild(int(build_id)) if info is None: - print "No such build: %s" % build + print "No such build: %s" % build_id return None task = None @@ -186,5 +189,3 @@ def get_build_info(build_id, nvr=False): sha = get_sha(tasklabel) print sha return (sha, nvrtag) - - diff --git a/fedbisect/scripts/bisect_state.py b/fedbisect/scripts/bisect_state.py index 963f8eb..b20ba26 100755 --- a/fedbisect/scripts/bisect_state.py +++ b/fedbisect/scripts/bisect_state.py @@ -10,14 +10,15 @@ import re import shutil import subprocess -patch_blacklist = [ \ +patch_blacklist = [ "kbuild-AFTER_LINK.patch", - "compile-fixes.patch", - "upstream-reverts.patch", - "hibernate-freeze-filesystems.patch", - "weird-root-dentry-name-debug.patch" + "compile-fixes.patch", + "upstream-reverts.patch", + "hibernate-freeze-filesystems.patch", + "weird-root-dentry-name-debug.patch", ] + class BisectState: def __init__(self, target_dir): @@ -30,10 +31,19 @@ class BisectState: print self.kdir if not os.path.exists(self.kdir): - k = Repo.clone_from("git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git", self.kdir) + k = Repo.clone_from( + "git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git", self.kdir) self.kernel_git = k.git - self.kernel_git.remote('add', 'stable', 'git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git') - self.kernel_git.remote('add', 'fedora', 'git://git.kernel.org/pub/scm/linux/kernel/git/jwboyer/fedora.git') + self.kernel_git.remote( + 'add', + 'stable', + 'git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git' + ) + self.kernel_git.remote( + 'add', + 'fedora', + 'git://git.kernel.org/pub/scm/linux/kernel/git/jwboyer/fedora.git' + ) self.kernel_git.remote('update') else: k = Repo(self.kdir) @@ -47,7 +57,7 @@ class BisectState: self.pkg_git = pkg.git if not os.path.exists(self.workdir+"/bisect-step"): - bisectf = open(self.workdir+"/bisect-step","w") + bisectf = open(self.workdir+"/bisect-step", "w") bisectf.write("0") bisectf.close() @@ -58,9 +68,9 @@ class BisectState: if not os.path.exists(self.workdir+"/step-"+self.rev): os.makedirs(self.workdir+"/step-"+self.rev) - rfile = open("/etc/fedora-release") - self.release = rfile.read().split(" ")[2].rstrip() - rfile.close() + rfile = open("/etc/fedora-release") + self.release = rfile.read().split(" ")[2].rstrip() + rfile.close() def tag_to_commit(self, tag): # is this a stable tag or rawhide? @@ -108,7 +118,7 @@ class BisectState: self.kernel_git.bisect("start", bhash, ghash) - bisectf = open(self.workdir+"/bisect-step","w") + bisectf = open(self.workdir+"/bisect-step", "w") bisectf.write("0") bisectf.close() return 0 @@ -147,7 +157,6 @@ class BisectState: return results def gen_patch_list(self, sfile, PATCHF, patchf): - patches = [] for l in sfile.readlines(): if not re.match("Patch[0-9]", l) or re.search("%\{", l): continue @@ -157,7 +166,6 @@ class BisectState: PATCHF.write(l+"\n") patchf.write("ApplyPatch "+name+"\n\n") - def try_build(self, b, apply_patches=True, command="local"): print command buildid = b['id'] @@ -185,17 +193,17 @@ class BisectState: os.system("cp "+self.pkggitdir+"/*.patch "+self.workdir+"/build") os.system("cp "+self.pkggitdir+"/config-* "+self.workdir+"/build") os.system("cp "+self.pkggitdir+"/Makefile.config "+self.workdir+"/build") - sfile = open(self.pkggitdir+"/kernel.spec") - PATCHF = open(self.workdir+"/PatchF","w+") - patchf = open(self.workdir+"/patchf","w+") + sfile = open(self.pkggitdir+"/kernel.spec") + PATCHF = open(self.workdir+"/PatchF", "w+") + patchf = open(self.workdir+"/patchf", "w+") if apply_patches: self.gen_patch_list(sfile, PATCHF, patchf) - patchf.flush() - PATCHF.flush() - patchf.close() - patchf.close() + patchf.flush() + PATCHF.flush() + patchf.close() + patchf.close() shutil.copy("scripts/kernel.spec.template", self.workdir+"/build/kernel.spec") shutil.copy("scripts/merge.pl", self.workdir+"/build/") @@ -204,28 +212,34 @@ class BisectState: shutil.copy("scripts/mod-sign.sh", self.workdir+"/build/") shutil.copy("scripts/Makefile.release", self.workdir+"/build/") - tag = ktag.split("-")[1] + tag = ktag.split("-")[1] act_version = tag.split(".")[0] act_patch = tag.split(".")[1] act_sublevel = tag.split(".")[2] - scommand = "s/%%BISECT_STEP%%/"+self.rev+"/\n"+ \ - "s/%%ACTUAL_VERSION%%/"+act_version+"."+act_patch+"."+act_sublevel+"/\n"+ \ - "/%%PATCH_LIST%%/r "+self.workdir+"/PatchF\n"+ \ - "/%%PATCH_LIST%%/d\n"+ \ - "/%%PATCH_APP%%/r "+self.workdir+"/patchf\n"+ \ - "/%%PATCH_APP%%/d" + scommand = ( + "s/%%BISECT_STEP%%/" + self.rev + "/\n" + "s/%%ACTUAL_VERSION%%/" + act_version + "." + + act_patch + "." + act_sublevel + "/\n" + + "/%%PATCH_LIST%%/r " + self.workdir + "/PatchF\n" + + "/%%PATCH_LIST%%/d\n" + "/%%PATCH_APP%%/r " + + self.workdir + "/patchf\n" + "/%%PATCH_APP%%/d" + ) - subprocess.call(["sed", "-i", "-e", scommand - , self.workdir+"/build/kernel.spec"]) + subprocess.call(["sed", "-i", "-e", scommand, + self.workdir + "/build/kernel.spec"]) self.kernel_git.archive("HEAD", "--output="+self.workdir+"/build/linux-snapshot.tar") - print("now calling building for "+ktag+". This may take a while...") - ret = subprocess.call(["fedpkg", "--dist", "f"+self.release, command], cwd=self.workdir+"/build") - if ret and command == "local": - print("well that didn't work...") - os.system("cp "+self.workdir+"/build/.build* "+self.workdir+"/step-"+self.rev+"/"+ktag+"-fail.txt") - return ret + print("now calling building for "+ktag+". This may take a while...") + ret = subprocess.call( + ["fedpkg", "--dist", "f"+self.release, command], cwd=self.workdir+"/build") + if ret and command == "local": + print("well that didn't work...") + os.system( + "cp " + self.workdir + "/build/.build* " + self.workdir + "/step-" + + self.rev + "/" + ktag + "-fail.txt" + ) + return ret def parse_vfield(self, v): s = v.split(" ") diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..2e3a527 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +GitPython +xmlrpclib diff --git a/setup.py b/setup.py index 2e26622..56e015f 100644 --- a/setup.py +++ b/setup.py @@ -1,11 +1,45 @@ -from distutils.core import setup +# -*- coding: utf-8 -*- + +from setuptools import setup + + +def get_requirements(filename='requirements.txt'): + """ + Get the contents of a file listing the requirements. + + :param filename: path to a requirements file + :type filename: str + + :returns: the list of requirements + :return type: list + """ + with open(filename) as f: + return [ + line.rstrip().split('#')[0] + for line in f.readlines() + if not line.startswith('#') + ] + + +def get_description(): + with open('README.rst', 'r') as f: + return f.read() + setup( - name='Fedbisect', - version='001', - packages=['fedbisect',], - scripts=['bin/fedbisect',], - package_data={'fedbisect': ['scripts/*']}, + name='fedbisect', + version='0.0.1', + description='Command line tool to bisect problems with the Fedora kernel', + url='https://pagure.io/fedbisect', + download_url='https://pagure.io/fedbisect/releases', license='MIT', - long_description='lol@u' + long_description=get_description(), + packages=['fedbisect'], + scripts=['bin/fedbisect'], + package_data={'fedbisect': ['scripts/*']}, + tests_require=get_requirements('test-requirements.txt'), + test_suite='test', + classifiers=[ + 'Programming Language :: Python', + ], ) diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 0000000..3930480 --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1 @@ +flake8 diff --git a/test/__init__.py b/test/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test/__init__.py diff --git a/test/test_style.py b/test/test_style.py new file mode 100644 index 0000000..4972489 --- /dev/null +++ b/test/test_style.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- + +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +"""This module runs flake8 on the entire code base""" + +import os +import subprocess +import unittest + + +REPO_PATH = os.path.abspath( + os.path.dirname(os.path.join(os.path.dirname(__file__), '../'))) + + +class TestStyle(unittest.TestCase): + """Run flake8 on the repository directory as part of the unit tests.""" + + def test_code_with_flake8(self): + """Assert the code is PEP8-compliant""" + flake8_command = ['flake8', '--max-line-length', '100', REPO_PATH] + self.assertEqual(subprocess.call(flake8_command), 0) + + +if __name__ == '__main__': + unittest.main()