[virt-tools-list] [virt-bootstrap] [PATCH] setup: Use pylint/pycodestyle modules

Cedric Bosdonnat cbosdonnat at suse.com
Mon Mar 12 10:12:45 UTC 2018


On Mon, 2018-03-12 at 09:52 +0000, Radostin Stoyanov wrote:
> Use pylint/pycodestyle modules instead of calling the executables
> to ensure that Python 3 code is checked with Py 3 version of
> pylint/pycodestyle.
> 
> Signed-off-by: Radostin Stoyanov <rstoyanov1 at gmail.com>
> ---
>  setup.py | 36 ++++++++++++++----------------------
>  1 file changed, 14 insertions(+), 22 deletions(-)
> 
> diff --git a/setup.py b/setup.py
> index 20f3de7..df404cd 100755
> --- a/setup.py
> +++ b/setup.py
> @@ -38,8 +38,6 @@ from setuptools.command.sdist import sdist
>  sys.path.insert(0, 'src')  # noqa: E402
>  import virtBootstrap
>  
> -IS_PI3 = (sys.version_info.major == 3)
> -
>  
>  def read(fname):
>      """
> @@ -96,36 +94,30 @@ class CheckPylint(setuptools.Command):
>          """
>          Call pycodestyle and pylint here.
>          """
> +        import pylint.lint
> +        import pycodestyle
>  
> -        res = 0
> -        files = ' '.join(["setup.py", "src/virtBootstrap/", "tests/"])
> +        files = ["setup.py", "src/virtBootstrap/", "tests/"]
>          output_format = "colorized" if sys.stdout.isatty() else "text"
>  
>          print(">>> Running pycodestyle ...")
>  
> -        if IS_PI3 and virtBootstrap.utils.is_installed('pycodestyle-3'):
> -            cmd = "pycodestyle-3 "
> -        else:
> -            cmd = "pycodestyle "
> -
> -        if (subprocess.call(cmd + files, shell=True) != 0):
> -            res = 1
> +        style_guide = pycodestyle.StyleGuide(paths=files)
> +        report = style_guide.check_files()
> +        if style_guide.options.count:
> +            sys.stderr.write(str(report.total_errors) + '\n')
>  
>          print(">>> Running pylint ...")
> -        args = ""
> -        if self.errors_only:
> -            args = "-E"
>  
> -        if IS_PI3 and virtBootstrap.utils.is_installed('pylint-3'):
> -            cmd = "pylint-3 "
> -        else:
> -            cmd = "pylint "
> +        pylint_opts = [
> +            "--rcfile", "pylintrc",
> +            "--output-format=%s" % output_format
> +        ]
>  
> -        cmd += "%s --output-format=%s " % (args, format(output_format))
> -        if (subprocess.call(cmd + files, shell=True) != 0):
> -            res = 1
> +        if self.errors_only:
> +            pylint_opts.append("-E")
>  
> -        sys.exit(res)
> +        pylint.lint.Run(files + pylint_opts)
>  
>  
>  # SdistCommand is reused from the libvirt python binding (GPLv2+)

ACK

--
Cedric




More information about the virt-tools-list mailing list