Ejemplo n.º 1
0
    def run(self, edit):
        """
        Run flake8 lint.
        """
        # current file name
        filename = os.path.abspath(self.view.file_name())

        # check if active view contains file
        if not filename:
            return

        # check only Python files
        if not self.view.match_selector(0, 'source.python'):
            return

        # save file if dirty
        if self.view.is_dirty():
            self.view.run_command('save')

        # try to get interpreter
        interpreter = settings.get('python_interpreter', 'auto')

        if not interpreter or interpreter == 'internal':
            # if interpreter is Sublime Text 2 internal python - lint file
            self.errors_list = lint(filename, settings)
        else:
            # else - check interpreter
            if interpreter == 'auto':
                interpreter = 'python'
            elif not os.path.exists(interpreter):
                sublime.error_message(
                    "Python Flake8 Lint error:\n"
                    "python interpreter '%s' is not found" % interpreter
                )

            # TODO: correct linter path handle
            # build linter path for Packages Manager installation
            linter = os.path.join(
                sublime.packages_path(), 'Python Flake8 Lint', 'lint.py')

            # build linter path for installation from git
            if not os.path.exists(linter):
                linter = os.path.join(
                    sublime.packages_path(), 'Flake8Lint', 'lint.py')

            if not os.path.exists(linter):
                sublime.error_message(
                    "Python Flake8 Lint error:\n"
                    "sorry, can't find correct plugin path"
                )

            # and lint file in subprocess
            self.errors_list = lint_external(filename, settings,
                                             interpreter, linter)

        # show errors
        if self.errors_list:
            self.show_errors()
Ejemplo n.º 2
0
    def run(self, edit):
        """
        Run flake8 lint.
        """
        # current file name
        filename = os.path.abspath(self.view.file_name())

        # check if active view contains file
        if not filename:
            return

        # check only Python files
        if not self.view.match_selector(0, "source.python"):
            return

        # we need to always clear regions. three situations here:
        # - we need to clear regions with fixed previous errors
        # - is user will turn off 'highlight' in settings and then run lint
        # - user adds file with errors to 'ignore_files' list
        self.view.erase_regions("flake8-errors")

        # we need to always erase status too. same situations.
        self.view.erase_status("flake8-tip")

        # skip files by mask
        ignore_files = settings.get("ignore_files")
        if ignore_files:
            basename = os.path.basename(filename)
            try:
                if any(fnmatch(basename, mask) for mask in ignore_files):
                    return
            except (TypeError, ValueError):
                sublime.error_message("Python Flake8 Lint error:\n" "'ignore_files' option is not a list of file masks")

        # save file if dirty
        if self.view.is_dirty():
            self.view.run_command("save")

        # try to get interpreter
        interpreter = settings.get("python_interpreter", "auto")

        if not interpreter or interpreter == "internal":
            # if interpreter is Sublime Text 2 internal python - lint file
            self.errors_list = lint(filename, settings)
        else:
            # else - check interpreter
            if interpreter == "auto":
                if os.name == "nt":
                    interpreter = "pythonw"
                else:
                    interpreter = "python"
            elif not os.path.exists(interpreter):
                sublime.error_message(
                    "Python Flake8 Lint error:\n" "python interpreter '%s' is not found" % interpreter
                )

            # build linter path for Packages Manager installation
            linter = os.path.join(FLAKE_DIR, "lint.py")

            # build linter path for installation from git
            if not os.path.exists(linter):
                linter = os.path.join(sublime.packages_path(), "Flake8Lint", "lint.py")

            if not os.path.exists(linter):
                sublime.error_message("Python Flake8 Lint error:\n" "sorry, can't find correct plugin path")

            # and lint file in subprocess
            self.errors_list = lint_external(filename, settings, interpreter, linter)

        # show errors
        if self.errors_list:
            self.show_errors()
Ejemplo n.º 3
0
    def async_lint(view, view_settings, quiet=False):
        """
        Do view lint asynchronously.
        """
        # try to get interpreter
        interpreter = view_settings.get('python_interpreter', 'auto')
        log("python interpreter: {0}".format(interpreter))

        lines = view.substr(sublime.Region(0, view.size()))

        # skip file check if 'noqa' for whole file is set
        if FLAKE8_NOQA(lines) is not None:
            log("skip file: 'noqa' is set")
            Flake8Lint.cleanup(view)
            return

        start_time = time.time()
        if not interpreter or interpreter == 'internal':
            # if interpreter is Sublime Text internal python - lint file
            log("interpreter is internal")
            errors_list = lint(lines, view_settings)
        else:
            # else - check interpreter
            log("interpreter is external")
            if interpreter == 'auto':
                if os.name == 'nt':
                    interpreter = 'pythonw'
                else:
                    interpreter = 'python'
                log("guess interpreter: '{0}'".format(interpreter))
            elif not os.path.exists(interpreter):
                sublime.error_message(
                    "Python Flake8 Lint error:\n"
                    "python interpreter '%s' is not found" % interpreter
                )

            # build linter path for Packages Manager installation
            linter = os.path.join(PLUGIN_DIR, 'lint.py')
            log("linter file: {0}".format(linter))

            # build linter path for installation from git
            if not os.path.exists(linter):
                linter = os.path.join(
                    sublime.packages_path(), 'Python Flake8 Lint', 'lint.py')
                log("linter is not exists, try this: {0}".format(linter))

            if not os.path.exists(linter):
                sublime.error_message(
                    "Python Flake8 Lint error:\n"
                    "sorry, can't find correct plugin path"
                )

            # and lint file in subprocess
            log("interpreter is external")
            errors_list = lint_external(lines, view_settings,
                                        interpreter, linter)

        if not errors_list:
            errors_list = []

        lint_time = time.time() - start_time
        log("lint time: {0:.3f}ms".format(lint_time))
        log("lint errors found: {0}".format(len(errors_list)))

        # clean regions and statusbar
        Flake8Lint.cleanup(view)
        # show errors
        LintReport(view, errors_list, view_settings, quiet=quiet)
Ejemplo n.º 4
0
    def run(self, edit):
        """
        Run flake8 lint.
        """
        # current file name
        filename = os.path.abspath(self.view.file_name())

        # check if active view contains file
        if not filename:
            return

        # check only Python files
        if not self.view.match_selector(0, 'source.python'):
            return

        # we need to always clear regions. three situations here:
        # - we need to clear regions with fixed previous errors
        # - is user will turn off 'highlight' in settings and then run lint
        # - user adds file with errors to 'ignore_files' list
        self.view.erase_regions('flake8-errors')

        # we need to always erase status too. same situations.
        self.view.erase_status('flake8-tip')

        # skip files by mask
        ignore_files = settings.get('ignore_files')
        if ignore_files:
            basename = os.path.basename(filename)
            try:
                if any(fnmatch(basename, mask) for mask in ignore_files):
                    return
            except (TypeError, ValueError):
                sublime.error_message(
                    "Python Flake8 Lint error:\n"
                    "'ignore_files' option is not a list of file masks"
                )

        # save file if dirty
        if self.view.is_dirty():
            self.view.run_command('save')

        # try to get interpreter
        interpreter = settings.get('python_interpreter', 'auto')

        if not interpreter or interpreter == 'internal':
            # if interpreter is Sublime Text 2 internal python - lint file
            self.errors_list = lint(filename, settings)
        else:
            # else - check interpreter
            if interpreter == 'auto':
                if os.name == 'nt':
                    interpreter = 'pythonw'
                else:
                    interpreter = 'python'
            elif not os.path.exists(interpreter):
                sublime.error_message(
                    "Python Flake8 Lint error:\n"
                    "python interpreter '%s' is not found" % interpreter
                )

            # build linter path for Packages Manager installation
            linter = os.path.join(FLAKE_DIR, 'lint.py')

            # build linter path for installation from git
            if not os.path.exists(linter):
                linter = os.path.join(
                    sublime.packages_path(), 'Flake8Lint', 'lint.py')

            if not os.path.exists(linter):
                sublime.error_message(
                    "Python Flake8 Lint error:\n"
                    "sorry, can't find correct plugin path"
                )

            # and lint file in subprocess
            self.errors_list = lint_external(filename, settings,
                                             interpreter, linter)

        # show errors
        if self.errors_list:
            self.show_errors()
Ejemplo n.º 5
0
    def async_lint(view, view_settings, quiet=False):
        """
        Do view lint asynchronously.
        """
        # try to get interpreter
        interpreter = view_settings.get('python_interpreter', 'auto')
        log("python interpreter: {0}".format(interpreter))

        lines = view.substr(sublime.Region(0, view.size()))

        # skip file check if 'noqa' for whole file is set
        if FLAKE8_NOQA(lines) is not None:
            log("skip file: 'noqa' is set")
            Flake8Lint.cleanup(view)
            return

        start_time = time.time()
        if not interpreter or interpreter == 'internal':
            # if interpreter is Sublime Text internal python - lint file
            log("interpreter is internal")
            errors_list = lint(lines, view_settings)
        else:
            # else - check interpreter
            log("interpreter is external")
            if interpreter == 'auto':
                if os.name == 'nt':
                    interpreter = 'pythonw'
                else:
                    interpreter = 'python'
                log("guess interpreter: '{0}'".format(interpreter))
            elif not os.path.exists(interpreter):
                sublime.error_message(
                    "Python Flake8 Lint error:\n"
                    "python interpreter '%s' is not found" % interpreter
                )

            # build linter path for Packages Manager installation
            linter = os.path.join(PLUGIN_DIR, 'lint.py')
            log("linter file: {0}".format(linter))

            # build linter path for installation from git
            if not os.path.exists(linter):
                linter = os.path.join(
                    sublime.packages_path(), 'Python Flake8 Lint', 'lint.py')
                log("linter is not exists, try this: {0}".format(linter))

            if not os.path.exists(linter):
                sublime.error_message(
                    "Python Flake8 Lint error:\n"
                    "sorry, can't find correct plugin path"
                )

            # and lint file in subprocess
            log("interpreter is external")
            errors_list = lint_external(lines, view_settings,
                                        interpreter, linter)

        if not errors_list:
            errors_list = []

        lint_time = time.time() - start_time
        log("lint time: {0:.3f}ms".format(lint_time))
        log("lint errors found: {0}".format(len(errors_list)))

        # clean regions and statusbar
        Flake8Lint.cleanup(view)
        # show errors
        LintReport(view, errors_list, view_settings, quiet=quiet)
Ejemplo n.º 6
0
    def run(self, edit):
        """
        Run flake8 lint.
        """
        debug("run flake8 lint")
        # check if active view contains file
        filename = self.view.file_name()
        if not filename:
            debug("skip view: filename is empty")
            return

        filename = os.path.abspath(filename)

        # check only Python files
        if not self.view.match_selector(0, 'source.python'):
            debug("skip file: view source type is not 'python'")
            return

        # skip file check if 'noqa' for whole file is set
        if skip_file(filename):
            debug("skip file: 'noqa' is set")
            return

        # we need to always clear regions. three situations here:
        # - we need to clear regions with fixed previous errors
        # - is user will turn off 'highlight' in settings and then run lint
        # - user adds file with errors to 'ignore_files' list
        self.view.erase_regions('flake8-errors')

        # we need to always erase status too. same situations.
        self.view.erase_status('flake8-tip')

        # get view settings
        view_settings = get_view_settings(self.view)

        # skip files by pattern
        patterns = view_settings.get('ignore_files')
        debug("ignore file patterns: {0}".format(patterns))
        if patterns:
            # add file basename to check list
            paths = [os.path.basename(filename)]

            # add file relative paths to check list
            for folder in sublime.active_window().folders():
                folder_name = folder.rstrip(os.path.sep) + os.path.sep
                if filename.startswith(folder_name):
                    paths.append(filename[len(folder_name):])

            try:
                if any(filename_match(path, patterns) for path in set(paths)):
                    message = "File '{0}' lint was skipped by 'ignore' setting"
                    print(message.format(filename))
                    return
            except (TypeError, ValueError):
                sublime.error_message(
                    "Python Flake8 Lint error:\n"
                    "'ignore_files' option is not a list of file masks"
                )

        # save file if dirty
        if self.view.is_dirty():
            debug("save file before lint, because view is 'dirty'")
            self.view.run_command('save')

        # try to get interpreter
        interpreter = view_settings.get('python_interpreter', 'auto')
        debug("python interpreter: {0}".format(interpreter))

        if not interpreter or interpreter == 'internal':
            # if interpreter is Sublime Text 2 internal python - lint file
            debug("interpreter is internal")
            self.errors_list = lint(filename, view_settings)
        else:
            # else - check interpreter
            debug("interpreter is external")
            if interpreter == 'auto':
                if os.name == 'nt':
                    interpreter = 'pythonw'
                else:
                    interpreter = 'python'
                debug("guess interpreter: '{0}'".format(interpreter))
            elif not os.path.exists(interpreter):
                sublime.error_message(
                    "Python Flake8 Lint error:\n"
                    "python interpreter '%s' is not found" % interpreter
                )

            # build linter path for Packages Manager installation
            linter = os.path.join(FLAKE_DIR, 'lint.py')
            debug("linter file: {0}".format(linter))

            # build linter path for installation from git
            if not os.path.exists(linter):
                linter = os.path.join(
                    sublime.packages_path(), 'Python Flake8 Lint', 'lint.py')
                debug("linter is not exists, try this: {0}".format(linter))

            if not os.path.exists(linter):
                sublime.error_message(
                    "Python Flake8 Lint error:\n"
                    "sorry, can't find correct plugin path"
                )

            # and lint file in subprocess
            debug("interpreter is external")
            self.errors_list = lint_external(filename, view_settings,
                                             interpreter, linter)

        debug("lint errors found: {0}".format(len(self.errors_list)))
        # show errors
        if self.errors_list:
            self.show_errors(view_settings)
        elif settings.get('report_on_success', False):
            sublime.message_dialog('Flake8 Lint: SUCCESS')
Ejemplo n.º 7
0
    def run(self, edit):
        """
        Run flake8 lint.
        """
        # check if active view contains file
        filename = self.view.file_name()
        if not filename:
            return

        filename = os.path.abspath(filename)

        # check only Python files
        if not self.view.match_selector(0, 'source.python'):
            return

        # skip file check if 'noqa' for whole file is set
        if skip_file(filename):
            return

        # we need to always clear regions. three situations here:
        # - we need to clear regions with fixed previous errors
        # - is user will turn off 'highlight' in settings and then run lint
        # - user adds file with errors to 'ignore_files' list
        self.view.erase_regions('flake8-errors')

        # we need to always erase status too. same situations.
        self.view.erase_status('flake8-tip')

        # skip files by mask
        ignore_files = settings.get('ignore_files')
        if ignore_files:
            basename = os.path.basename(filename)
            try:
                if any(fnmatch(basename, mask) for mask in ignore_files):
                    return
            except (TypeError, ValueError):
                sublime.error_message(
                    "Python Flake8 Lint error:\n"
                    "'ignore_files' option is not a list of file masks"
                )

        # save file if dirty
        if self.view.is_dirty():
            self.view.run_command('save')

        # try to get interpreter
        interpreter = settings.get('python_interpreter', 'auto')

        if not interpreter or interpreter == 'internal':
            # if interpreter is Sublime Text 2 internal python - lint file
            self.errors_list = lint(filename, settings)
        else:
            # else - check interpreter
            if interpreter == 'auto':
                if os.name == 'nt':
                    interpreter = 'pythonw'
                else:
                    interpreter = 'python'
            elif not os.path.exists(interpreter):
                sublime.error_message(
                    "Python Flake8 Lint error:\n"
                    "python interpreter '%s' is not found" % interpreter
                )

            # build linter path for Packages Manager installation
            linter = os.path.join(FLAKE_DIR, 'lint.py')

            # build linter path for installation from git
            if not os.path.exists(linter):
                linter = os.path.join(
                    sublime.packages_path(), 'Python Flake8 Lint', 'lint.py')

            if not os.path.exists(linter):
                sublime.error_message(
                    "Python Flake8 Lint error:\n"
                    "sorry, can't find correct plugin path"
                )

            # and lint file in subprocess
            self.errors_list = lint_external(filename, settings,
                                             interpreter, linter)

        # show errors
        if self.errors_list:
            self.show_errors()
        elif settings.get('report_on_success', False):
            sublime.message_dialog('Flake8 Lint: SUCCESS')
Ejemplo n.º 8
0
    def run(self, edit):
        """
        Run flake8 lint.
        """
        # current file name
        filename = os.path.abspath(self.view.file_name())

        # check if active view contains file
        if not filename:
            return

        # check only Python files
        if not self.view.match_selector(0, 'source.python'):
            return

        # save file if dirty
        if self.view.is_dirty():
            self.view.run_command('save')

        # try to get interpreter
        interpreter = settings.get('python_interpreter', 'auto')

        if not interpreter or interpreter == 'internal':
            # if interpreter is Sublime Text 2 internal python - lint file
            self.errors_list = lint(filename, settings)
        else:
            # else - check interpreter
            if interpreter == 'auto':
                interpreter = 'python'
            elif not os.path.exists(interpreter):
                sublime.error_message(
                    "Python Flake8 Lint error:\n"
                    "python interpreter '%s' is not found" % interpreter
                )

            # build linter path for Packages Manager installation
            linter = os.path.join(FLAKE_DIR, 'lint.py')

            # build linter path for installation from git
            if not os.path.exists(linter):
                linter = os.path.join(
                    sublime.packages_path(), 'Flake8Lint', 'lint.py')

            if not os.path.exists(linter):
                sublime.error_message(
                    "Python Flake8 Lint error:\n"
                    "sorry, can't find correct plugin path"
                )

            # and lint file in subprocess
            self.errors_list = lint_external(filename, settings,
                                             interpreter, linter)

        # we need to always clear regions. two situations here:
        # - we need to clear regions with fixed previous errors
        # - is user will turn off 'highlight' in settings and then run lint
        self.view.erase_regions('flake8-errors')

        # we need to always erase status too. same situations.
        self.view.erase_status('flake8-tip')

        # show errors
        if self.errors_list:
            self.show_errors()
Ejemplo n.º 9
0
    def run(self, edit):
        """
        Run flake8 lint.
        """
        debug("run flake8 lint")
        # check if active view contains file
        filename = self.view.file_name()
        if not filename:
            debug("skip view: filename is empty")
            return

        filename = os.path.abspath(filename)

        # check only Python files
        if not self.view.match_selector(0, 'source.python'):
            debug("skip file: view source type is not 'python'")
            return

        # skip file check if 'noqa' for whole file is set
        if skip_file(filename):
            debug("skip file: 'noqa' is set")
            return

        # we need to always clear regions. three situations here:
        # - we need to clear regions with fixed previous errors
        # - is user will turn off 'highlight' in settings and then run lint
        # - user adds file with errors to 'ignore_files' list
        self.view.erase_regions('flake8-errors')

        # we need to always erase status too. same situations.
        self.view.erase_status('flake8-tip')

        # get view settings
        view_settings = get_view_settings(self.view)

        # skip files by pattern
        patterns = view_settings.get('ignore_files')
        debug("ignore file patterns: {0}".format(patterns))
        if patterns:
            # add file basename to check list
            paths = [os.path.basename(filename)]

            # add file relative paths to check list
            for folder in sublime.active_window().folders():
                folder_name = folder.rstrip(os.path.sep) + os.path.sep
                if filename.startswith(folder_name):
                    paths.append(filename[len(folder_name):])

            try:
                if any(filename_match(path, patterns) for path in set(paths)):
                    message = "File '{0}' lint was skipped by 'ignore' setting"
                    print(message.format(filename))
                    return
            except (TypeError, ValueError):
                sublime.error_message(
                    "Python Flake8 Lint error:\n"
                    "'ignore_files' option is not a list of file masks"
                )

        # save file if dirty
        if self.view.is_dirty():
            debug("save file before lint, because view is 'dirty'")
            self.view.run_command('save')

        # try to get interpreter
        interpreter = view_settings.get('python_interpreter', 'auto')
        debug("python interpreter: {0}".format(interpreter))

        if not interpreter or interpreter == 'internal':
            # if interpreter is Sublime Text 2 internal python - lint file
            debug("interpreter is internal")
            self.errors_list = lint(filename, view_settings)
        else:
            # else - check interpreter
            debug("interpreter is external")
            if interpreter == 'auto':
                if os.name == 'nt':
                    interpreter = 'pythonw'
                else:
                    interpreter = 'python'
                debug("guess interpreter: '{0}'".format(interpreter))
            elif not os.path.exists(interpreter):
                sublime.error_message(
                    "Python Flake8 Lint error:\n"
                    "python interpreter '%s' is not found" % interpreter
                )

            # build linter path for Packages Manager installation
            linter = os.path.join(FLAKE_DIR, 'lint.py')
            debug("linter file: {0}".format(linter))

            # build linter path for installation from git
            if not os.path.exists(linter):
                linter = os.path.join(
                    sublime.packages_path(), 'Python Flake8 Lint', 'lint.py')
                debug("linter is not exists, try this: {0}".format(linter))

            if not os.path.exists(linter):
                sublime.error_message(
                    "Python Flake8 Lint error:\n"
                    "sorry, can't find correct plugin path"
                )

            # and lint file in subprocess
            debug("interpreter is external")
            self.errors_list = lint_external(filename, view_settings,
                                             interpreter, linter)

        debug("lint errors found: {0}".format(len(self.errors_list)))
        # show errors
        if self.errors_list:
            self.show_errors(view_settings)
        elif settings.get('report_on_success', False):
            sublime.message_dialog('Flake8 Lint: SUCCESS')