From b63973fecc2d3bc7b93fe3354088661d343e18d6 Mon Sep 17 00:00:00 2001 From: Radostin Stoyanov Date: Fri, 16 Jun 2017 11:08:19 +0100 Subject: Add automated check for code style To run the code style checks, run `python setup.py pylint` Only errors could be reported using the option --errors-only. Could be useful to run in interactive git rebase Fix the reported pylint errors as well --- setup.py | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) (limited to 'setup.py') diff --git a/setup.py b/setup.py index 3fe759f..c87d6f6 100755 --- a/setup.py +++ b/setup.py @@ -1,8 +1,16 @@ #!/usr/bin/env python # -*- coding: utf-8; -*- +""" +Setup script used for building, testing, and installing modules +based on setuptools. +""" + import codecs import os +import sys +from subprocess import call +from setuptools import Command from setuptools import setup @@ -15,6 +23,52 @@ def read(fname): return fobj.read() +class CheckPylint(Command): + """ + Check python source files with pylint and pycodestyle. + """ + + user_options = [('errors-only', 'e', 'only report errors')] + description = "Check code using pylint and pycodestyle" + + def initialize_options(self): + """ + Initialize the options to default values. + """ + # pylint: disable=attribute-defined-outside-init + self.errors_only = False + + def finalize_options(self): + """ + Check final option values. + """ + pass + + def run(self): + """ + Call pycodestyle and pylint here. + """ + + res = 0 + files = ' '.join(["setup.py", "src/virtBootstrap/*.py"]) + output_format = "colorized" if sys.stdout.isatty() else "text" + + print(">>> Running pycodestyle ...") + cmd = "pycodestyle " + if (call(cmd + files, shell=True) != 0): + res = 1 + + print(">>> Running pylint ...") + args = "" + if self.errors_only: + args = "-E" + cmd = "pylint %s --output-format=%s " % (args, format(output_format)) + if (call(cmd + files, shell=True) != 0): + res = 1 + + sys.exit(res) + + setup( name='virt-bootstrap', version='0.1.0', @@ -53,5 +107,15 @@ setup( 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6' - ] + + ], + cmdclass={ + 'pylint': CheckPylint + }, + extras_require={ + 'dev': [ + 'pylint', + 'pycodestyle' + ] + } ) -- cgit