Skip to content

Commit 57a4500

Browse files
authored
Merge pull request #27 from adafruit/pylint-update
Ran black, updated to pylint 2.x
2 parents 085582b + 4d08718 commit 57a4500

File tree

6 files changed

+119
-93
lines changed

6 files changed

+119
-93
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_pca9685.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,10 @@
5757
from adafruit_register.i2c_struct_array import StructArray
5858
from adafruit_bus_device import i2c_device
5959

60+
6061
class PWMChannel:
6162
"""A single PCA9685 channel that matches the :py:class:`~pulseio.PWMOut` API."""
63+
6264
def __init__(self, pca, index):
6365
self._pca = pca
6466
self._index = index
@@ -80,23 +82,25 @@ def duty_cycle(self):
8082
always be high, 0 will always be low and 0x7fff will be half high and then half low."""
8183
pwm = self._pca.pwm_regs[self._index]
8284
if pwm[0] == 0x1000:
83-
return 0xffff
85+
return 0xFFFF
8486
return pwm[1] << 4
8587

8688
@duty_cycle.setter
8789
def duty_cycle(self, value):
88-
if not 0 <= value <= 0xffff:
90+
if not 0 <= value <= 0xFFFF:
8991
raise ValueError("Out of range")
9092

91-
if value == 0xffff:
93+
if value == 0xFFFF:
9294
self._pca.pwm_regs[self._index] = (0x1000, 0)
9395
else:
9496
# Shift our value by four because the PCA9685 is only 12 bits but our value is 16
9597
value = (value + 1) >> 4
9698
self._pca.pwm_regs[self._index] = (0, value)
9799

98-
class PCAChannels: # pylint: disable=too-few-public-methods
100+
101+
class PCAChannels: # pylint: disable=too-few-public-methods
99102
"""Lazily creates and caches channel objects as needed. Treat it like a sequence."""
103+
100104
def __init__(self, pca):
101105
self._pca = pca
102106
self._channels = [None] * len(self)
@@ -109,6 +113,7 @@ def __getitem__(self, index):
109113
self._channels[index] = PWMChannel(self._pca, index)
110114
return self._channels[index]
111115

116+
112117
class PCA9685:
113118
"""
114119
Initialise the PCA9685 chip at ``address`` on ``i2c_bus``.
@@ -122,10 +127,11 @@ class PCA9685:
122127
:param int address: The I2C address of the PCA9685.
123128
:param int reference_clock_speed: The frequency of the internal reference clock in Hertz.
124129
"""
130+
125131
# Registers:
126-
mode1_reg = UnaryStruct(0x00, '<B')
127-
prescale_reg = UnaryStruct(0xFE, '<B')
128-
pwm_regs = StructArray(0x06, '<HH', 16)
132+
mode1_reg = UnaryStruct(0x00, "<B")
133+
prescale_reg = UnaryStruct(0xFE, "<B")
134+
pwm_regs = StructArray(0x06, "<HH", 16)
129135

130136
def __init__(self, i2c_bus, *, address=0x40, reference_clock_speed=25000000):
131137
self.i2c_device = i2c_device.I2CDevice(i2c_bus, address)
@@ -137,7 +143,7 @@ def __init__(self, i2c_bus, *, address=0x40, reference_clock_speed=25000000):
137143

138144
def reset(self):
139145
"""Reset the chip."""
140-
self.mode1_reg = 0x00 # Mode1
146+
self.mode1_reg = 0x00 # Mode1
141147

142148
@property
143149
def frequency(self):
@@ -149,12 +155,12 @@ def frequency(self, freq):
149155
prescale = int(self.reference_clock_speed / 4096.0 / freq + 0.5)
150156
if prescale < 3:
151157
raise ValueError("PCA9685 cannot output at the given frequency")
152-
old_mode = self.mode1_reg # Mode 1
153-
self.mode1_reg = (old_mode & 0x7F) | 0x10 # Mode 1, sleep
154-
self.prescale_reg = prescale # Prescale
155-
self.mode1_reg = old_mode # Mode 1
158+
old_mode = self.mode1_reg # Mode 1
159+
self.mode1_reg = (old_mode & 0x7F) | 0x10 # Mode 1, sleep
160+
self.prescale_reg = prescale # Prescale
161+
self.mode1_reg = old_mode # Mode 1
156162
time.sleep(0.005)
157-
self.mode1_reg = old_mode | 0xa1 # Mode 1, autoincrement on
163+
self.mode1_reg = old_mode | 0xA1 # Mode 1, autoincrement on
158164

159165
def __enter__(self):
160166
return self

docs/conf.py

Lines changed: 68 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,53 @@
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.viewcode',
14+
"sphinx.ext.autodoc",
15+
"sphinx.ext.intersphinx",
16+
"sphinx.ext.viewcode",
1617
]
1718

18-
intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'BusDevice': ('https://circuitpython.readthedocs.io/projects/busdevice/en/latest/', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)}
19+
intersphinx_mapping = {
20+
"python": ("https://docs.python.org/3.4", None),
21+
"BusDevice": (
22+
"https://circuitpython.readthedocs.io/projects/busdevice/en/latest/",
23+
None,
24+
),
25+
"CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None),
26+
}
1927

2028
# Libraries we depend on but don't need for generating docs.
2129
# autodoc_mock_imports = ['adafruit_bus_device', 'adafruit_register']
2230

2331
# Add any paths that contain templates here, relative to this directory.
24-
templates_path = ['_templates']
32+
templates_path = ["_templates"]
2533

26-
source_suffix = '.rst'
34+
source_suffix = ".rst"
2735

2836
# The master toctree document.
29-
master_doc = 'index'
37+
master_doc = "index"
3038

3139
# General information about the project.
32-
project = u'Adafruit PCA9685 Library'
33-
copyright = u'2016 Radomir Dopieralski, 2017 Scott Shawcroft'
34-
author = u'Radomir Dopieralski'
40+
project = u"Adafruit PCA9685 Library"
41+
copyright = u"2016 Radomir Dopieralski, 2017 Scott Shawcroft"
42+
author = u"Radomir Dopieralski"
3543

3644
# The version info for the project you're documenting, acts as replacement for
3745
# |version| and |release|, also used in various other places throughout the
3846
# built documents.
3947
#
4048
# The short X.Y version.
41-
version = u'1.0'
49+
version = u"1.0"
4250
# The full version, including alpha/beta/rc tags.
43-
release = u'1.0'
51+
release = u"1.0"
4452

4553
# The language for content autogenerated by Sphinx. Refer to documentation
4654
# for a list of supported languages.
@@ -52,7 +60,7 @@
5260
# List of patterns, relative to source directory, that match files and
5361
# directories to ignore when looking for source files.
5462
# This patterns also effect to html_static_path and html_extra_path
55-
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '.env', 'CODE_OF_CONDUCT.md']
63+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", ".env", "CODE_OF_CONDUCT.md"]
5664

5765
# The reST default role (used for this markup: `text`) to use for all
5866
# documents.
@@ -64,7 +72,7 @@
6472
add_function_parentheses = True
6573

6674
# The name of the Pygments (syntax highlighting) style to use.
67-
pygments_style = 'sphinx'
75+
pygments_style = "sphinx"
6876

6977
# If true, `todo` and `todoList` produce output, else they produce nothing.
7078
todo_include_todos = False
@@ -78,68 +86,76 @@
7886
# The theme to use for HTML and HTML Help pages. See the documentation for
7987
# a list of builtin themes.
8088
#
81-
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
89+
on_rtd = os.environ.get("READTHEDOCS", None) == "True"
8290

8391
if not on_rtd: # only import and set the theme if we're building docs locally
8492
try:
8593
import sphinx_rtd_theme
86-
html_theme = 'sphinx_rtd_theme'
87-
html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), '.']
94+
95+
html_theme = "sphinx_rtd_theme"
96+
html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."]
8897
except:
89-
html_theme = 'default'
90-
html_theme_path = ['.']
98+
html_theme = "default"
99+
html_theme_path = ["."]
91100
else:
92-
html_theme_path = ['.']
101+
html_theme_path = ["."]
93102

94103
# Add any paths that contain custom static files (such as style sheets) here,
95104
# relative to this directory. They are copied after the builtin static files,
96105
# so a file named "default.css" will overwrite the builtin "default.css".
97-
html_static_path = ['_static']
106+
html_static_path = ["_static"]
98107

99108
# The name of an image file (relative to this directory) to use as a favicon of
100109
# the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
101110
# pixels large.
102111
#
103-
html_favicon = '_static/favicon.ico'
112+
html_favicon = "_static/favicon.ico"
104113

105114
# Output file base name for HTML help builder.
106-
htmlhelp_basename = 'AdafruitPCA9685Librarydoc'
115+
htmlhelp_basename = "AdafruitPCA9685Librarydoc"
107116

108117
# -- Options for LaTeX output ---------------------------------------------
109118

110119
latex_elements = {
111-
# The paper size ('letterpaper' or 'a4paper').
112-
#
113-
# 'papersize': 'letterpaper',
114-
115-
# The font size ('10pt', '11pt' or '12pt').
116-
#
117-
# 'pointsize': '10pt',
118-
119-
# Additional stuff for the LaTeX preamble.
120-
#
121-
# 'preamble': '',
122-
123-
# Latex figure (float) alignment
124-
#
125-
# 'figure_align': 'htbp',
120+
# The paper size ('letterpaper' or 'a4paper').
121+
#
122+
# 'papersize': 'letterpaper',
123+
# The font size ('10pt', '11pt' or '12pt').
124+
#
125+
# 'pointsize': '10pt',
126+
# Additional stuff for the LaTeX preamble.
127+
#
128+
# 'preamble': '',
129+
# Latex figure (float) alignment
130+
#
131+
# 'figure_align': 'htbp',
126132
}
127133

128134
# Grouping the document tree into LaTeX files. List of tuples
129135
# (source start file, target name, title,
130136
# author, documentclass [howto, manual, or own class]).
131137
latex_documents = [
132-
(master_doc, 'AdafruitPCA9685Library.tex', u'Adafruit PCA9685 Library Documentation',
133-
author, 'manual'),
138+
(
139+
master_doc,
140+
"AdafruitPCA9685Library.tex",
141+
u"Adafruit PCA9685 Library Documentation",
142+
author,
143+
"manual",
144+
),
134145
]
135146

136147
# -- Options for manual page output ---------------------------------------
137148

138149
# One entry per manual page. List of tuples
139150
# (source start file, name, description, authors, manual section).
140151
man_pages = [
141-
(master_doc, 'adafruitPCA9685library', u'Adafruit PCA9685 Library Documentation',
142-
[author], 1)
152+
(
153+
master_doc,
154+
"adafruitPCA9685library",
155+
u"Adafruit PCA9685 Library Documentation",
156+
[author],
157+
1,
158+
)
143159
]
144160

145161
# -- Options for Texinfo output -------------------------------------------
@@ -148,7 +164,13 @@
148164
# (source start file, target name, title, author,
149165
# dir menu entry, description, category)
150166
texinfo_documents = [
151-
(master_doc, 'AdafruitPCA9685Library', u'Adafruit PCA9685 Library Documentation',
152-
author, 'AdafruitPCA9685Library', 'One line description of project.',
153-
'Miscellaneous'),
167+
(
168+
master_doc,
169+
"AdafruitPCA9685Library",
170+
u"Adafruit PCA9685 Library Documentation",
171+
author,
172+
"AdafruitPCA9685Library",
173+
"One line description of project.",
174+
"Miscellaneous",
175+
),
154176
]

examples/pca9685_calibration.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,21 @@
2525
# Set the PWM duty cycle for channel zero to 50%. duty_cycle is 16 bits to match other PWM objects
2626
# but the PCA9685 will only actually give 12 bits of resolution.
2727
print("Running with default calibration")
28-
pca.channels[0].duty_cycle = 0x7fff
28+
pca.channels[0].duty_cycle = 0x7FFF
2929
time.sleep(1)
3030
pca.channels[0].duty_cycle = 0
3131

3232
measured_frequency = float(input("Frequency measured: "))
3333
print()
3434

35-
pca.reference_clock_speed = pca.reference_clock_speed * (measured_frequency / pca.frequency)
35+
pca.reference_clock_speed = pca.reference_clock_speed * (
36+
measured_frequency / pca.frequency
37+
)
3638
# Set frequency again so we can get closer. Reading it back will produce the real value.
3739
pca.frequency = 100
3840

3941
input("Press enter when ready to measure coarse calibration frequency.")
40-
pca.channels[0].duty_cycle = 0x7fff
42+
pca.channels[0].duty_cycle = 0x7FFF
4143
time.sleep(1)
4244
pca.channels[0].duty_cycle = 0
4345
measured_after_calibration = float(input("Frequency measured: "))

examples/pca9685_simpletest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@
1818

1919
# Set the PWM duty cycle for channel zero to 50%. duty_cycle is 16 bits to match other PWM objects
2020
# but the PCA9685 will only actually give 12 bits of resolution.
21-
pca.channels[0].duty_cycle = 0x7fff
21+
pca.channels[0].duty_cycle = 0x7FFF

0 commit comments

Comments
 (0)