Skip to content

Commit 239795b

Browse files
committed
Switch from black to ruff for formatting
1 parent a34b26e commit 239795b

File tree

12 files changed

+47
-60
lines changed

12 files changed

+47
-60
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,17 @@ jobs:
3535

3636
format:
3737
runs-on: ubuntu-24.04
38-
name: Check code formatting with black
38+
name: Check code formatting with ruff
3939
steps:
4040
- uses: actions/checkout@v3
4141
- name: Setup python
4242
uses: actions/setup-python@v4
4343
with:
4444
python-version: 3.12
45-
- name: Install black
46-
run: pip install black~=25.1
45+
- name: Install ruff
46+
run: pip install ruff~=0.11.2
4747
- name: Check code formatting
48-
run: black --check .
48+
run: ruff format --check --diff
4949

5050
lint:
5151
runs-on: ubuntu-24.04

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ Then run the tests:
124124
Coding Guidelines
125125
=================
126126

127-
Please reformat your code using `black <https://black.readthedocs.io/>`_::
127+
Please reformat your code using `ruff format <https://docs.astral.sh/ruff/formatter/>`_::
128128

129-
black .
129+
ruff format
130130

131131

132132
About HD44780

RPLCD/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def __new__(cls, *args, **kwargs):
1111
from .gpio import CharLCD as GpioCharLCD
1212

1313
warnings.warn(
14-
"Using RPLCD.CharLCD directly is deprecated. Use RPLCD.gpio.CharLCD instead!",
14+
'Using RPLCD.CharLCD directly is deprecated. Use RPLCD.gpio.CharLCD instead!',
1515
DeprecationWarning,
1616
)
1717
return GpioCharLCD(*args, **kwargs)

RPLCD/i2c.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ def __init__(
148148
if expander_params is None:
149149
if self._i2c_expander == 'MCP23017':
150150
raise ValueError(
151-
'MCP23017: expander_params[\'gpio_bank\'] is not defined, '
152-
'must be either \'A\' or \'B\''
151+
"MCP23017: expander_params['gpio_bank'] is not defined, "
152+
"must be either 'A' or 'B'"
153153
)
154154
else:
155155
self._expander_params = {}
@@ -160,8 +160,8 @@ def __init__(
160160
self._expander_params['gpio_bank'] = expander_params['gpio_bank']
161161
else:
162162
raise ValueError(
163-
'MCP23017: expander_params[\'gpio_bank\'] is \'%s\', '
164-
'must be either \'A\' or \'B\'' % expander_params['gpio_bank']
163+
"MCP23017: expander_params['gpio_bank'] is '%s', "
164+
"must be either 'A' or 'B'" % expander_params['gpio_bank']
165165
)
166166

167167
# Currently the I2C mode only supports 4 bit communication

RPLCD/lcd.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333

3434

3535
class BaseCharLCD(object):
36-
3736
# Init, setup, teardown
3837

3938
def __init__(self, cols=20, rows=4, dotsize=8, charmap='A02', auto_linebreaks=True):
@@ -284,7 +283,6 @@ def write_string(self, value):
284283
ignored = False
285284

286285
for [char, lookahead] in c.sliding_window(encoded, lookahead=1):
287-
288286
# If the previous character has been ignored, skip this one too.
289287
if ignored is True:
290288
ignored = False

RPLCD/pigpio.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,6 @@ def _init_connection(self):
258258
self._writescript = self.pi.store_script(bytes(piscript, 'utf-8'))
259259

260260
def _close_connection(self):
261-
262261
while self.pi.script_status(self._writescript) == pigpio.PI_SCRIPT_RUNNING:
263262
c.msleep(10)
264263
self.pi.delete_script(self._writescript)

RPLCD_Tests/entrypoint.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ def print_usage(error=None):
7272

7373
# Options for GPIO mode
7474
elif (len(sys.argv) > 1) and (sys.argv[1] == 'gpio'):
75-
7675
print('<options> gpio options:')
7776
print('')
7877
print(' mode - GPIO numbering mode, either BOARD or BCM')
@@ -98,7 +97,6 @@ def print_usage(error=None):
9897
)
9998
# Options for PIGPIO mode
10099
elif (len(sys.argv) > 1) and (sys.argv[1] == 'pigpio'):
101-
102100
print('<options> pigpio options:')
103101
print('')
104102
print(' host - Host name of the Pi on which the pigpio daemon is running.')
@@ -142,11 +140,11 @@ def print_usage(error=None):
142140

143141

144142
def options_pop(value, default=no_default):
145-
'''Pops value from options with error checking
143+
"""Pops value from options with error checking
146144
value: which option to pop and check.
147145
default: optional, sets a default if not defined.
148146
returns: a string corresponding to the option on the command line
149-
'''
147+
"""
150148
global options
151149
try:
152150
# If no default value is defined
@@ -161,7 +159,7 @@ def options_pop(value, default=no_default):
161159
except Exception as e:
162160
raise e
163161
if return_value == '':
164-
print_usage('Option %s can\'t be blank.' % value)
162+
print_usage("Option %s can't be blank." % value)
165163
return return_value
166164

167165

@@ -184,7 +182,6 @@ def run():
184182
rows = int(options_pop('rows'))
185183
charmap = options_pop('charmap', 'A00')
186184
if lcdmode == 'i2c':
187-
188185
from RPLCD import i2c
189186

190187
if len(sys.argv) < 5:
@@ -210,7 +207,6 @@ def run():
210207
'or device not connected properly'
211208
)
212209
elif lcdmode == 'gpio':
213-
214210
import RPi.GPIO as GPIO
215211
from RPLCD import gpio
216212

@@ -251,7 +247,6 @@ def run():
251247
charmap=charmap,
252248
)
253249
elif lcdmode == 'pigpio':
254-
255250
from pigpio import pi
256251
from RPLCD import pigpio
257252

@@ -308,4 +303,4 @@ def run():
308303
else:
309304
print_usage('%sx%s displays are not supported in this test.' % (cols, rows))
310305
else:
311-
print_usage('Test \'%s\' is not supported.' % test)
306+
print_usage("Test '%s' is not supported." % test)

RPLCD_Tests/show_charmap.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626

2727
def run(lcd, rows, cols):
28-
2928
print('This tool shows the character map of your LCD on the display.')
3029
print('Press ctrl+c at any time to abort.\n')
3130

RPLCD_Tests/testsuite_16x2.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424

2525
def run(lcd):
26-
2726
lcd.backlight = True
2827
input('Display should be blank. ')
2928

RPLCD_Tests/testsuite_20x4.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424

2525
def run(lcd):
26-
2726
lcd.backlight = True
2827
input('Display should be blank. ')
2928

0 commit comments

Comments
 (0)