Example #1
0
    def show_docstring(self):
        if not self.app.environment:
            return

        cursor = self.app.cursor
        if not cursor:
            return

        items = self.app.script.goto(
            line=cursor.row,
            column=cursor.x)

        if items:
            text = items[0].docstring()
        else:
            return

        if text:
            ct.app_log(ct.LOG_CLEAR, '', panel=ct.LOG_PANEL_OUTPUT)
            for s in text.splitlines():
                ct.app_log(ct.LOG_ADD, s, panel=ct.LOG_PANEL_OUTPUT)

            ct.ed.cmd(cmds.cmd_ShowPanelOutput)
            ct.ed.focus()
        else:
            ct.msg_status('Cannot find doc-string')
    def execCurrentFileAsPlugin(self):
        fn  = ed.get_filename()
        if not fn.endswith('.py'):
            return app.msg_status(_('Fail. Use only for python file.'))
        ed.save()
        app.app_log(app.LOG_CONSOLE_CLEAR, 'm')
        cmd = r'exec(open(r"{fn}", encoding="UTF-8").read().lstrip("\uFEFF"))'
#       cmd = f(r'exec(open(r"{}", encoding="UTF-8").read().lstrip("\uFEFF"))', fn)
        pass;                  #log('cmd={!r}',(cmd))
        ans     = app.app_proc(app.PROC_EXEC_PYTHON, cmd)
        print('>>> run {!r}'.format(fn))
        print(ans)
Example #3
0
 def show_docstring(self):
     cursor = self.get_cursor()
     if not cursor:
         return
     word, _ = self.get_word_under_cursor(*cursor)
     if not word:
         return
     with open(self.api_file, encoding='utf-8') as f:
         for line in f:
             if line.lower().find(word.lower()) == 0:
                 if '/a>' in line:
                     start = line.find('<a')
                     end = line.find('/a>') + 3
                     line = line[:start] + line[end:]
                 ct.app_log(ct.LOG_CLEAR, '', panel=ct.LOG_PANEL_OUTPUT)
                 ct.app_log(ct.LOG_ADD, line, panel=ct.LOG_PANEL_OUTPUT)
                 ct.ed.cmd(ct_cmd.cmd_ShowPanelOutput)
                 ct.ed.focus()
                 return True
     ct.msg_status('Cannot find doc-string')
Example #4
0
 def clear_valid_pan(self):
     # clear Valid pane
     # app.app_log(app.LOG_SET_PANEL, app.LOG_PANEL_VALIDATE)
     app.app_log(app.LOG_CLEAR, '', panel=app.LOG_PANEL_VALIDATE)
Example #5
0
 def clear_valid_pan(self):
     app.app_log(app.LOG_CLEAR, '', panel=app.LOG_PANEL_VALIDATE)
Example #6
0
    def lint(self):
        """
        Perform the lint, retrieve the results, and add marks to the view.

        The flow of control is as follows:

        - Get the command line. If it is an empty string, bail.
        - Run the linter.
        - If the view has been modified since the original hit_time, stop.
        - Parse the linter output with the regex.
        - Highlight warnings and errors.

        """

        error_count = 0

        if self.filename:
            cwd = os.getcwd()
            os.chdir(os.path.dirname(self.filename))

        if self.cmd is None:
            cmd = None
        else:
            settings = {}
            args_map = {}
            if not self.defaults is None:
                for name, value in self.defaults.items():
                    match = ARG_RE.match(name)

                    if match:
                        name = match.group('name')
                        args_map[name] = match.groupdict()

                    settings[name] = value

            args = list()
            for setting, arg_info in args_map.items():
                prefix = arg_info['prefix']

                if setting not in settings or setting[
                        0] == '@' or prefix is None:
                    continue

                values = settings[setting]

                if values is None:
                    continue
                elif isinstance(values, (list, tuple)):
                    if values:
                        # If the values can be passed as a single list, join them now
                        if arg_info['sep'] and not arg_info['multiple']:
                            values = [str(value) for value in values]
                            values = [arg_info['sep'].join(values)]
                    else:
                        continue
                elif isinstance(values, str):
                    if values:
                        values = [values]
                    else:
                        continue
                elif isinstance(values, Number):
                    if values is False:
                        continue
                    else:
                        values = [values]
                else:
                    # Unknown type
                    continue

                for value in values:
                    if prefix == '@':
                        args.append(str(value))
                    else:
                        arg = prefix + arg_info['name']
                        joiner = arg_info['joiner']

                        if joiner == '=':
                            args.append('{}={}'.format(arg, value))
                        elif joiner == ':':
                            args.append(arg)
                            args.append(str(value))

            if callable(self.cmd):
                cmd = self.cmd()
            else:
                cmd = self.cmd
            if isinstance(cmd, str):
                cmd = shlex.split(cmd)
            else:
                cmd = list(cmd)

            which = cmd[0]
            have_path, path = self.context_sensitive_executable_path(cmd)

            if have_path:
                # Returning None means the linter runs code internally
                if path == '<builtin>':
                    return 0
            elif which is None or self.executable_path is None:
                executable = ''

                if not callable(self.cmd):
                    if isinstance(self.cmd, (tuple, list)):
                        executable = (self.cmd or [''])[0]
                    elif isinstance(self.cmd, str):
                        executable = self.cmd

                if not executable and self.executable:
                    executable = self.executable

                if executable:
                    path = util.which(executable) or ''

                    if (path is None
                            or (isinstance(path,
                                           (tuple, list)) and None in path)):
                        path = ''
                else:
                    path = None
            elif self.executable_path:
                path = self.executable_path

                if isinstance(path, (list, tuple)) and None in path:
                    path = None
            else:
                path = util.which(which)

            if not path:
                print('ERROR: {} cannot locate \'{}\''.format(
                    self.name, which))
                return 0

            cmd[0:1] = util.convert_type(path, [])

            if '*' in cmd:
                i = cmd.index('*')

                if args:
                    cmd[i:i + 1] = args
                else:
                    cmd.pop(i)
            else:
                cmd += args

            if cmd is not None and not cmd:
                return 0

        output = self.run(cmd, self.view.get_text_all())

        self.view.bookmark(app.BOOKMARK_CLEAR_ALL, 0)
        if not output:
            return 0

        if self.filename:
            os.chdir(cwd)

        # app.app_log(app.LOG_SET_PANEL, app.LOG_PANEL_VALIDATE)
        app.app_log(app.LOG_CLEAR, '', panel=app.LOG_PANEL_VALIDATE)
        app.app_log(app.LOG_SET_FILENAME,
                    self.filename,
                    panel=app.LOG_PANEL_VALIDATE)
        app.app_log(app.LOG_SET_LINE_ID, '1', panel=app.LOG_PANEL_VALIDATE)
        app.app_log(app.LOG_SET_COL_ID, '2', panel=app.LOG_PANEL_VALIDATE)
        app.app_log(app.LOG_SET_ZEROBASE, '0', panel=app.LOG_PANEL_VALIDATE)
        app.app_log(app.LOG_SET_REGEX,
                    'Line (\d+) Col (\d+):.+',
                    panel=app.LOG_PANEL_VALIDATE)

        m = []
        error_list = self.find_errors(output)
        for match, line, col, error, warning, message, near in error_list:
            if match and message and line is not None:
                m.append((line, col, message, error, warning))

        error_count = 0
        if m:
            m = sorted(m, key=lambda m: m[0])
            bm = dict()
            for line, col, message, error, warning in m:
                if error:
                    bm_kind = KIND_ERROR
                elif warning:
                    bm_kind = KIND_WARN
                else:
                    if self.default_type == ERROR:
                        bm_kind = KIND_ERROR
                    elif self.default_type == WARNING:
                        bm_kind = KIND_WARN
                    else:
                        bm_kind = KIND_INFO

                if col is None:
                    col = 1
                app.app_log(app.LOG_ADD,
                            'Line {} Col {}: {}'.format(line, col, message),
                            panel=app.LOG_PANEL_VALIDATE)

                bm[line] = (line - 1, bm_kind, message)
                error_count += 1

            self.view.bookmark(app.BOOKMARK_CLEAR_ALL, 0)
            for line in bm:
                self.view.bookmark(app.BOOKMARK_SET, bm[line][0], bm[line][1],
                                   -1, bm[line][2])

        return error_count
    " Remove the key from the dict (if is) and return the dict. "
    if key in dct:
        del dct[key]
    return dct
   #def dispose

def likesint(what):     return isinstance(what, int)
def likesstr(what):     return isinstance(what, str)
def likeslist(what):    return isinstance(what, tuple) or isinstance(what, list)
def likesdict(what):    return isinstance(what, dict)
   
if __name__ == '__main__' :
    # To start the tests run in Console
    #   exec(open(path_to_the_file, encoding="UTF-8").read())

    app.app_log(app.LOG_CONSOLE_CLEAR, 'm')
    print('Start all tests')
    if -1==-1:
        print('Start tests: log')
        log('n={}',1.23)
        log('n,s¬=¶{}',(1.23, 'abc'))
        def my():
            log('a={}',1.23)
            def sub():
                log('###')
            class CMy:
                def meth(self):
                    log('###')
            sub()
            CMy().meth()
        my()
Example #8
0
    def lint(self):
        """
        Perform the lint, retrieve the results, and add marks to the view.

        The flow of control is as follows:

        - Get the command line. If it is an empty string, bail.
        - Run the linter.
        - If the view has been modified since the original hit_time, stop.
        - Parse the linter output with the regex.
        - Highlight warnings and errors.

        """

        error_count = 0

        if self.filename:
            cwd = os.getcwd()
            os.chdir(os.path.dirname(self.filename))

        if self.cmd is None:
            cmd = None
        else:
            settings = {}
            args_map = {}
            if not self.defaults is None:
                for name, value in self.defaults.items():
                    match = ARG_RE.match(name)

                    if match:
                        name = match.group('name')
                        args_map[name] = match.groupdict()

                    settings[name] = value

            args = list()
            for setting, arg_info in args_map.items():
                prefix = arg_info['prefix']

                if setting not in settings or setting[0] == '@' or prefix is None:
                    continue

                values = settings[setting]

                if values is None:
                    continue
                elif isinstance(values, (list, tuple)):
                    if values:
                        # If the values can be passed as a single list, join them now
                        if arg_info['sep'] and not arg_info['multiple']:
                            values = [str(value) for value in values]
                            values = [arg_info['sep'].join(values)]
                    else:
                        continue
                elif isinstance(values, str):
                    if values:
                        values = [values]
                    else:
                        continue
                elif isinstance(values, Number):
                    if values is False:
                        continue
                    else:
                        values = [values]
                else:
                    # Unknown type
                    continue

                for value in values:
                    if prefix == '@':
                        args.append(str(value))
                    else:
                        arg = prefix + arg_info['name']
                        joiner = arg_info['joiner']

                        if joiner == '=':
                            args.append('{}={}'.format(arg, value))
                        elif joiner == ':':
                            args.append(arg)
                            args.append(str(value))

            if callable(self.cmd):
                cmd = self.cmd()
            else:
                cmd = self.cmd
            if isinstance(cmd, str):
                cmd = shlex.split(cmd)
            else:
                cmd = list(cmd)

            which = cmd[0]
            have_path, path = self.context_sensitive_executable_path(cmd)

            if have_path:
                # Returning None means the linter runs code internally
                if path == '<builtin>':
                    return 0
            elif which is None or self.executable_path is None:
                executable = ''

                if not callable(self.cmd):
                    if isinstance(self.cmd, (tuple, list)):
                        executable = (self.cmd or [''])[0]
                    elif isinstance(self.cmd, str):
                        executable = self.cmd

                if not executable and self.executable:
                    executable = self.executable

                if executable:
                    path = util.which(executable) or ''

                    if (
                        path is None or
                        (isinstance(path, (tuple, list)) and None in path)
                    ):
                        path = ''
                else:
                    path = None
            elif self.executable_path:
                path = self.executable_path

                if isinstance(path, (list, tuple)) and None in path:
                    path = None
            else:
                path = util.which(which)

            if not path:
                print('ERROR: {} cannot locate \'{}\''.format(self.name, which))
                return 0

            cmd[0:1] = util.convert_type(path, [])

            if '*' in cmd:
                i = cmd.index('*')

                if args:
                    cmd[i:i + 1] = args
                else:
                    cmd.pop(i)
            else:
                cmd += args

            if cmd is not None and not cmd:
                return 0

        output = self.run(cmd, self.view.get_text_all())

        self.view.bookmark(app.BOOKMARK_DELETE_BY_TAG, 0, tag=MY_TAG)
        if not output:
            return 0

        if self.filename:
            os.chdir(cwd)

        app.app_log(app.LOG_CLEAR, '', panel=app.LOG_PANEL_VALIDATE)
        app.app_log(app.LOG_SET_FILENAME, self.filename, panel=app.LOG_PANEL_VALIDATE)
        app.app_log(app.LOG_SET_LINE_ID, '1', panel=app.LOG_PANEL_VALIDATE)
        app.app_log(app.LOG_SET_COL_ID, '2', panel=app.LOG_PANEL_VALIDATE)
        app.app_log(app.LOG_SET_ZEROBASE, '0', panel=app.LOG_PANEL_VALIDATE)
        app.app_log(app.LOG_SET_REGEX, 'Line (\d+) Col (\d+):.+', panel=app.LOG_PANEL_VALIDATE)

        m = []
        error_list = self.find_errors(output)
        for match, line, col, error, warning, message, near in error_list:
            if match and message and line is not None:
                m.append((line, col, message, error, warning))

        error_count = 0
        if m:
            m = sorted(m, key = lambda m: m[0])
            bm = dict()
            for line, col, message, error, warning in m:
                if error:
                    bm_kind = KIND_ERROR
                elif warning:
                    bm_kind = KIND_WARN
                else:
                    if self.default_type == ERROR:
                        bm_kind = KIND_ERROR
                    elif self.default_type == WARNING:
                        bm_kind = KIND_WARN
                    else:
                        bm_kind = KIND_INFO

                if col is None:
                    col = 1
                app.app_log(app.LOG_ADD,
                            'Line {} Col {}: {}'.format(line, col, message),
                            panel=app.LOG_PANEL_VALIDATE)

                bm[line] = (line-1, bm_kind, message)
                error_count += 1

            self.view.bookmark(app.BOOKMARK_DELETE_BY_TAG, 0, tag=MY_TAG)
            for line in bm:
                self.view.bookmark(app.BOOKMARK_SET, 
                    nline=bm[line][0], 
                    nkind=bm[line][1], 
                    text=bm[line][2],
                    tag=MY_TAG
                    )

        return error_count