Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flake8 #4

Merged
merged 4 commits into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ jobs:
run: |
python -m pip install setuptools
python -m pip install --upgrade pip
python -m pip install flake8
python -m pip install pytest
python -m pip install -e .
- name: Test
run: |
flake8 --ignore=E501
py.test
7 changes: 5 additions & 2 deletions pyvim/commands/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand All @@ -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(',')]
Expand Down
6 changes: 3 additions & 3 deletions pyvim/completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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

5 changes: 2 additions & 3 deletions pyvim/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions pyvim/io/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from .base import *
from .backends import *
from .base import * # noqa
from .backends import * # noqa
1 change: 1 addition & 0 deletions pyvim/io/backends.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import codecs
import gzip
import os
import urllib

from .base import EditorIO

Expand Down
2 changes: 1 addition & 1 deletion pyvim/io/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
)


class EditorIO(metaclass = ABCMeta):
class EditorIO(metaclass=ABCMeta):
"""
The I/O interface for editor buffers.

Expand Down
9 changes: 3 additions & 6 deletions pyvim/key_bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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):
Expand Down
36 changes: 17 additions & 19 deletions pyvim/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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


Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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=(
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -623,14 +621,15 @@ def _get_line_prefix(self, buffer, line_number, wrap_count):
return result
return ''


class ReportingProcessor(Processor):
"""
Highlight all pyflakes errors on the input.
"""
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:
Expand All @@ -644,7 +643,6 @@ def apply_transformation(self, transformation_input):
return Transformation(fragments)



def get_terminal_title(editor):
"""
Return the terminal title,
Expand Down
1 change: 1 addition & 0 deletions pyvim/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def lex_document(self, document):

_DirectoryListing = Token.DirectoryListing


class DirectoryListingLexer(RegexLexer):
"""
Highlighting of directory listings.
Expand Down
3 changes: 2 additions & 1 deletion pyvim/rc_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
'run_rc_file',
)


def _press_enter_to_continue():
""" Wait for the user to press enter. """
input('\nPress ENTER to continue...')
Expand Down Expand Up @@ -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()
Loading