diff options
author | Radostin Stoyanov <rstoyanov1@gmail.com> | 2017-06-16 11:08:19 +0100 |
---|---|---|
committer | Cédric Bosdonnat <cbosdonnat@suse.com> | 2017-06-19 14:55:51 +0200 |
commit | b63973fecc2d3bc7b93fe3354088661d343e18d6 (patch) | |
tree | 50d2ec678c89933717c6b98edb8de4dba13b0307 /setup.py | |
parent | 2366b18b529288138fdbe9f2a7820bd7959109f4 (diff) | |
download | virt-bootstrap.git-b63973fecc2d3bc7b93fe3354088661d343e18d6.tar.gz virt-bootstrap.git-b63973fecc2d3bc7b93fe3354088661d343e18d6.tar.xz virt-bootstrap.git-b63973fecc2d3bc7b93fe3354088661d343e18d6.zip |
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
Diffstat (limited to 'setup.py')
-rwxr-xr-x | setup.py | 66 |
1 files changed, 65 insertions, 1 deletions
@@ -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' + ] + } ) |