Skip to content

Commit 0111721

Browse files
authored
Merge pull request #36 from adafruit/pylint-update
Ran black, updated to pylint 2.x
2 parents 525c273 + 2dc7d0b commit 0111721

13 files changed

+329
-267
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
source actions-ci/install.sh
4141
- name: Pip install pylint, black, & Sphinx
4242
run: |
43-
pip install --force-reinstall pylint==1.9.2 black==19.10b0 Sphinx sphinx-rtd-theme
43+
pip install --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme
4444
- name: Library version
4545
run: git describe --dirty --always --tags
4646
- name: PyLint

adafruit_espatcontrol/adafruit_espatcontrol.py

Lines changed: 130 additions & 106 deletions
Large diffs are not rendered by default.
Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
"""A 'socket' compatible interface thru the ESP AT command set"""
22
from micropython import const
33

4-
_the_interface = None # pylint: disable=invalid-name
4+
_the_interface = None # pylint: disable=invalid-name
5+
6+
57
def set_interface(iface):
68
"""Helper to set the global internet interface"""
7-
global _the_interface # pylint: disable=global-statement, invalid-name
9+
global _the_interface # pylint: disable=global-statement, invalid-name
810
_the_interface = iface
911

12+
1013
SOCK_STREAM = const(1)
1114
AF_INET = const(2)
1215

@@ -17,42 +20,46 @@ def getaddrinfo(host, port, family=0, socktype=0, proto=0, flags=0):
1720
if not isinstance(port, int):
1821
raise RuntimeError("port must be an integer")
1922
ipaddr = _the_interface.nslookup(host)
20-
return [(AF_INET, socktype, proto, '', (ipaddr, port))]
23+
return [(AF_INET, socktype, proto, "", (ipaddr, port))]
24+
25+
2126
# pylint: enable=too-many-arguments, unused-argument
2227

2328

2429
# pylint: disable=unused-argument, redefined-builtin, invalid-name
2530
class socket:
2631
"""A simplified implementation of the Python 'socket' class, for connecting
2732
through an interface to a remote device"""
33+
2834
def __init__(self, family=AF_INET, type=SOCK_STREAM, proto=0, fileno=None):
2935
if family != AF_INET:
3036
raise RuntimeError("Only AF_INET family supported")
3137
if type != SOCK_STREAM:
3238
raise RuntimeError("Only SOCK_STREAM type supported")
33-
self._buffer = b''
39+
self._buffer = b""
3440
self.settimeout(0)
3541

3642
def connect(self, address, conntype=None):
3743
"""Connect the socket to the 'address' (which should be dotted quad IP). 'conntype'
3844
is an extra that may indicate SSL or not, depending on the underlying interface"""
3945
host, port = address
40-
if not _the_interface.socket_connect(conntype, host, port, keepalive=10, retries=3):
46+
if not _the_interface.socket_connect(
47+
conntype, host, port, keepalive=10, retries=3
48+
):
4149
raise RuntimeError("Failed to connect to host", host)
42-
self._buffer = b''
50+
self._buffer = b""
4351

44-
45-
def send(self, data): # pylint: disable=no-self-use
52+
def send(self, data): # pylint: disable=no-self-use
4653
"""Send some data to the socket"""
4754
_the_interface.socket_send(data)
4855

4956
def readline(self):
5057
"""Attempt to return as many bytes as we can up to but not including '\r\n'"""
51-
if b'\r\n' not in self._buffer:
58+
if b"\r\n" not in self._buffer:
5259
# there's no line already in there, read some more
5360
self._buffer = self._buffer + _the_interface.socket_receive(timeout=3)
54-
#print(self._buffer)
55-
firstline, self._buffer = self._buffer.split(b'\r\n', 1)
61+
# print(self._buffer)
62+
firstline, self._buffer = self._buffer.split(b"\r\n", 1)
5663
return firstline
5764

5865
def recv(self, num=0):
@@ -61,7 +68,7 @@ def recv(self, num=0):
6168
if num == 0:
6269
# read as much as we can
6370
ret = self._buffer + _the_interface.socket_receive(timeout=self._timeout)
64-
self._buffer = b''
71+
self._buffer = b""
6572
else:
6673
ret = self._buffer[:num]
6774
self._buffer = self._buffer[num:]
@@ -70,11 +77,14 @@ def recv(self, num=0):
7077
def close(self):
7178
"""Close the socket, after reading whatever remains"""
7279
# read whatever's left
73-
self._buffer = self._buffer + _the_interface.socket_receive(timeout=self._timeout)
80+
self._buffer = self._buffer + _the_interface.socket_receive(
81+
timeout=self._timeout
82+
)
7483
_the_interface.socket_disconnect()
7584

7685
def settimeout(self, value):
7786
"""Set the read timeout for sockets, if value is 0 it will block"""
7887
self._timeout = value
7988

89+
8090
# pylint: enable=unused-argument, redefined-builtin, invalid-name

adafruit_espatcontrol/adafruit_espatcontrol_wifimanager.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@
3434
import adafruit_espatcontrol.adafruit_espatcontrol_socket as socket
3535
import adafruit_requests as requests
3636

37+
3738
class ESPAT_WiFiManager:
3839
"""
3940
A class to help manage the Wifi connection
4041
"""
42+
4143
def __init__(self, esp, secrets, status_pixel=None, attempts=2):
4244
"""
4345
:param ESP_SPIcontrol esp: The ESP object we are using

docs/conf.py

Lines changed: 65 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22

33
import os
44
import sys
5-
sys.path.insert(0, os.path.abspath('..'))
5+
6+
sys.path.insert(0, os.path.abspath(".."))
67

78
# -- General configuration ------------------------------------------------
89

910
# Add any Sphinx extension module names here, as strings. They can be
1011
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
1112
# ones.
1213
extensions = [
13-
'sphinx.ext.autodoc',
14-
'sphinx.ext.intersphinx',
15-
'sphinx.ext.napoleon',
16-
'sphinx.ext.todo',
14+
"sphinx.ext.autodoc",
15+
"sphinx.ext.intersphinx",
16+
"sphinx.ext.napoleon",
17+
"sphinx.ext.todo",
1718
]
1819

1920
# TODO: Please Read!
@@ -23,29 +24,32 @@
2324
# autodoc_mock_imports = ["digitalio", "busio"]
2425

2526

26-
intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)}
27+
intersphinx_mapping = {
28+
"python": ("https://docs.python.org/3.4", None),
29+
"CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None),
30+
}
2731

2832
# Add any paths that contain templates here, relative to this directory.
29-
templates_path = ['_templates']
33+
templates_path = ["_templates"]
3034

31-
source_suffix = '.rst'
35+
source_suffix = ".rst"
3236

3337
# The master toctree document.
34-
master_doc = 'index'
38+
master_doc = "index"
3539

3640
# General information about the project.
37-
project = u'Adafruit espATcontrol Library'
38-
copyright = u'2018 ladyada'
39-
author = u'ladyada'
41+
project = u"Adafruit espATcontrol Library"
42+
copyright = u"2018 ladyada"
43+
author = u"ladyada"
4044

4145
# The version info for the project you're documenting, acts as replacement for
4246
# |version| and |release|, also used in various other places throughout the
4347
# built documents.
4448
#
4549
# The short X.Y version.
46-
version = u'1.0'
50+
version = u"1.0"
4751
# The full version, including alpha/beta/rc tags.
48-
release = u'1.0'
52+
release = u"1.0"
4953

5054
# The language for content autogenerated by Sphinx. Refer to documentation
5155
# for a list of supported languages.
@@ -57,7 +61,7 @@
5761
# List of patterns, relative to source directory, that match files and
5862
# directories to ignore when looking for source files.
5963
# This patterns also effect to html_static_path and html_extra_path
60-
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '.env', 'CODE_OF_CONDUCT.md']
64+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", ".env", "CODE_OF_CONDUCT.md"]
6165

6266
# The reST default role (used for this markup: `text`) to use for all
6367
# documents.
@@ -69,7 +73,7 @@
6973
add_function_parentheses = True
7074

7175
# The name of the Pygments (syntax highlighting) style to use.
72-
pygments_style = 'sphinx'
76+
pygments_style = "sphinx"
7377

7478
# If true, `todo` and `todoList` produce output, else they produce nothing.
7579
todo_include_todos = False
@@ -84,68 +88,76 @@
8488
# The theme to use for HTML and HTML Help pages. See the documentation for
8589
# a list of builtin themes.
8690
#
87-
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
91+
on_rtd = os.environ.get("READTHEDOCS", None) == "True"
8892

8993
if not on_rtd: # only import and set the theme if we're building docs locally
9094
try:
9195
import sphinx_rtd_theme
92-
html_theme = 'sphinx_rtd_theme'
93-
html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), '.']
96+
97+
html_theme = "sphinx_rtd_theme"
98+
html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."]
9499
except:
95-
html_theme = 'default'
96-
html_theme_path = ['.']
100+
html_theme = "default"
101+
html_theme_path = ["."]
97102
else:
98-
html_theme_path = ['.']
103+
html_theme_path = ["."]
99104

100105
# Add any paths that contain custom static files (such as style sheets) here,
101106
# relative to this directory. They are copied after the builtin static files,
102107
# so a file named "default.css" will overwrite the builtin "default.css".
103-
html_static_path = ['_static']
108+
html_static_path = ["_static"]
104109

105110
# The name of an image file (relative to this directory) to use as a favicon of
106111
# the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
107112
# pixels large.
108113
#
109-
html_favicon = '_static/favicon.ico'
114+
html_favicon = "_static/favicon.ico"
110115

111116
# Output file base name for HTML help builder.
112-
htmlhelp_basename = 'AdafruitEspatcontrolLibrarydoc'
117+
htmlhelp_basename = "AdafruitEspatcontrolLibrarydoc"
113118

114119
# -- Options for LaTeX output ---------------------------------------------
115120

116121
latex_elements = {
117-
# The paper size ('letterpaper' or 'a4paper').
118-
#
119-
# 'papersize': 'letterpaper',
120-
121-
# The font size ('10pt', '11pt' or '12pt').
122-
#
123-
# 'pointsize': '10pt',
124-
125-
# Additional stuff for the LaTeX preamble.
126-
#
127-
# 'preamble': '',
128-
129-
# Latex figure (float) alignment
130-
#
131-
# 'figure_align': 'htbp',
122+
# The paper size ('letterpaper' or 'a4paper').
123+
#
124+
# 'papersize': 'letterpaper',
125+
# The font size ('10pt', '11pt' or '12pt').
126+
#
127+
# 'pointsize': '10pt',
128+
# Additional stuff for the LaTeX preamble.
129+
#
130+
# 'preamble': '',
131+
# Latex figure (float) alignment
132+
#
133+
# 'figure_align': 'htbp',
132134
}
133135

134136
# Grouping the document tree into LaTeX files. List of tuples
135137
# (source start file, target name, title,
136138
# author, documentclass [howto, manual, or own class]).
137139
latex_documents = [
138-
(master_doc, 'AdafruitespATcontrolLibrary.tex', u'AdafruitespATcontrol Library Documentation',
139-
author, 'manual'),
140+
(
141+
master_doc,
142+
"AdafruitespATcontrolLibrary.tex",
143+
u"AdafruitespATcontrol Library Documentation",
144+
author,
145+
"manual",
146+
),
140147
]
141148

142149
# -- Options for manual page output ---------------------------------------
143150

144151
# One entry per manual page. List of tuples
145152
# (source start file, name, description, authors, manual section).
146153
man_pages = [
147-
(master_doc, 'AdafruitespATcontrollibrary', u'Adafruit espATcontrol Library Documentation',
148-
[author], 1)
154+
(
155+
master_doc,
156+
"AdafruitespATcontrollibrary",
157+
u"Adafruit espATcontrol Library Documentation",
158+
[author],
159+
1,
160+
)
149161
]
150162

151163
# -- Options for Texinfo output -------------------------------------------
@@ -154,7 +166,13 @@
154166
# (source start file, target name, title, author,
155167
# dir menu entry, description, category)
156168
texinfo_documents = [
157-
(master_doc, 'AdafruitespATcontrolLibrary', u'Adafruit espATcontrol Library Documentation',
158-
author, 'AdafruitespATcontrolLibrary', 'One line description of project.',
159-
'Miscellaneous'),
169+
(
170+
master_doc,
171+
"AdafruitespATcontrolLibrary",
172+
u"Adafruit espATcontrol Library Documentation",
173+
author,
174+
"AdafruitespATcontrolLibrary",
175+
"One line description of project.",
176+
"Miscellaneous",
177+
),
160178
]

examples/esp_atcontrol_aio_post.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
from digitalio import Direction
66

77
# ESP32 AT
8-
from adafruit_espatcontrol import adafruit_espatcontrol, adafruit_espatcontrol_wifimanager
9-
8+
from adafruit_espatcontrol import (
9+
adafruit_espatcontrol,
10+
adafruit_espatcontrol_wifimanager,
11+
)
1012

1113

1214
# Get wifi details and more from a secrets.py file
@@ -29,23 +31,29 @@
2931
status_light = None
3032

3133
print("ESP AT commands")
32-
esp = adafruit_espatcontrol.ESP_ATcontrol(uart, 115200,
33-
reset_pin=resetpin, rts_pin=rtspin, debug=False)
34+
esp = adafruit_espatcontrol.ESP_ATcontrol(
35+
uart, 115200, reset_pin=resetpin, rts_pin=rtspin, debug=False
36+
)
3437
wifi = adafruit_espatcontrol_wifimanager.ESPAT_WiFiManager(esp, secrets, status_light)
3538

3639

3740
counter = 0
3841

3942
while True:
4043
try:
41-
print("Posting data...", end='')
44+
print("Posting data...", end="")
4245
data = counter
43-
feed = 'test'
44-
payload = {'value':data}
46+
feed = "test"
47+
payload = {"value": data}
4548
response = wifi.post(
46-
"https://io.adafruit.com/api/v2/"+secrets['aio_username']+"/feeds/"+feed+"/data",
49+
"https://io.adafruit.com/api/v2/"
50+
+ secrets["aio_username"]
51+
+ "/feeds/"
52+
+ feed
53+
+ "/data",
4754
json=payload,
48-
headers={"X-AIO-KEY":secrets['aio_key']})
55+
headers={"X-AIO-KEY": secrets["aio_key"]},
56+
)
4957
print(response.json())
5058
response.close()
5159
counter = counter + 1

0 commit comments

Comments
 (0)