Skip to content

Commit 5c79881

Browse files
committed
added pydocstyle and compliant docstrings to source and example code.
1 parent cc6b39c commit 5c79881

File tree

15 files changed

+335
-3
lines changed

15 files changed

+335
-3
lines changed

.github/workflows/python-package.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ jobs:
3232
run: |
3333
# stop the build if there are Python syntax errors or undefined names
3434
flake8 test/ notecard/ examples/ --count --ignore=E722,F401,F403,W503 --show-source --statistics
35+
- name: Lint Docs with Pydocstyle
36+
run: |
37+
pydocstyle notecard/ examples/
3538
- name: Test with pytest
3639
run: |
3740
pytest

MAKEFILE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ default: test
77
venv: $(VENV_NAME)/bin/activate
88

99
test: venv
10+
${PYTHON} -m pydocstyle notecard/ examples/
1011
${PYTHON} -m flake8 test/ notecard/ examples/ --count --ignore=E722,F401,F403,W503 --show-source --statistics
1112
${PYTHON} -m pytest test --cov=notecard
1213

examples/cpy-example.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
"""note-python CircuitPython example.
2+
3+
This file contains a complete working sample for using the note-python
4+
library on a CircuitPython device.
5+
"""
16
import sys
27
import time
38
import notecard
@@ -13,12 +18,26 @@
1318

1419

1520
def NotecardExceptionInfo(exception):
21+
"""Construct a formatted Exception string.
22+
23+
Args:
24+
exception (Exception): An exception object.
25+
26+
Returns:
27+
string: a summary of the exception with line number and details.
28+
"""
1629
name = exception.__class__.__name__
1730
return sys.platform + ": " + name \
1831
+ ": " + ' '.join(map(str, exception.args))
1932

2033

2134
def transactionTest(card):
35+
"""Submit a simple JSON-based request to the Notecard.
36+
37+
Args:
38+
card (object): An instance of the Notecard class
39+
40+
"""
2241
req = {"req": "card.status"}
2342
req["string"] = "string"
2443
req["bool"] = True
@@ -34,6 +53,7 @@ def transactionTest(card):
3453

3554

3655
def main():
56+
"""Connect to Notcard and run a transaction test."""
3757
print("Opening port...")
3858
try:
3959
if use_uart:

examples/i2c-example.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
"""note-python I2C example.
2+
3+
This file contains a complete working sample for using the note-python
4+
library with an I2C Notecard connection.
5+
"""
16
import sys
27
import os
38
import time
@@ -14,12 +19,26 @@
1419

1520

1621
def NotecardExceptionInfo(exception):
22+
"""Construct a formatted Exception string.
23+
24+
Args:
25+
exception (Exception): An exception object.
26+
27+
Returns:
28+
string: a summary of the exception with line number and details.
29+
"""
1730
s1 = '{}'.format(sys.exc_info()[-1].tb_lineno)
1831
s2 = exception.__class__.__name__
1932
return "line " + s1 + ": " + s2 + ": " + ' '.join(map(str, exception.args))
2033

2134

2235
def transactionTest(card):
36+
"""Submit a simple JSON-based request to the Notecard.
37+
38+
Args:
39+
card (object): An instance of the Notecard class
40+
41+
"""
2342
req = {"req": "card.status"}
2443
req["string"] = "string"
2544
req["bool"] = True
@@ -35,6 +54,7 @@ def transactionTest(card):
3554

3655

3756
def main():
57+
"""Connect to Notcard and run a transaction test."""
3858
print("Opening port...")
3959
try:
4060
port = I2C("/dev/i2c-1")

examples/mpy-example.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
"""note-python MicroPython example.
2+
3+
This file contains a complete working sample for using the note-python
4+
library on a MicroPython device.
5+
"""
16
import sys
27
import time
38
import notecard
@@ -13,12 +18,26 @@
1318

1419

1520
def NotecardExceptionInfo(exception):
21+
"""Construct a formatted Exception string.
22+
23+
Args:
24+
exception (Exception): An exception object.
25+
26+
Returns:
27+
string: a summary of the exception with line number and details.
28+
"""
1629
name = exception.__class__.__name__
1730
return sys.platform + ": " + name + ": " \
1831
+ ' '.join(map(str, exception.args))
1932

2033

2134
def transactionTest(card):
35+
"""Submit a simple JSON-based request to the Notecard.
36+
37+
Args:
38+
card (object): An instance of the Notecard class
39+
40+
"""
2241
req = {"req": "card.status"}
2342
req["string"] = "string"
2443
req["bool"] = True
@@ -34,6 +53,7 @@ def transactionTest(card):
3453

3554

3655
def main():
56+
"""Connect to Notcard and run a transaction test."""
3757
print("Opening port...")
3858
try:
3959
if use_uart:

examples/rpi-example.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
"""note-python Raspberry Pi example.
2+
3+
This file contains a complete working sample for using the note-python
4+
library on a Raspberry Pi device.
5+
"""
16
import sys
27
import os
38
import time
@@ -19,12 +24,26 @@
1924

2025

2126
def NotecardExceptionInfo(exception):
27+
"""Construct a formatted Exception string.
28+
29+
Args:
30+
exception (Exception): An exception object.
31+
32+
Returns:
33+
string: a summary of the exception with line number and details.
34+
"""
2235
s1 = '{}'.format(sys.exc_info()[-1].tb_lineno)
2336
s2 = exception.__class__.__name__
2437
return "line " + s1 + ": " + s2 + ": " + ' '.join(map(str, exception.args))
2538

2639

2740
def transactionTest(card):
41+
"""Submit a simple JSON-based request to the Notecard.
42+
43+
Args:
44+
card (object): An instance of the Notecard class
45+
46+
"""
2847
req = {"req": "card.status"}
2948
req["string"] = "string"
3049
req["bool"] = True
@@ -40,6 +59,7 @@ def transactionTest(card):
4059

4160

4261
def main():
62+
"""Connect to Notcard and run a transaction test."""
4363
print("Opening port...")
4464
try:
4565
if use_uart:

examples/serial-example.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
"""note-python Serial example.
2+
3+
This file contains a complete working sample for using the note-python
4+
library with a Serial Notecard connection.
5+
"""
16
import sys
27
import os
38
import time
@@ -20,12 +25,26 @@
2025

2126

2227
def NotecardExceptionInfo(exception):
28+
"""Construct a formatted Exception string.
29+
30+
Args:
31+
exception (Exception): An exception object.
32+
33+
Returns:
34+
string: a summary of the exception with line number and details.
35+
"""
2336
s1 = '{}'.format(sys.exc_info()[-1].tb_lineno)
2437
s2 = exception.__class__.__name__
2538
return "line " + s1 + ": " + s2 + ": " + ' '.join(map(str, exception.args))
2639

2740

2841
def transactionTest(card):
42+
"""Submit a simple JSON-based request to the Notecard.
43+
44+
Args:
45+
card (object): An instance of the Notecard class
46+
47+
"""
2948
req = {"req": "card.status"}
3049
req["string"] = "string"
3150
req["bool"] = True
@@ -41,6 +60,7 @@ def transactionTest(card):
4160

4261

4362
def main():
63+
"""Connect to Notcard and run a transaction test."""
4464
print("Opening port...")
4565
try:
4666
if sys.platform == "linux" or sys.platform == "linux2":

notecard/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
"""__init__ Module for note-python."""
2+
13
from .notecard import *

notecard/card.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
1+
"""card Fluent API Helper.
2+
3+
This module contains helper methods for calling card.*
4+
Notecard API commands.
5+
"""
16
import notecard
27

38

49
def attn(card, mode=None, files=None, seconds=None):
10+
"""Configure interrupt detection between a host and Notecard.
11+
12+
Args:
13+
mode (string): The attn mode to set.
14+
files (array): A collection of notefiles to watch.
15+
seconds (int): A timeout to use when arming attn mode.
16+
17+
Returns:
18+
string: The result of the Notecard request.
19+
"""
520
if not isinstance(card, notecard.Notecard):
621
raise Exception("Notecard object required")
722

@@ -16,6 +31,11 @@ def attn(card, mode=None, files=None, seconds=None):
1631

1732

1833
def time(card):
34+
"""Retrieve the current time and date from the Notecard.
35+
36+
Returns:
37+
string: The result of the Notecard request.
38+
"""
1939
if not isinstance(card, notecard.Notecard):
2040
raise Exception("Notecard object required")
2141

@@ -24,6 +44,11 @@ def time(card):
2444

2545

2646
def status(card):
47+
"""Retrieve the status of the Notecard.
48+
49+
Returns:
50+
string: The result of the Notecard request.
51+
"""
2752
if not isinstance(card, notecard.Notecard):
2853
raise Exception("Notecard object required")
2954

@@ -32,6 +57,11 @@ def status(card):
3257

3358

3459
def temp(card):
60+
"""Retrieve the current temperature from the Notecard.
61+
62+
Returns:
63+
string: The result of the Notecard request.
64+
"""
3565
if not isinstance(card, notecard.Notecard):
3666
raise Exception("Notecard object required")
3767

@@ -40,6 +70,11 @@ def temp(card):
4070

4171

4272
def version(card):
73+
"""Retrieve firmware version] information from the Notecard.
74+
75+
Returns:
76+
string: The result of the Notecard request.
77+
"""
4378
if not isinstance(card, notecard.Notecard):
4479
raise Exception("Notecard object required")
4580

@@ -48,6 +83,17 @@ def version(card):
4883

4984

5085
def voltage(card, hours=None, offset=None, vmax=None, vmin=None):
86+
"""Retrive current and historical voltage info from the Notecard.
87+
88+
Args:
89+
hours (int): Number of hours to analyze.
90+
offset (int): Number of hours to offset.
91+
vmax (decimal): max voltage level to report.
92+
vmin (decimal): min voltage level to report.
93+
94+
Returns:
95+
string: The result of the Notecard request.
96+
"""
5197
if not isinstance(card, notecard.Notecard):
5298
raise Exception("Notecard object required")
5399

@@ -64,6 +110,14 @@ def voltage(card, hours=None, offset=None, vmax=None, vmin=None):
64110

65111

66112
def wireless(card, mode=None):
113+
"""Retrive wireless modem info or customize modem behavior.
114+
115+
Args:
116+
mode (string): The wireless module mode to set.
117+
118+
Returns:
119+
string: The result of the Notecard request.
120+
"""
67121
if not isinstance(card, notecard.Notecard):
68122
raise Exception("Notecard object required")
69123

notecard/env.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
1+
"""env Fluent API Helper.
2+
3+
This module contains helper methods for calling env.*
4+
Notecard API commands.
5+
"""
16
import notecard
27

38

49
def get(card, name=None):
10+
"""Perform an env.get request against a Notecard.
11+
12+
Args:
13+
name (string): The name of an environment variable to get.
14+
15+
Returns:
16+
string: The result of the Notecard request.
17+
"""
518
if not isinstance(card, notecard.Notecard):
619
raise Exception("Notecard object required")
720

0 commit comments

Comments
 (0)