Skip to content

Commit ae18321

Browse files
committed
Black and lint
1 parent 4f5dc63 commit ae18321

File tree

6 files changed

+99
-102
lines changed

6 files changed

+99
-102
lines changed

.pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ confidence=
5252
# no Warning level messages displayed, use"--disable=all --enable=classes
5353
# --disable=W"
5454
# disable=import-error,print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call
55-
disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error
55+
disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error,bad-continuation
5656

5757
# Enable the message, report, category or checker with the given id(s). You can
5858
# either give multiple identifier separated by comma (,) or put this option

adafruit_radio.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,10 @@
4141
"""
4242
import time
4343
import struct
44-
import random
4544
from micropython import const
4645
from adafruit_ble import BLERadio
4746
from adafruit_ble.advertising import Advertisement, LazyObjectField
48-
from adafruit_ble.advertising.standard import ManufacturerData, ManufacturerDataField
47+
from adafruit_ble.advertising.standard import ManufacturerData
4948

5049

5150
__version__ = "0.0.0-auto.0"
@@ -58,21 +57,22 @@
5857
#: Amount of time to advertise a message (in seconds).
5958
AD_DURATION = 0.5
6059

61-
_MANUFACTURING_DATA_ADT = const(0xff)
60+
_MANUFACTURING_DATA_ADT = const(0xFF)
6261
_ADAFRUIT_COMPANY_ID = const(0x0822)
6362
_RADIO_DATA_ID = const(0x0001) # TODO: check this isn't already taken.
6463

64+
6565
class _RadioAdvertisement(Advertisement):
6666
"""Broadcast arbitrary bytes as a radio message."""
67-
prefix = struct.pack("<BBH",
68-
0x3,
69-
0xff,
70-
_ADAFRUIT_COMPANY_ID)
71-
manufacturer_data = LazyObjectField(ManufacturerData,
72-
"manufacturer_data",
73-
advertising_data_type=_MANUFACTURING_DATA_ADT,
74-
company_id=_ADAFRUIT_COMPANY_ID,
75-
key_encoding="<H")
67+
68+
prefix = struct.pack("<BBH", 0x3, 0xFF, _ADAFRUIT_COMPANY_ID)
69+
manufacturer_data = LazyObjectField(
70+
ManufacturerData,
71+
"manufacturer_data",
72+
advertising_data_type=_MANUFACTURING_DATA_ADT,
73+
company_id=_ADAFRUIT_COMPANY_ID,
74+
key_encoding="<H",
75+
)
7676

7777
@classmethod
7878
def matches(cls, entry):
@@ -84,6 +84,7 @@ def matches(cls, entry):
8484

8585
@property
8686
def msg(self):
87+
"""Raw radio data"""
8788
if _RADIO_DATA_ID not in self.manufacturer_data.data:
8889
return b""
8990
return self.manufacturer_data.data[_RADIO_DATA_ID]
@@ -92,6 +93,7 @@ def msg(self):
9293
def msg(self, value):
9394
self.manufacturer_data.data[_RADIO_DATA_ID] = value
9495

96+
9597
class Radio:
9698
"""
9799
Represents a connection through which one can send or receive strings
@@ -143,9 +145,7 @@ def send_bytes(self, message):
143145
"""
144146
# Ensure length of message.
145147
if len(message) > MAX_LENGTH:
146-
raise ValueError(
147-
"Message too long (max length = {})".format(MAX_LENGTH)
148-
)
148+
raise ValueError("Message too long (max length = {})".format(MAX_LENGTH))
149149
advertisement = _RadioAdvertisement()
150150
# Concatenate the bytes that make up the advertised message.
151151
advertisement.msg = struct.pack("<BB", self._channel, self.uid) + message
@@ -166,8 +166,7 @@ def receive(self):
166166
msg = self.receive_full()
167167
if msg:
168168
return msg[0].decode("utf-8").replace("\x00", "")
169-
else:
170-
return None
169+
return None
171170

172171
def receive_full(self):
173172
"""

docs/conf.py

Lines changed: 59 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", "adafruit_ble"]
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 radio Library'
38-
copyright = u'2019 Nicholas H.Tollervey'
39-
author = u'Nicholas H.Tollervey'
41+
project = "Adafruit radio Library"
42+
copyright = "2019 Nicholas H.Tollervey"
43+
author = "Nicholas H.Tollervey"
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 = "1.0"
4751
# The full version, including alpha/beta/rc tags.
48-
release = u'1.0'
52+
release = "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,70 @@
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 = 'AdafruitRadioLibrarydoc'
117+
htmlhelp_basename = "AdafruitRadioLibrarydoc"
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, 'AdafruitradioLibrary.tex', u'Adafruitradio Library Documentation',
139-
author, 'manual'),
140+
(
141+
master_doc,
142+
"AdafruitradioLibrary.tex",
143+
"Adafruitradio 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, 'Adafruitradiolibrary', u'Adafruit radio Library Documentation',
148-
[author], 1)
154+
(master_doc, "Adafruitradiolibrary", "Adafruit radio Library Documentation", [author], 1)
149155
]
150156

151157
# -- Options for Texinfo output -------------------------------------------
@@ -154,7 +160,13 @@
154160
# (source start file, target name, title, author,
155161
# dir menu entry, description, category)
156162
texinfo_documents = [
157-
(master_doc, 'AdafruitradioLibrary', u'Adafruit radio Library Documentation',
158-
author, 'AdafruitradioLibrary', 'One line description of project.',
159-
'Miscellaneous'),
163+
(
164+
master_doc,
165+
"AdafruitradioLibrary",
166+
"Adafruit radio Library Documentation",
167+
author,
168+
"AdafruitradioLibrary",
169+
"One line description of project.",
170+
"Miscellaneous",
171+
),
160172
]

examples/radio_simpletest.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,3 @@
5454
# m = r.receive()
5555
# if m:
5656
# print(m)
57-

setup.py

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,58 +6,48 @@
66
"""
77

88
from setuptools import setup, find_packages
9+
910
# To use a consistent encoding
1011
from codecs import open
1112
from os import path
1213

1314
here = path.abspath(path.dirname(__file__))
1415

1516
# Get the long description from the README file
16-
with open(path.join(here, 'README.rst'), encoding='utf-8') as f:
17+
with open(path.join(here, "README.rst"), encoding="utf-8") as f:
1718
long_description = f.read()
1819

1920
setup(
20-
name='adafruit-circuitpython-radio',
21-
21+
name="adafruit-circuitpython-radio",
2222
use_scm_version=True,
23-
setup_requires=['setuptools_scm'],
24-
25-
description='Simple byte and string based inter-device communication via BLE.',
23+
setup_requires=["setuptools_scm"],
24+
description="Simple byte and string based inter-device communication via BLE.",
2625
long_description=long_description,
27-
long_description_content_type='text/x-rst',
28-
26+
long_description_content_type="text/x-rst",
2927
# The project's main homepage.
30-
url='https://github.com/adafruit/Adafruit_CircuitPython_radio',
31-
28+
url="https://github.com/adafruit/Adafruit_CircuitPython_radio",
3229
# Author details
33-
author='Adafruit Industries',
34-
author_email='[email protected]',
35-
36-
install_requires=[
37-
'adafruit-circuitpython-ble'
38-
],
39-
30+
author="Adafruit Industries",
31+
author_email="[email protected]",
32+
install_requires=["adafruit-circuitpython-ble"],
4033
# Choose your license
41-
license='MIT',
42-
34+
license="MIT",
4335
# See https://pypi.python.org/pypi?%3Aaction=list_classifiers
4436
classifiers=[
45-
'Development Status :: 3 - Alpha',
46-
'Intended Audience :: Developers',
47-
'Topic :: Software Development :: Libraries',
48-
'Topic :: System :: Hardware',
49-
'License :: OSI Approved :: MIT License',
50-
'Programming Language :: Python :: 3',
51-
'Programming Language :: Python :: 3.4',
52-
'Programming Language :: Python :: 3.5',
37+
"Development Status :: 3 - Alpha",
38+
"Intended Audience :: Developers",
39+
"Topic :: Software Development :: Libraries",
40+
"Topic :: System :: Hardware",
41+
"License :: OSI Approved :: MIT License",
42+
"Programming Language :: Python :: 3",
43+
"Programming Language :: Python :: 3.4",
44+
"Programming Language :: Python :: 3.5",
5345
],
54-
5546
# What does your project relate to?
56-
keywords='adafruit blinka circuitpython micropython radio ble',
57-
47+
keywords="adafruit blinka circuitpython micropython radio ble",
5848
# You can just specify the packages manually here if your project is
5949
# simple. Or you can use find_packages().
6050
# TODO: IF LIBRARY FILES ARE A PACKAGE FOLDER,
6151
# CHANGE `py_modules=['...']` TO `packages=['...']`
62-
py_modules=['adafruit_radio'],
52+
py_modules=["adafruit_radio"],
6353
)

tests/test_adafruit_radio.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,7 @@ def test_radio_receive_full_no_messages(radio):
136136
radio.ble.start_scan.return_value = []
137137
assert radio.receive_full() is None
138138
radio.ble.start_scan.assert_called_once_with(
139-
adafruit_radio.AdafruitRadio, minimum_rssi=-255, timeout=1,
140-
extended=True
139+
adafruit_radio.AdafruitRadio, minimum_rssi=-255, timeout=1, extended=True
141140
)
142141
radio.ble.stop_scan.assert_called_once_with()
143142

@@ -170,9 +169,7 @@ def test_radio_receive_full_and_remove_expired_message_metadata(radio):
170169
mock_entry.address.address_bytes = b"adr2"
171170
mock_entry.rssi = -40
172171
radio.ble.start_scan.return_value = [mock_entry]
173-
radio.msg_pool.add(
174-
(time.monotonic() - adafruit_radio.AD_DURATION - 1, 42, 0, b"addr")
175-
)
172+
radio.msg_pool.add((time.monotonic() - adafruit_radio.AD_DURATION - 1, 42, 0, b"addr"))
176173
result = radio.receive_full()
177174
assert result[0] == b"Hello"
178175
assert result[1] == -40

0 commit comments

Comments
 (0)