Skip to content

Commit 5bc6eaf

Browse files
committed
tweak doc & fix linting
1 parent 273562e commit 5bc6eaf

File tree

5 files changed

+40
-25
lines changed

5 files changed

+40
-25
lines changed

docs/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
# digitalio, micropython and busio. List the modules you use. Without it, the
2727
# autodoc module docs will fail to generate with a warning.
2828
# autodoc_mock_imports = ["digitalio", "busio"]
29+
autodoc_mock_imports = ["usb_cdc"]
2930

3031

3132
intersphinx_mapping = {

examples/nonblocking_serialinput_advanced.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030

3131
def userinput_print_help():
3232
"""Print Help."""
33-
global runtime_print
34-
global runtime_print_intervall
3533
text = (
3634
"you can change some things:\n"
3735
"- 'tr': toggle print runtime ({runtime_print})\n"
@@ -47,6 +45,7 @@ def userinput_print_help():
4745

4846
def userinput_handling(input_string):
4947
"""Check Input."""
48+
# pylint: disable=global-statement
5049
global running
5150
global runtime_print
5251
global runtime_print_next
@@ -76,9 +75,8 @@ def userinput_handling(input_string):
7675

7776
def main_update():
7877
"""Do all the things your main code want's to do...."""
79-
global runtime_print
78+
# pylint: disable=global-statement
8079
global runtime_print_next
81-
global runtime_print_intervall
8280

8381
if runtime_print:
8482
if runtime_print_next < time.monotonic():

examples/nonblocking_serialinput_advanced_statusline.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@
77

88
"""Simple Minimal example of CircuitPython_nonblocking_serialinput library usage."""
99

10+
# CircuitPython ignores the normal docstring - so we have to explicitly set it..
11+
__doc__ = """
12+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
13+
| nonblocking_serialinput_advanced_class.py |
14+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15+
| more at: |
16+
| https://github.com/s-light/CircuitPython_nonblocking_serialinput |
17+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18+
"""
19+
1020
import time
1121
import sys
1222
import board
@@ -44,6 +54,7 @@ def userinput_print_help(self):
4454
"""Print Help."""
4555
text = (
4656
"you can change some things:\n"
57+
"- '?': about\n"
4758
"- 'tr': toggle print runtime ({runtime_print})\n"
4859
"- 'time set:???': set print runtime intervall ({runtime_print_intervall: > 7.2f}s)\n"
4960
"- 'exit' stop program"
@@ -56,17 +67,19 @@ def userinput_print_help(self):
5667

5768
def userinput_event_handling(self, input_string):
5869
"""Handle user input."""
59-
if "tr" in input_string:
70+
if "?" in input_string:
71+
self.my_input.print(__doc__)
72+
elif "tr" in input_string:
6073
self.runtime_print = not self.runtime_print
61-
if "time set" in input_string:
74+
elif "time set" in input_string:
6275
self.my_input.print("time set:")
6376
value = nb_serialin.parse_value(input_string, "time set")
6477
if nb_serialin.is_number(value):
6578
self.runtime_print_intervall = value
6679
self.runtime_print_next = (
6780
time.monotonic() + self.runtime_print_intervall
6881
)
69-
if "exit" in input_string:
82+
elif "exit" in input_string:
7083
self.my_input.print("Stop Program running.")
7184
self.running = False
7285

examples/nonblocking_serialinput_statusline_dev.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
import time
1111
import board
1212
import digitalio
13-
import nonblocking_serialinput as nb_serialin
1413
import ansi_escape_code as terminal
14+
import nonblocking_serialinput as nb_serialin
1515

1616
##########################################
1717
# globals

nonblocking_serialinput.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@
2020
2121
**Software and Dependencies:**
2222
23-
* Adafruit CircuitPython firmware `>= 7.0.0 for the supported boards.
24-
<https://github.com/adafruit/circuitpython/releases>`_
25-
* Core Module `usb_cdc:
23+
* Adafruit CircuitPython firmware
24+
`>= 7.0.0 for the supported boards. <https://github.com/adafruit/circuitpython/releases>`_
25+
* Core Module ` ``usb_cdc``
2626
<https://circuitpython.readthedocs.io/en/latest/shared-bindings/usb_cdc/index.html>`_
27+
* `CircuitPython_ansi_escape_code <https://github.com/s-light/CircuitPython_ansi_escape_code>`_
2728
"""
2829

2930
import time
@@ -42,7 +43,7 @@
4243

4344

4445
class NonBlockingSerialInput:
45-
"""Non Blocking Serial Input Class.
46+
r"""Non Blocking Serial Input Class.
4647
4748
This CircuitPython helper class can be used as non-blocking *drop-in* for the build
4849
in ``input()`` method.
@@ -54,7 +55,7 @@ class NonBlockingSerialInput:
5455
:param function input_handling_fn: function to call if there is one ore more
5556
fully received new lines. ``input_handling(input_string: string)``
5657
Default: None
57-
:param function print_help_fn:function to call when a help text should be printed
58+
:param function print_help_fn: function to call when a help text should be printed
5859
fully received new lines. ``print_help()``
5960
Default: None
6061
:param ~usb_cdc.Serial serial: serial connection object to use
@@ -76,10 +77,10 @@ class NonBlockingSerialInput:
7677
:param string, list line_end_custom: set custom line ends
7778
Default: None
7879
:param bool use_universal_line_end_basic: use a basic default set of line_ends
79-
[`\n`, '\r', '\r\n']
80+
``['\n', '\r', '\r\n']``]
8081
Default: True
8182
:param bool use_universal_line_end_advanced: use a advanced default set of line_ends
82-
['\v', '\f', '\x1c',...]
83+
``['\v', '\f', '\x1c',...]``
8384
Default: False
8485
:param bool verbose: print debugging information in some internal functions. Default to False
8586
@@ -168,7 +169,7 @@ def echo_print(self):
168169

169170
def print(self, *args, content=True):
170171
# def print(self, *args, end="\n"):
171-
"""
172+
r"""
172173
Print information & variables to the connected serial.
173174
174175
This is a *drop in replacement* for the global print function.
@@ -177,7 +178,7 @@ def print(self, *args, content=True):
177178
178179
currently it is not supported to print without newline at end.
179180
180-
:param object *args: things to print
181+
:param object \*args: things to print
181182
"""
182183
# :param bool end: line end character to print. Default: "\n"
183184
if self.echo or self.statusline:
@@ -280,11 +281,12 @@ def _buffer_handle_cursor_position(self):
280281

281282
def input(self):
282283
"""
283-
Input.
284+
Get oldest input if available.
284285
285-
get oldest input string if there is any available. Otherwise an emtpy string.
286+
test
287+
Otherwise an emtpy string.
286288
287-
:return string: if available oldest input_line. Otherwise `""`
289+
:return string: if available oldest input_line. otherwise ``""``
288290
"""
289291
try:
290292
result = self.input_list.pop(0)
@@ -395,7 +397,7 @@ def find_first_line_end(input_string, line_end_list=None, start=0):
395397
:param string input_string: input search
396398
:param list line_end_list: list with strings to search for.
397399
:param int start: start position for search. (default = 0)
398-
:return int: index of first found line_end; `-1` if nothing is found.
400+
:return int: index of first found line_end; ``-1`` if nothing is found.
399401
"""
400402
result = None
401403
if line_end_list is None:
@@ -422,7 +424,7 @@ def splitlines_advanced(input_string, line_end_list=None):
422424
then splits at these points. the resulting list is returned.
423425
this also returns empty string segments.
424426
the search happens in the order of line_end_list.
425-
if the string does not end with a line_end symbol this last part will be returned in `rest`
427+
if the string does not end with a line_end symbol this last part will be returned in ``rest``
426428
427429
:param string input_string: input to split
428430
:param list line_end_list: list with strings where the splitting should happen.
@@ -471,11 +473,12 @@ def parse_value(input_string, pre_text=""):
471473
"""
472474
Parse Value from input_string.
473475
474-
known values are numbers (`float()` is used), None, True, False
476+
known values are numbers (``float()`` is used), ``None``, ``True``, ``False``
475477
476478
:param string input_string: input to parse
477-
:param string pre_text: text at start of input_string to ignore. defaults to ""
478-
:return float | None | True | False: parsed value
479+
:param string pre_text: text at start of input_string to ignore. defaults to ``""``
480+
:return: parsed value
481+
:rtype: float, None, bool
479482
"""
480483
value = None
481484
# strip pre_text

0 commit comments

Comments
 (0)