Skip to content

Commit a173864

Browse files
authored
Merge pull request #80 from jkonecny12/master-remove-pocketlint
Replace pocketlint with pylint
2 parents 8f2d7ad + 0d91852 commit a173864

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+810
-243
lines changed

.pylintrc

Lines changed: 504 additions & 0 deletions
Large diffs are not rendered by default.

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ coverage:
6161

6262
.PHONY: check
6363
check:
64-
@echo "*** Running pocketlint ***"
65-
PYTHONPATH=. tests/pylint/runpylint.py
64+
@echo "*** Running pylint ***"
65+
$(PYTHON) -m pylint simpleline/ examples/*/*.py tests/
6666

6767
.PHONY: install
6868
install:

examples/01_base_widgets/01_base_widgets.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,17 @@ def refresh(self, args=None):
5252

5353
# Checkbox widget
5454
# Checkbox which can hold 2 states.
55-
checkbox_widget = CheckboxWidget(key="o", title="Checkbox title", text="Checkbox text", completed=True)
55+
checkbox_widget = CheckboxWidget(key="o",
56+
title="Checkbox title",
57+
text="Checkbox text",
58+
completed=True)
5659
self.window.add_with_separator(checkbox_widget)
5760

5861
# Checkbox widget unchecked
59-
checkbox_widget_unchecked = CheckboxWidget(key="o", title="Checkbox title", text="Unchecked", completed=False)
62+
checkbox_widget_unchecked = CheckboxWidget(key="o",
63+
title="Checkbox title",
64+
text="Unchecked",
65+
completed=False)
6066
self.window.add_with_separator(checkbox_widget_unchecked)
6167

6268

examples/03_entry_counter/03_entry_counter.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ def input(self, args, key):
4343
ScreenHandler.push_screen(self._counter_spoke)
4444
# this input was processed
4545
return InputState.PROCESSED
46-
else:
47-
# return for outer processing
48-
# the basic processing is 'c' for continue, 'r' for refresh, 'q' to quit
49-
# otherwise the input is discarded and waiting for a new input
50-
return key
46+
47+
# return for outer processing
48+
# the basic processing is 'c' for continue, 'r' for refresh, 'q' to quit
49+
# otherwise the input is discarded and waiting for a new input
50+
return key
5151

5252
def prompt(self, args=None):
5353
"""Add our information to the prompt."""

examples/05_hub_spoke/05_hub_spoke.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,9 @@ def refresh(self, args=None):
8282
#
8383
# widget - Widget we want to render. It will be numbered automatically.
8484
# Could be container if needed.
85-
# callback - This callback will be called by the ListRowContainer.process_user_input() method
86-
# when a user press the number of this item. Callback will get args passed as 3rd argument.
85+
# callback - This callback will be called by the ListRowContainer.process_user_input()
86+
# method when a user press the number of this item. Callback will get args
87+
# passed as 3rd argument.
8788
# args - Argument for callback.
8889
self._container.add(widget, self._push_screen_callback, self._name_spoke)
8990

@@ -139,16 +140,18 @@ def input(self, args, key):
139140
if self._container.process_user_input(key):
140141
# Do not process other input if spoke is entered.
141142
return InputState.PROCESSED
143+
142144
# Block continue ('c') if everything is not set.
143-
elif key == Prompt.CONTINUE:
145+
if key == Prompt.CONTINUE:
144146
if self._name_spoke and self._surname_spoke and self._password_spoke.answer:
145147
return key
146-
else: # catch 'c' key if not everything set
147-
return InputState.DISCARDED
148-
else:
149-
return key
148+
# catch 'c' key if not everything set
149+
return InputState.DISCARDED
150+
151+
return key
150152

151-
def _push_screen_callback(self, target_screen):
153+
@staticmethod
154+
def _push_screen_callback(target_screen):
152155
"""Push target screen as new screen.
153156
154157
Target screen is passed in as an argument in the refresh() method.

examples/07_divider/07_divider.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ def input(self, args, key):
8080
# This will call refresh so our new result will be processed inside of the refresh()
8181
# method.
8282
return InputState.PROCESSED_AND_REDRAW
83-
else:
84-
# Not input for our screen, try other default inputs. This will result in the
85-
# same state as DISCARDED when no default option is used.
86-
return key
83+
84+
# Not input for our screen, try other default inputs. This will result in the
85+
# same state as DISCARDED when no default option is used.
86+
return key
8787

8888

8989
if __name__ == "__main__":
@@ -100,4 +100,3 @@ def input(self, args, key):
100100
# Run the application. You must have some screen scheduled
101101
# otherwise it will end in an infinite loop.
102102
App.run()
103-

simpleline/__init__.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
setup_logging()
3030

3131

32-
class App(object):
32+
class App():
3333
"""This is the main class for Simpleline library.
3434
3535
Do not create instance of this class. Use this class as static!
@@ -43,7 +43,7 @@ class in your application.
4343
"""
4444
__app = None
4545

46-
class AppPimpl(object):
46+
class AppPimpl():
4747

4848
def __init__(self, scheduler, event_loop, configuration):
4949
self.event_loop = event_loop
@@ -69,9 +69,9 @@ def initialize(cls, scheduler=None, event_loop=None, global_configuration=None):
6969
:type global_configuration: object based on class
7070
`simpleline.global_configuration.GlobalConfiguration`
7171
"""
72-
from simpleline.event_loop.main_loop import MainLoop
73-
from simpleline.render.screen_scheduler import ScreenScheduler
74-
from simpleline.global_configuration import GlobalConfiguration
72+
from simpleline.event_loop.main_loop import MainLoop # pylint: disable=import-outside-toplevel
73+
from simpleline.render.screen_scheduler import ScreenScheduler # pylint: disable=import-outside-toplevel
74+
from simpleline.global_configuration import GlobalConfiguration # pylint: disable=import-outside-toplevel
7575

7676
if event_loop is None:
7777
event_loop = MainLoop()
@@ -86,7 +86,7 @@ def initialize(cls, scheduler=None, event_loop=None, global_configuration=None):
8686

8787
@classmethod
8888
def _post_init(cls):
89-
from simpleline.input.input_threading import InputThreadManager
89+
from simpleline.input.input_threading import InputThreadManager # pylint: disable=import-outside-toplevel
9090
# FIXME: This should be done by more general way not by calling exact class here.
9191
# Create new instance of InputThreadManager because it needs new event loop
9292
InputThreadManager.create_new_instance()
@@ -99,8 +99,8 @@ def is_initialized(cls):
9999
"""
100100
if cls.__app is None:
101101
return False
102-
else:
103-
return True
102+
103+
return True
104104

105105
@classmethod
106106
def get_scheduler(cls):

simpleline/event_loop/__init__.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ def enqueue_signal(self, signal):
9292
:param signal: Signal which you want to add to the event queue for processing.
9393
:type signal: Instance based on AbstractEvent class.
9494
"""
95-
log.debug("New signal %s enqueued with source %s", signal, signal.source.__class__.__name__)
95+
log.debug("New signal %s enqueued with source %s",
96+
signal,
97+
signal.source.__class__.__name__)
9698

9799
@abstractmethod
98100
def run(self):
@@ -132,14 +134,14 @@ def close_loop(self):
132134
def process_signals(self, return_after=None):
133135
"""This method processes incoming async messages.
134136
135-
Process signals enqueued by the `self.enqueue_signal()` method. Call handlers registered to the signals by
136-
the `self.register_signal_handler()` method.
137+
Process signals enqueued by the `self.enqueue_signal()` method. Call handlers
138+
registered to the signals by the `self.register_signal_handler()` method.
137139
138140
When `return_after` is specified then wait to the point when this signal is processed.
139141
NO warranty that this method will return immediately after the signal was processed!
140142
141-
Without `return_after` parameter this method will return after all queued signals with the highest priority
142-
will be processed.
143+
Without `return_after` parameter this method will return after all queued signals
144+
with the highest priority will be processed.
143145
144146
The method is NOT thread safe!
145147
@@ -161,8 +163,8 @@ def set_quit_callback(self, callback, args=None):
161163
def kill_app_with_traceback(self, exception_signal, data=None):
162164
"""Print exception and screen stack and kill the application.
163165
164-
:param exception_signal: ExceptionSignal encapsulating the original exception which will be passed to
165-
the sys.excepthook method.
166+
:param exception_signal: ExceptionSignal encapsulating the original exception which
167+
will be passed to the sys.excepthook method.
166168
:type exception_signal: Instance of `simpleline.event_loop.signals.ExceptionSignal` class.
167169
168170
:param data: To be usable as signal handler.
@@ -171,7 +173,7 @@ def kill_app_with_traceback(self, exception_signal, data=None):
171173
log.debug("Unhandled error in handler raised:")
172174
sys.excepthook(*exception_signal.exception_info)
173175

174-
from simpleline import App
176+
from simpleline import App # pylint: disable=import-outside-toplevel
175177
stack_dump = App.get_scheduler().dump_stack()
176178
print("")
177179
print(stack_dump)
@@ -180,7 +182,8 @@ def kill_app_with_traceback(self, exception_signal, data=None):
180182
log.debug("Killing application!")
181183
sys.exit(1)
182184

183-
def _create_event_handler(self, callback, data):
185+
@staticmethod
186+
def _create_event_handler(callback, data):
184187
"""Create event handler data object and return it."""
185188
return EventHandler(callback=callback, data=data)
186189

@@ -214,7 +217,7 @@ def _check_if_signal_processed(self, wait_on_signal, unique_id):
214217
return self._processed_signals.check_ticket(wait_on_signal.__name__, unique_id)
215218

216219

217-
class EventHandler(object):
220+
class EventHandler():
218221
"""Data class to save event handlers."""
219222

220223
def __init__(self, callback, data):
@@ -250,7 +253,8 @@ def priority(self):
250253
"""Priority of this event.
251254
252255
Values less than 0 denote higher priorities. Values greater than 0 denote lower priorities.
253-
Events from high priority sources are always processed before events from lower priority sources.
256+
Events from high priority sources are always processed before events from lower priority
257+
sources.
254258
"""
255259
return self._priority
256260

simpleline/event_loop/event_queue.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class EventQueueError(SimplelineError):
3636
"""
3737

3838

39-
class EventQueue(object):
39+
class EventQueue():
4040
"""Class for managing signal queue.
4141
4242
Responsibilities of this class are:
@@ -68,7 +68,8 @@ def enqueue(self, signal):
6868
def enqueue_if_source_belongs(self, signal, source):
6969
"""Enqueue signal to this queue if the signal source belongs to this queue.
7070
71-
Enqueue the `signal` only if the `source` belongs to this queue. See the `add_source()` method.
71+
Enqueue the `signal` only if the `source` belongs to this queue.
72+
See the `add_source()` method.
7273
7374
:param signal: Signal which should be enqueued to this queue.
7475
:type signal: Signal class based on `simpleline.event_loop.signals.AbstractSignal`.
@@ -80,8 +81,8 @@ def enqueue_if_source_belongs(self, signal, source):
8081
if self.contains_source(source):
8182
self._queue.put(signal)
8283
return True
83-
else:
84-
return False
84+
85+
return False
8586

8687
def get(self):
8788
"""Return enqueued signal with the highest priority.
@@ -106,9 +107,9 @@ def get_top_event_if_priority(self, priority):
106107
event = self._queue.get()
107108
if event.priority == priority:
108109
return event
109-
else:
110-
self._queue.put(event)
111-
return None
110+
111+
self._queue.put(event)
112+
return None
112113

113114
def add_source(self, signal_source):
114115
"""Add new source of signals to this queue.

simpleline/event_loop/glib_event_loop.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@
2121
#
2222
# Author(s): Jiri Konecny <[email protected]>
2323
#
24-
2524
from collections import namedtuple
2625

26+
import gi
27+
2728
from simpleline.event_loop import AbstractEventLoop, ExitMainLoop
2829
from simpleline.event_loop.signals import ExceptionSignal
30+
from simpleline.logging import get_simpleline_logger
2931

30-
import gi
3132
gi.require_version("GLib", "2.0")
3233

33-
from gi.repository import GLib
34-
from simpleline.logging import get_simpleline_logger
34+
from gi.repository import GLib # pylint: disable=wrong-import-order, wrong-import-position
3535

3636
log = get_simpleline_logger()
3737

@@ -92,9 +92,9 @@ def _register_handlers_to_loop(self, event_loop, signal):
9292
context = event_loop.get_context()
9393
handlers = []
9494

95-
if type(signal) in self._handlers:
95+
if type(signal) in self._handlers: # pylint: disable=unidiomatic-typecheck
9696
handlers = self._handlers[type(signal)]
97-
elif type(signal) is ExceptionSignal:
97+
elif isinstance(signal, ExceptionSignal):
9898
handler_data = self._create_event_handler(self.kill_app_with_traceback, None)
9999
handlers = [handler_data]
100100

@@ -188,14 +188,14 @@ def close_loop(self):
188188
def process_signals(self, return_after=None):
189189
"""This method processes incoming async messages.
190190
191-
Process signals enqueued by the `self.enqueue_signal()` method. Call handlers registered to the signals by
192-
the `self.register_signal_handler()` method.
191+
Process signals en-queued by the `self.enqueue_signal()` method. Call handlers registered
192+
to the signals by the `self.register_signal_handler()` method.
193193
194194
When `return_after` is specified then wait to the point when this signal is processed.
195195
NO warranty that this method will return immediately after the signal was processed!
196196
197-
Without `return_after` parameter this method will return after all queued signals with the highest priority
198-
will be processed.
197+
Without `return_after` parameter this method will return after all queued signals with
198+
the highest priority will be processed.
199199
200200
The method is NOT thread safe!
201201
@@ -208,22 +208,23 @@ def process_signals(self, return_after=None):
208208
if return_after is not None:
209209
ticket_id = self._register_wait_on_signal(return_after)
210210

211-
while not self._check_if_signal_processed(return_after, ticket_id) and not self._force_quit:
211+
while not self._check_if_signal_processed(return_after, ticket_id) and \
212+
not self._force_quit:
212213
self._iterate_event_loop(loop_data.loop)
213214
else:
214215
self._iterate_event_loop(loop_data.loop)
215216

216-
def _iterate_event_loop(self, event_loop):
217+
@staticmethod
218+
def _iterate_event_loop(event_loop):
217219
context = event_loop.get_context()
218220
# This is useful for tests
219221
wait_on_timeout = False
220222
context.iteration(wait_on_timeout)
221223

222224

223-
class EventLoopData(object):
225+
class EventLoopData():
224226

225227
def __init__(self, loop):
226228
super().__init__()
227229
self.loop = loop
228230
self.sources = set()
229-

0 commit comments

Comments
 (0)