How to use pyflakes - 10 common examples

To help you get started, we’ve selected a few pyflakes examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ros-infrastructure / ros_buildfarm / test / test_pyflakes.py View on Github external
def test_pyflakes_conformance():
    """Test source code for PyFlakes conformance."""
    reporter = Reporter(sys.stdout, sys.stderr)
    base_path = os.path.join(os.path.dirname(__file__), '..')
    paths = [
        os.path.join(base_path, 'ros_buildfarm'),
        os.path.join(base_path, 'scripts'),
    ]
    warning_count = checkRecursive(paths, reporter)
    assert warning_count == 0, \
        'Found %d code style warnings' % warning_count
github qutech / qupulse / tests / pyflakes_syntax_tests.py View on Github external
def test_pyflakes_syntax(self) -> None:
        rootPath = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
        pyflakes.api.checkRecursive([rootPath + '/qupulse/', rootPath + '/tests/'], Reporter(sys.stdout, sys.stderr))
github ethanchewy / PythonBuddy / old_code / test_pyflakes.py View on Github external
def check(text):
	pyflakes.api.check(text,"test.py")
github jtriley / StarCluster / check.py View on Github external
else:
            line = text.splitlines()[-1]

            if offset is not None:
                offset = offset - (len(text) - len(line))

            print >> sys.stderr, '%s:%d: %s' % (filename, lineno, msg)
            print >> sys.stderr, line

            if offset is not None:
                print >> sys.stderr, " " * offset, "^"

        return 1
    else:
        # Okay, it's syntactically valid.  Now check it.
        w = checker.Checker(tree, filename)
        lines = codeString.split('\n')
        messages = [message for message in w.messages
                    if lines[message.lineno - 1].find('pyflakes:ignore') < 0]
        messages.sort(lambda a, b: cmp(a.lineno, b.lineno))
        for warning in messages:
            print warning
        return len(messages)
github django-guardian / django-guardian / extras.py View on Github external
# If there's an encoding problem with the file, the text is None.
        if text is None:
            # Avoid using msg, since for the only known case, it contains a
            # bogus message that claims the encoding the file declared was
            # unknown.
            reporter.unexpectedError(filename, 'problem decoding source')
        else:
            reporter.syntaxError(filename, msg, lineno, offset, text)
        return 1
    except Exception:
        reporter.unexpectedError(filename, 'problem decoding source')
        return 1
    else:
        # Okay, it's syntactically valid.  Now check it.
        lines = codeString.splitlines()
        warnings = Checker(tree, filename)
        warnings.messages.sort(key=lambda m: m.lineno)
        real_messages = []
        for m in warnings.messages:
            line = lines[m.lineno - 1]
            if 'pyflakes:ignore' in line.rsplit('#', 1)[-1]:
                # ignore lines with pyflakes:ignore
                pass
            else:
                real_messages.append(m)
                reporter.flake(m)
        return len(real_messages)
github pylava / pylava / pylama / lint / pylama_pyflakes / __init__.py View on Github external
def run(path, code=None, params=None, **meta):
        """ Pyflake code checking.

        :return list: List of errors.

        """
        import _ast

        builtins = params.get("builtins", "")

        if builtins:
            builtins = builtins.split(",")

        errors = []
        tree = compile(code, path, "exec", _ast.PyCF_ONLY_AST)
        w = checker.Checker(tree, path, builtins=builtins)
        w.messages = sorted(w.messages, key=lambda m: m.lineno)
        for w in w.messages:
            errors.append(dict(
                lnum=w.lineno,
                text=w.message % w.message_args,
            ))
        return errors
github jmwright / cadquery-freecad-module / Libs / pyqode / python / backend / workers.py View on Github external
_ast.PyCF_ONLY_AST)
        except SyntaxError as value:
            msg = '[pyFlakes] %s' % value.args[0]
            (lineno, offset, text) = value.lineno - 1, value.offset, value.text
            # If there's an encoding problem with the file, the text is None
            if text is None:
                # Avoid using msg, since for the only known case, it
                # contains a bogus message that claims the encoding the
                # file declared was unknown.s
                _logger().warning("[SyntaxError] %s: problem decoding source",
                                  path)
            else:
                ret_val.append((msg, ERROR, lineno))
        else:
            # Okay, it's syntactically valid.  Now check it.
            w = checker.Checker(tree, os.path.split(path)[1])
            w.messages.sort(key=lambda m: m.lineno)
            for message in w.messages:
                msg = "[pyFlakes] %s" % str(message).split(':')[-1].strip()
                line = message.lineno - 1
                status = WARNING \
                    if message.__class__ not in PYFLAKES_ERROR_MESSAGES \
                    else ERROR
                ret_val.append((msg, status, line))
    prev_results = ret_val
    return ret_val
github nathan-v / aws_okta_keyman / setup.py View on Github external
def run(self):
        """Execute pyflakes check."""
        # Don't import the pyflakes code until now because setup.py needs to be
        # able to install Pyflakes if its missing. This localizes the import to
        # only after the setuptools code has run and verified everything is
        # installed.
        from pyflakes import api
        from pyflakes import reporter

        # Run the Pyflakes check against our package and check its output
        val = api.checkRecursive([PACKAGE], reporter._makeDefaultReporter())
        if val > 0:
            sys.exit("ERROR: Pyflakes failed with exit code {}".format(val))
github Nextdoor / kingpin / setup.py View on Github external
def run(self):
        # Don't import the pyflakes code until now because setup.py needs to be
        # able to install Pyflakes if its missing. This localizes the import to
        # only after the setuptools code has run and verified everything is
        # installed.
        from pyflakes import api
        from pyflakes import reporter

        # Run the Pyflakes check against our package and check its output
        val = api.checkRecursive([PACKAGE], reporter._makeDefaultReporter())
        if val > 0:
            sys.exit('ERROR: Pyflakes failed with exit code %d' % val)
github QQuick / Transcrypt / xtranscrypt / modules / org / transcrypt / static_check / pyflakes / pyflakes / api.py View on Github external
def main(prog=None):
    """Entry point for the script "pyflakes"."""
    import optparse

    # Handle "Keyboard Interrupt" and "Broken pipe" gracefully
    _exitOnSignal('SIGINT', '... stopped')
    _exitOnSignal('SIGPIPE', 1)

    parser = optparse.OptionParser(prog=prog, version=__version__)
    (__, args) = parser.parse_args()
    reporter = modReporter._makeDefaultReporter()
    if args:
        warnings = checkRecursive(args, reporter)
    else:
        warnings = check(sys.stdin.read(), '', reporter)
    raise SystemExit(warnings > 0)