Exemple #1
0
def lint_files(path, filenames, exclude=()):
    for namext in filenames:
        name, ext = os.path.splitext(namext)
        if ext != '.py':
            continue
        if name in exclude:
            continue
        fullname = os.path.join(path, namext)
        print(fullname)
        epylint.lint(fullname, CONFIG)
Exemple #2
0
def lint_files(path, filenames, exclude=[]):
    for namext in filenames:
        name, ext = os.path.splitext(namext)
        if ext != '.py':
            continue
        if name in exclude:
            continue
        fullname = os.path.join(path, namext)
        print fullname
        epylint.lint(fullname, ['--ignored-modules=pygame,numpy,pygame.mixer', '--ignored-classes=Serial,pygame.Surface', '--errors-only'])
Exemple #3
0
def lint_files(path, filenames, exclude=[]):
    for namext in filenames:
        name, ext = os.path.splitext(namext)
        if ext != '.py':
            continue
        if name in exclude:
            continue
        fullname = os.path.join(path, namext)
        print fullname
        epylint.lint(fullname, [
            '--ignored-modules=pygame,numpy,pygame.mixer',
            '--ignored-classes=Serial,pygame.Surface', '--errors-only'
        ])
Exemple #4
0
    def assertLinted(self, paths, whitelist=()):  # noqa
        """Takes a path to a folder or a list of paths to folders and recursively finds
        all *.py files within that folder except the ones with filenames in whitelist.

        Will assert lint.lint(fname) == 0 for every *.py file found.
        """
        if lint is None:
            self.skipTest("pylint not installed")
            
        if isinstance(paths, str):
            paths = [paths]
        files = self._get_lintable_files(paths, whitelist=whitelist)
        for f in files:
            self.assertEqual(0, lint.lint(f, self.LINT_ARGS), 'Linting required for %s' % f)
Exemple #5
0
    def assertLinted(self, paths, whitelist=()):  # noqa
        """Takes a path to a folder or a list of paths to folders and recursively finds
        all *.py files within that folder except the ones with filenames in whitelist.

        Will assert lint.lint(fname) == 0 for every *.py file found.
        """
        if lint is None:
            self.skipTest("pylint not installed")

        if isinstance(paths, str):
            paths = [paths]
        files = self._get_lintable_files(paths, whitelist=whitelist)
        for f in files:
            self.assertEqual(0, lint.lint(f, self.LINT_ARGS), 'Linting required for %s' % f)
Exemple #6
0
    def analyse_file(self, path):
        if path[-3:] != ".py":
            return 0, 0, [], []

        find_py3_ok_result = find_py3_msg(path)
        lint_ok_result = lint.lint(path, ["--py3k"]) in [OK]
        error_list = []
        if find_py3_ok_result and not lint_ok_result:
            self.logger.error(
                "The auto-claimed python file {path} as python is not python3".
                format(path=path))
            error_list.append(path)
        if not find_py3_ok_result and lint_ok_result:
            self.logger.info("The file {path} is python3".format(path=path))
        return 0 if lint_ok_result else 1, 1, [], error_list
Exemple #7
0
    def test_quality(self):
        """
        Test case for the Pylint called from python.
        """

        config_file_path = '--rcfile=' + os.getcwd() + PYLINT_CONFIG

        pylint_exit_code = 0

        for dir_str in SOURCE_DIRS:
            print("\n=============\nCurrent directory: " + dir_str + '\n')

            pylint_exit_code |= epylint.lint(filename=dir_str,
                                             options=([config_file_path]))

        self.assertEqual(0, pylint_exit_code)
def run_pylint(modulepath, pylint_options):
    """Runs Pylint. Returns a boolean indicating success"""
    pylint_stats = Path('/run/user/{}/pylint_stats'.format(os.getuid()))
    if not pylint_stats.parent.is_dir():  #pylint: disable=no-member
        pylint_stats = Path('/run/shm/pylint_stats')
    os.environ['PYLINTHOME'] = str(pylint_stats)

    result = lint.lint(
        filename=str(modulepath),
        options=pylint_options,
    )

    if pylint_stats.is_dir():
        shutil.rmtree(str(pylint_stats))

    if result != 0:
        print('WARNING: {}() returned non-zero result: {}'.format(
            '.'.join((lint.lint.__module__, lint.lint.__name__)), result))
        return False
    return True
Exemple #9
0
def _test(root, modfile, modname, options=()):
    #    print("TEST ({}, {}, {}, {})".format(root, modfile, modname, options))
    options = ()
    if os.path.exists(".pylintrc"):
        cwd = os.getcwd()
        options += ("--rcfile=" + os.path.join(cwd, ".pylintrc"), )
    header("Linter on {}", modname).flush()
    if lint.lint(modfile, options=options) > 0:
        sys.exit(1)
    header("Doctest on {}", modname).flush()
    module = importlib.import_module(modname)
    try:
        failed, total = doctest.testmod(module, optionflags=doctest.ELLIPSIS)
    except:
        import traceback
        traceback.print_exc()
        raise

    notify("    {} tests, {} failures", total, failed)
    if failed:
        sys.exit(1)
Exemple #10
0
    def analyse_file(self, path):
        if path[-3:] != ".py":
            return 0, 0, [], []

        find_py3_ok_result = find_py3_msg(path)
        lint_ok_result = lint.lint(path, ["--py3k"]) in [OK]
        error_list = []
        if find_py3_ok_result and not lint_ok_result:
            self.logger.error(
                "The auto-claimed python file {path} as python is not python3".
                format(path=path))
            error_list.append(path)
        if not find_py3_ok_result and lint_ok_result:
            self.logger.info(
                "The file {path} is python3, adding the signature comment in the last line"
                .format(path=path))
            with open(path, "a+") as py3_file:
                py3_file.writelines(["\n\n", PY3_MSG, "\n"])

        if not lint_ok_result:
            self.logger.info("The file {path} is python2".format(path=path))
        return 1 if lint_ok_result else 0, 1, [], error_list
#!/usr/bin/env python3

# Copyright (c) 2018 The ungoogled-chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

if __name__ == '__main__':
    import sys
    from pylint import epylint as lint
    from pathlib import Path

    sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

    if len(sys.argv) < 2:
        print('Need a path to the module to test')
        exit(1)
    if len(sys.argv) > 2:
        print('Too many arguments: Expected 2, got %s' % len(sys.argv))
        exit(2)
    if not Path(sys.argv[1]).exists():
        print('Module path does not exist')
        exit(3)

    lint.lint(filename=sys.argv[1],
              options=[
                  '--disable=locally-disabled,wrong-import-position',
                  '--jobs=4'
              ])
Exemple #12
0
#!/usr/bin/python
# -*- coding: UTF-8 -*-

from pylint.epylint import lint
import os
import tempfile
import cgi
import cgitb

cgitb.enable()
form = cgi.FieldStorage()
file = tempfile.NamedTemporaryFile(delete=False)
file.write(form.getfirst("code"))
file.close()

print '''Content-type: text/html

'''

options = ['--reports', 'no',
           '--output-format', 'JSONReporter']

result = lint(file.name, options)


os.remove(file.name)
#!/usr/bin/env python3

# ungoogled-chromium: A Google Chromium variant for removing Google integration and
# enhancing privacy, control, and transparency
# Copyright (C) 2016  Eloston
#
# This file is part of ungoogled-chromium.
#
# ungoogled-chromium 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 3 of the License, or
# (at your option) any later version.
#
# ungoogled-chromium 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 ungoogled-chromium.  If not, see <http://www.gnu.org/licenses/>.

if __name__ == "__main__":
    from pylint import epylint as lint

    lint.lint(filename="buildlib",
              options=[
                  "--disable=logging-format-interpolation", "--disable=fixme",
                  "--ignore=_external"
              ])
Exemple #14
0
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-

if __name__ == "__main__":
    from pylint import epylint as lint

    lint.lint(filename="autozlap",
              options=["--disable=logging-format-interpolation",
                       "--disable=fixme",
                       "--disable=locally-disabled",
                       "--ignore=_external"])
Exemple #15
0
#!/usr/bin/python
# -*- coding: UTF-8 -*-

from pylint.epylint import lint
import os
import tempfile
import cgi
import cgitb

cgitb.enable()
form = cgi.FieldStorage()
file = tempfile.NamedTemporaryFile(delete=False)
file.write(form.getfirst("code"))
file.close()

print '''Content-type: text/html

'''

options = ['--reports', 'no', '--output-format', 'JSONReporter']

result = lint(file.name, options)

os.remove(file.name)
Exemple #16
0
 def test_linting(self):
     paths = ['friskby', 'tests']
     files = self._get_lintable_files(paths)
     for f in files:
         self.assertEqual(0, lint.lint(f), 'Linting required for %s' % f)
Exemple #17
0
#!/usr/bin/env python3

# Copyright (c) 2017 The ungoogled-chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

if __name__ == "__main__":
    from pylint import epylint as lint

    lint.lint(filename="mix_splitter.py",
              options=["--disable=logging-format-interpolation",
                       "--disable=locally-disabled"])
Exemple #18
0
    for namext in filenames:
        name, ext = os.path.splitext(namext)
        if ext != '.py':
            continue
        if name in exclude:
            continue
        fullname = os.path.join(path, namext)
        print fullname
        epylint.lint(fullname, [
            '--ignored-modules=pygame,numpy,pygame.mixer',
            '--ignored-classes=Serial,pygame.Surface', '--errors-only'
        ])


basedir = os.path.join('..', 'pcbasic')

args = sys.argv[1:]
if not args or args == ['--all']:
    exclude = ['example', 'video_pygame']

    for path, _, filenames in os.walk(basedir):
        lint_files(path, filenames, exclude)
        epylint.lint(os.path.join(basedir, 'interface', 'video_pygame.py'), [
            '--ignored-modules=pygame,numpy,pygame.mixer',
            '--ignored-classes=Serial,pygame.Surface', '--errors-only',
            '--disable=too-many-function-args,unexpected-keyword-arg'
        ])

else:
    lint_files(basedir, args)
Exemple #19
0
 def test_linting(self):
     files = self._get_lintable_files('rpiparticle')
     files = files + self._get_lintable_files('tests')
     for f in files:
         self.assertEqual(lint.lint(f), 0, 'pylint failed')
Exemple #20
0
#!/usr/bin/env python3

# Copyright (c) 2017 The ungoogled-chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

if __name__ == "__main__":
    from pylint import epylint as lint
    import pathlib

    lint.lint(filename=str(
        pathlib.Path(__file__).parent / "gnome_proxy_overrider.py"),
              options=[
                  "--disable=logging-format-interpolation",
                  "--disable=locally-disabled"
              ])
#!/usr/bin/env python3

# Copyright (c) 2017 The ungoogled-chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

if __name__ == "__main__":
    from pylint import epylint as lint
    import pathlib

    lint.lint(filename=str(pathlib.Path(__file__).parent.parent / "utilikit"),
              options=[
                  "--disable=logging-format-interpolation",
                  "--disable=locally-disabled"
              ])
Exemple #22
0
from pylint import epylint
import os
import sys


def lint_files(path, filenames, exclude=[]):
    for namext in filenames:
        name, ext = os.path.splitext(namext)
        if ext != '.py':
            continue
        if name in exclude:
            continue
        fullname = os.path.join(path, namext)
        print fullname
        epylint.lint(fullname, ['--ignored-modules=pygame,numpy,pygame.mixer', '--ignored-classes=Serial,pygame.Surface', '--errors-only'])


basedir = os.path.join('..', 'pcbasic')

args = sys.argv[1:]
if not args or args == ['--all']:
    exclude = ['example', 'video_pygame']

    for path, _, filenames in os.walk(basedir):
        lint_files(path, filenames, exclude)
        epylint.lint(os.path.join(basedir, 'interface', 'video_pygame.py'),
            ['--ignored-modules=pygame,numpy,pygame.mixer', '--ignored-classes=Serial,pygame.Surface', '--errors-only', '--disable=too-many-function-args,unexpected-keyword-arg'])

else:
    lint_files(basedir, args)
#!/usr/bin/env python3

# Copyright (c) 2017 The ungoogled-chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

if __name__ == "__main__":
    from pylint import epylint as lint
    import pathlib

    lint.lint(filename=str(pathlib.Path(__file__).parent.parent / "utilikit"),
              options=["--disable=logging-format-interpolation",
                       "--disable=locally-disabled"])
Exemple #24
0
#!/usr/bin/env python3

# ungoogled-chromium: Google Chromium patches for removing Google integration, enhancing privacy,
# and adding features
# Copyright (C) 2016  Eloston
#
# This file is part of ungoogled-chromium.
#
# ungoogled-chromium 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 3 of the License, or
# (at your option) any later version.
#
# ungoogled-chromium 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 ungoogled-chromium.  If not, see <http://www.gnu.org/licenses/>.

if __name__ == "__main__":
    from pylint import epylint as lint

    lint.lint(filename="buildlib.py",
              options=["--disable=logging-format-interpolation",
                       "--disable=fixme"])
Exemple #25
0
 def test_linting(self):
     files = self._get_lintable_files('friskby_controlpanel')
     files = files + self._get_lintable_files('tests')
     files.append('bin/fby_init')
     for f in files:
         self.assertEqual(lint.lint(f), 0, 'linting required for %s' % f)