From fc745dba7e03ef82459ddf0f90b71706230b7c16 Mon Sep 17 00:00:00 2001 From: Hajime Nakagami Date: Sat, 6 Jul 2024 20:49:13 +0900 Subject: [PATCH] flake8 --- pyvim/commands/commands.py | 7 +- pyvim/completion.py | 6 +- pyvim/editor.py | 5 +- pyvim/io/__init__.py | 4 +- pyvim/io/backends.py | 1 + pyvim/io/base.py | 2 +- pyvim/key_bindings.py | 9 +-- pyvim/layout.py | 36 +++++----- pyvim/lexer.py | 1 + pyvim/rc_file.py | 3 +- pyvim/style.py | 140 ++++++++++++++++++------------------ pyvim/welcome_message.py | 5 +- pyvim/window_arrangement.py | 6 +- 13 files changed, 110 insertions(+), 115 deletions(-) diff --git a/pyvim/commands/commands.py b/pyvim/commands/commands.py index bcd05c5..7309059 100644 --- a/pyvim/commands/commands.py +++ b/pyvim/commands/commands.py @@ -410,7 +410,7 @@ def pwd(editor): @location_cmd('cd', accepts_force=False) -def pwd(editor, location): +def cwd(editor, location): " Change working directory. " try: os.chdir(location) @@ -673,18 +673,21 @@ def enable_cursorline(editor): " Highlight the line that contains the cursor. " editor.cursorline = True + @set_cmd('nocursorline') @set_cmd('nocul') def disable_cursorline(editor): " No cursorline. " editor.cursorline = False + @set_cmd('cursorcolumn') @set_cmd('cuc') def enable_cursorcolumn(editor): " Highlight the column that contains the cursor. " editor.cursorcolumn = True + @set_cmd('nocursorcolumn') @set_cmd('nocuc') def disable_cursorcolumn(editor): @@ -694,7 +697,7 @@ def disable_cursorcolumn(editor): @set_cmd('colorcolumn', accepts_value=True) @set_cmd('cc', accepts_value=True) -def set_scroll_offset(editor, value): +def set_color_column(editor, value): try: if value: numbers = [int(val) for val in value.split(',')] diff --git a/pyvim/completion.py b/pyvim/completion.py index aaa6eb3..fbcde03 100644 --- a/pyvim/completion.py +++ b/pyvim/completion.py @@ -93,8 +93,9 @@ def get_completions(self, document, complete_event): display=c.name_with_symbols) def _get_jedi_script_from_document(self, document): - import jedi # We keep this import in-line, to improve start-up time. - # Importing Jedi is 'slow'. + # We keep this import in-line, to improve start-up time. + # Importing Jedi is 'slow'. + import jedi try: return jedi.Script( @@ -116,4 +117,3 @@ def _get_jedi_script_from_document(self, document): except KeyError: # Workaround for a crash when the input is "u'", the start of a unicode string. return None - diff --git a/pyvim/editor.py b/pyvim/editor.py index 922b4bc..8860d27 100644 --- a/pyvim/editor.py +++ b/pyvim/editor.py @@ -20,7 +20,7 @@ from .commands.preview import CommandPreviewer from .help import HELP_TEXT from .key_bindings import create_key_bindings -from .layout import EditorLayout, get_terminal_title +from .layout import EditorLayout from .style import generate_built_in_styles, get_editor_style_by_name from .window_arrangement import WindowArrangement from .io import FileIO, DirectoryIO, HttpIO, GZipFileIO @@ -167,10 +167,9 @@ def _create_application(self): editing_mode=EditingMode.VI, layout=self.editor_layout.layout, key_bindings=self.key_bindings, -# get_title=lambda: get_terminal_title(self), style=DynamicStyle(lambda: self.current_style), paste_mode=Condition(lambda: self.paste_mode), -# ignore_case=Condition(lambda: self.ignore_case), # TODO + # ignore_case=Condition(lambda: self.ignore_case), # TODO include_default_pygments_style=False, mouse_support=Condition(lambda: self.enable_mouse_support), full_screen=True, diff --git a/pyvim/io/__init__.py b/pyvim/io/__init__.py index a4f29c0..ac56303 100644 --- a/pyvim/io/__init__.py +++ b/pyvim/io/__init__.py @@ -1,2 +1,2 @@ -from .base import * -from .backends import * +from .base import * # noqa +from .backends import * # noqa diff --git a/pyvim/io/backends.py b/pyvim/io/backends.py index 2aa7632..023d65f 100644 --- a/pyvim/io/backends.py +++ b/pyvim/io/backends.py @@ -1,6 +1,7 @@ import codecs import gzip import os +import urllib from .base import EditorIO diff --git a/pyvim/io/base.py b/pyvim/io/base.py index 13d924c..bdef738 100644 --- a/pyvim/io/base.py +++ b/pyvim/io/base.py @@ -5,7 +5,7 @@ ) -class EditorIO(metaclass = ABCMeta): +class EditorIO(metaclass=ABCMeta): """ The I/O interface for editor buffers. diff --git a/pyvim/key_bindings.py b/pyvim/key_bindings.py index fcb2094..b4b44e8 100644 --- a/pyvim/key_bindings.py +++ b/pyvim/key_bindings.py @@ -79,8 +79,7 @@ def enter_command_mode(event): """ editor.enter_command_mode() - @kb.add('tab', filter=vi_insert_mode & - ~has_focus(editor.command_buffer) & whitespace_before_cursor_on_line) + @kb.add('tab', filter=vi_insert_mode & ~has_focus(editor.command_buffer) & whitespace_before_cursor_on_line) def autocomplete_or_indent(event): """ When the 'tab' key is pressed with only whitespace character before the @@ -94,8 +93,7 @@ def autocomplete_or_indent(event): @kb.add('escape', filter=has_focus(editor.command_buffer)) @kb.add('c-c', filter=has_focus(editor.command_buffer)) - @kb.add('backspace', - filter=has_focus(editor.command_buffer) & Condition(lambda: editor.command_buffer.text == '')) + @kb.add('backspace', filter=has_focus(editor.command_buffer) & Condition(lambda: editor.command_buffer.text == '')) def leave_command_mode(event): """ Leaving command mode. @@ -139,8 +137,7 @@ def show_help(event): @Condition def in_file_explorer_mode(): - return bool(editor.current_editor_buffer and - editor.current_editor_buffer.in_file_explorer_mode) + return bool(editor.current_editor_buffer and editor.current_editor_buffer.in_file_explorer_mode) @kb.add('enter', filter=in_file_explorer_mode) def open_path(event): diff --git a/pyvim/layout.py b/pyvim/layout.py index 1a7ebfd..caa0e6a 100644 --- a/pyvim/layout.py +++ b/pyvim/layout.py @@ -32,6 +32,7 @@ 'get_terminal_title', ) + def _try_char(character, backup, encoding=sys.stdout.encoding): """ Return `character` if it can be encoded using sys.stdout, else return the @@ -125,8 +126,7 @@ def condition(): # Only show when there is only one empty buffer, but once the # welcome message has been hidden, don't show it again. - result = (len(buffers) == 1 and buffers[0].buffer.text == '' and - buffers[0].location is None and not once_hidden[0]) + result = len(buffers) == 1 and buffers[0].buffer.text == '' and buffers[0].location is None and not once_hidden[0] if not result: once_hidden[0] = True return result @@ -149,8 +149,7 @@ def overlay_is_visible(): app = get_app() text = editor.command_buffer.text.lstrip() - return app.layout.has_focus(editor.command_buffer) and ( - any(text.startswith(p) for p in ['b ', 'b! ', 'buffer', 'buffer!'])) + return app.layout.has_focus(editor.command_buffer) and (any(text.startswith(p) for p in ['b ', 'b! ', 'buffer', 'buffer!'])) return overlay_is_visible @@ -286,9 +285,7 @@ def get_formatted_text(): return [] - super(ReportMessageToolbar, self).__init__( - FormattedTextToolbar(get_formatted_text), - filter=~has_focus(editor.command_buffer) & ~is_searching & ~has_focus('system')) + super(ReportMessageToolbar, self).__init__(FormattedTextToolbar(get_formatted_text), filter=~has_focus(editor.command_buffer) & ~is_searching & ~has_focus('system')) class WindowStatusBar(FormattedTextToolbar): @@ -454,9 +451,7 @@ def __init__(self, editor, window_arrangement): Float(bottom=1, left=0, right=0, height=1, content=ConditionalContainer( CompletionsToolbar(), - filter=has_focus(editor.command_buffer) & - ~_bufferlist_overlay_visible(editor) & - Condition(lambda: editor.show_wildmenu))), + filter=has_focus(editor.command_buffer) & ~_bufferlist_overlay_visible(editor) & Condition(lambda: editor.show_wildmenu))), Float(bottom=1, left=0, right=0, height=1, content=ValidationToolbar()), Float(bottom=1, left=0, right=0, height=1, @@ -541,11 +536,12 @@ def wrap_lines(): top=(lambda: self.editor.scroll_offset), bottom=(lambda: self.editor.scroll_offset)), wrap_lines=wrap_lines, - left_margins=[ConditionalMargin( - margin=NumberedMargin( - display_tildes=True, - relative=Condition(lambda: self.editor.relative_number)), - filter=Condition(lambda: self.editor.show_line_numbers))], + left_margins=[ + ConditionalMargin( + margin=NumberedMargin(display_tildes=True, relative=Condition(lambda: self.editor.relative_number)), + filter=Condition(lambda: self.editor.show_line_numbers) + ) + ], cursorline=Condition(lambda: self.editor.cursorline), cursorcolumn=Condition(lambda: self.editor.cursorcolumn), colorcolumns=( @@ -582,8 +578,10 @@ def preview_search(): TabsProcessor( tabstop=(lambda: self.editor.tabstop), char1=(lambda: '|' if self.editor.display_unprintable_characters else ' '), - char2=(lambda: _try_char('\u2508', '.', get_app().output.encoding()) - if self.editor.display_unprintable_characters else ' '), + char2=( + lambda: _try_char('\u2508', '.', get_app().output.encoding()) + if self.editor.display_unprintable_characters else ' ' + ), ), # Reporting of errors, for Pyflakes. @@ -623,6 +621,7 @@ def _get_line_prefix(self, buffer, line_number, wrap_count): return result return '' + class ReportingProcessor(Processor): """ Highlight all pyflakes errors on the input. @@ -630,7 +629,7 @@ class ReportingProcessor(Processor): def __init__(self, editor_buffer): self.editor_buffer = editor_buffer - def apply_transformation(self, transformation_input): + def apply_transformation(self, transformation_input): fragments = transformation_input.fragments if self.editor_buffer.report_errors: @@ -644,7 +643,6 @@ def apply_transformation(self, transformation_input): return Transformation(fragments) - def get_terminal_title(editor): """ Return the terminal title, diff --git a/pyvim/lexer.py b/pyvim/lexer.py index 9cb7efa..ff0501a 100644 --- a/pyvim/lexer.py +++ b/pyvim/lexer.py @@ -31,6 +31,7 @@ def lex_document(self, document): _DirectoryListing = Token.DirectoryListing + class DirectoryListingLexer(RegexLexer): """ Highlighting of directory listings. diff --git a/pyvim/rc_file.py b/pyvim/rc_file.py index ecca21b..855dc56 100644 --- a/pyvim/rc_file.py +++ b/pyvim/rc_file.py @@ -14,6 +14,7 @@ 'run_rc_file', ) + def _press_enter_to_continue(): """ Wait for the user to press enter. """ input('\nPress ENTER to continue...') @@ -48,7 +49,7 @@ def run_rc_file(editor, rc_file): if 'configure' in namespace: namespace['configure'](editor) - except Exception as e: + except Exception: # Handle possible exceptions in rc file. traceback.print_exc() _press_enter_to_continue() diff --git a/pyvim/style.py b/pyvim/style.py index 45e7033..b591b4d 100644 --- a/pyvim/style.py +++ b/pyvim/style.py @@ -38,110 +38,110 @@ def generate_built_in_styles(): style_extensions = { # Toolbar colors. - 'toolbar.status': '#ffffff bg:#444444', + 'toolbar.status': '#ffffff bg:#444444', 'toolbar.status.cursorposition': '#bbffbb bg:#444444', - 'toolbar.status.percentage': '#ffbbbb bg:#444444', + 'toolbar.status.percentage': '#ffbbbb bg:#444444', # Flakes color. - 'flakeserror': 'bg:#ff4444 #ffffff', + 'flakeserror': 'bg:#ff4444 #ffffff', # Flake messages - 'flakemessage.prefix': 'bg:#ff8800 #ffffff', - 'flakemessage': '#886600', + 'flakemessage.prefix': 'bg:#ff8800 #ffffff', + 'flakemessage': '#886600', # Highlighting for the text in the command bar. - 'commandline.command': 'bold', - 'commandline.location': 'bg:#bbbbff #000000', + 'commandline.command': 'bold', + 'commandline.location': 'bg:#bbbbff #000000', # Frame borders (for between vertical splits.) - 'frameborder': 'bold', #bg:#88aa88 #ffffff', + 'frameborder': 'bold', # bg:#88aa88 #ffffff', # Messages - 'message': 'bg:#bbee88 #222222', + 'message': 'bg:#bbee88 #222222', # Welcome message - 'welcome title': 'underline', - 'welcome version': '#8800ff', - 'welcome key': '#0000ff', - 'welcome pythonversion': 'bg:#888888 #ffffff', + 'welcome title': 'underline', + 'welcome version': '#8800ff', + 'welcome key': '#0000ff', + 'welcome pythonversion': 'bg:#888888 #ffffff', # Tabs - 'tabbar': 'noinherit reverse', - 'tabbar.tab': 'underline', - 'tabbar.tab.active': 'bold noinherit', + 'tabbar': 'noinherit reverse', + 'tabbar.tab': 'underline', + 'tabbar.tab.active': 'bold noinherit', # Arg count. - 'arg': 'bg:#cccc44 #000000', + 'arg': 'bg:#cccc44 #000000', # Buffer list - 'bufferlist': 'bg:#aaddaa #000000', - 'bufferlist title': 'underline', - 'bufferlist lineno': '#666666', - 'bufferlist active': 'bg:#ccffcc', + 'bufferlist': 'bg:#aaddaa #000000', + 'bufferlist title': 'underline', + 'bufferlist lineno': '#666666', + 'bufferlist active': 'bg:#ccffcc', 'bufferlist active.lineno': '#666666', - 'bufferlist searchmatch': 'bg:#eeeeaa', + 'bufferlist searchmatch': 'bg:#eeeeaa', # Completions toolbar. - 'completions-toolbar': 'bg:#aaddaa #000000', - 'completions-toolbar.arrow': 'bg:#aaddaa #000000 bold', - 'completions-toolbar completion': 'bg:#aaddaa #000000', + 'completions-toolbar': 'bg:#aaddaa #000000', + 'completions-toolbar.arrow': 'bg:#aaddaa #000000 bold', + 'completions-toolbar completion': 'bg:#aaddaa #000000', 'completions-toolbar current-completion': 'bg:#444444 #ffffff', # Soft wrap. - 'soft-wrap': '#888888', + 'soft-wrap': '#888888', # Directory listing style. - 'pygments.directorylisting.header': '#4444ff', + 'pygments.directorylisting.header': '#4444ff', 'pygments.directorylisting.directory': '#ff4444 bold', 'pygments.directorylisting.currentdirectory': '#888888', 'pygments.directorylisting.parentdirectory': '#888888', - 'pygments.directorylisting.tempfile': '#888888', - 'pygments.directorylisting.dotfile': '#888888', - 'pygments.directorylisting.pythonfile': '#8800ff', - 'pygments.directorylisting.textfile': '#aaaa00', + 'pygments.directorylisting.tempfile': '#888888', + 'pygments.directorylisting.dotfile': '#888888', + 'pygments.directorylisting.pythonfile': '#8800ff', + 'pygments.directorylisting.textfile': '#aaaa00', } # Default 'vim' color scheme. Taken from the Pygments Vim colorscheme, but # modified to use mainly ANSI colors. default_vim_style = { - 'pygments': '', - 'pygments.whitespace': '', - 'pygments.comment': 'ansiblue', - 'pygments.comment.preproc': 'ansiyellow', - 'pygments.comment.special': 'bold', - - 'pygments.keyword': '#999900', - 'pygments.keyword.declaration': 'ansigreen', - 'pygments.keyword.namespace': 'ansimagenta', - 'pygments.keyword.pseudo': '', - 'pygments.keyword.type': 'ansigreen', - - 'pygments.operator': '', - 'pygments.operator.word': '', - - 'pygments.name': '', - 'pygments.name.class': 'ansicyan', - 'pygments.name.builtin': 'ansicyan', - 'pygments.name.exception': '', - 'pygments.name.variable': 'ansicyan', - 'pygments.name.function': 'ansicyan', - - 'pygments.literal': 'ansired', - 'pygments.string': 'ansired', - 'pygments.string.doc': '', - 'pygments.number': 'ansimagenta', - - 'pygments.generic.heading': 'bold ansiblue', - 'pygments.generic.subheading': 'bold ansimagenta', - 'pygments.generic.deleted': 'ansired', - 'pygments.generic.inserted': 'ansigreen', - 'pygments.generic.error': 'ansibrightred', - 'pygments.generic.emph': 'italic', - 'pygments.generic.strong': 'bold', - 'pygments.generic.prompt': 'bold ansiblue', - 'pygments.generic.output': 'ansigray', - 'pygments.generic.traceback': '#04d', - - 'pygments.error': 'border:ansired' + 'pygments': '', + 'pygments.whitespace': '', + 'pygments.comment': 'ansiblue', + 'pygments.comment.preproc': 'ansiyellow', + 'pygments.comment.special': 'bold', + + 'pygments.keyword': '#999900', + 'pygments.keyword.declaration': 'ansigreen', + 'pygments.keyword.namespace': 'ansimagenta', + 'pygments.keyword.pseudo': '', + 'pygments.keyword.type': 'ansigreen', + + 'pygments.operator': '', + 'pygments.operator.word': '', + + 'pygments.name': '', + 'pygments.name.class': 'ansicyan', + 'pygments.name.builtin': 'ansicyan', + 'pygments.name.exception': '', + 'pygments.name.variable': 'ansicyan', + 'pygments.name.function': 'ansicyan', + + 'pygments.literal': 'ansired', + 'pygments.string': 'ansired', + 'pygments.string.doc': '', + 'pygments.number': 'ansimagenta', + + 'pygments.generic.heading': 'bold ansiblue', + 'pygments.generic.subheading': 'bold ansimagenta', + 'pygments.generic.deleted': 'ansired', + 'pygments.generic.inserted': 'ansigreen', + 'pygments.generic.error': 'ansibrightred', + 'pygments.generic.emph': 'italic', + 'pygments.generic.strong': 'bold', + 'pygments.generic.prompt': 'bold ansiblue', + 'pygments.generic.output': 'ansigray', + 'pygments.generic.traceback': '#04d', + + 'pygments.error': 'border:ansired' } diff --git a/pyvim/welcome_message.py b/pyvim/welcome_message.py index bd97315..3dc8ed5 100644 --- a/pyvim/welcome_message.py +++ b/pyvim/welcome_message.py @@ -1,9 +1,6 @@ """ The welcome message. This is displayed when the editor opens without any files. """ -from __future__ import unicode_literals -from prompt_toolkit.formatted_text.utils import fragment_list_len - import prompt_toolkit import pyvim import platform @@ -24,7 +21,7 @@ ('class:title', 'PyVim - Pure Python Vi clone\n'), ('', 'Still experimental\n\n'), ('', 'version '), ('class:version', pyvim_version), - ('', ', prompt_toolkit '), ('class:version', prompt_toolkit.__version__), + ('', ', prompt_toolkit '), ('class:version', prompt_toolkit.__version__), ('', '\n'), ('', 'by Jonathan Slenders\n\n'), ('', 'type :q'), diff --git a/pyvim/window_arrangement.py b/pyvim/window_arrangement.py index 9892e26..54f6815 100644 --- a/pyvim/window_arrangement.py +++ b/pyvim/window_arrangement.py @@ -354,8 +354,7 @@ def go_to_previous_tab(self): """ Focus the previous tab. """ - self.active_tab_index = (self.active_tab_index - 1 + - len(self.tab_pages)) % len(self.tab_pages) + self.active_tab_index = (self.active_tab_index - 1 + len(self.tab_pages)) % len(self.tab_pages) def go_to_buffer(self, buffer_name): """ @@ -364,8 +363,7 @@ def go_to_buffer(self, buffer_name): assert isinstance(buffer_name, str) for i, eb in enumerate(self.editor_buffers): - if (eb.location == buffer_name or - (buffer_name.isdigit() and int(buffer_name) == i)): + if eb.location == buffer_name or (buffer_name.isdigit() and int(buffer_name) == i): self.show_editor_buffer(eb) break