diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 10b414e..e97cac3 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -35,14 +35,28 @@ jobs:
format:
runs-on: ubuntu-24.04
- name: Check code formatting with black
+ name: Check code formatting with ruff
steps:
- uses: actions/checkout@v3
- name: Setup python
uses: actions/setup-python@v4
with:
python-version: 3.12
- - name: Install black
- run: pip install black~=25.1
+ - name: Install ruff
+ run: pip install ruff~=0.11.2
- name: Check code formatting
- run: black --check .
+ run: ruff format --check --diff
+
+ lint:
+ runs-on: ubuntu-24.04
+ name: Run linting with ruff
+ steps:
+ - uses: actions/checkout@v3
+ - name: Setup python
+ uses: actions/setup-python@v4
+ with:
+ python-version: 3.12
+ - name: Install ruff
+ run: pip install ruff~=0.11.2
+ - name: Run linter
+ run: ruff check
diff --git a/README.rst b/README.rst
index af9b92e..d3f5bf1 100644
--- a/README.rst
+++ b/README.rst
@@ -124,15 +124,9 @@ Then run the tests:
Coding Guidelines
=================
-`PEP8 `__ via `flake8
-`_ with ``max-line-width`` set to 99 and
-``E126-E128,C901`` ignored::
+Please reformat your code using `ruff format `_::
- flake8 --max-line-length=99 --ignore=E126,E127,E128,C901 RPLCD/lcd.py
-
-Additionally, please reformat your code using `black `_::
-
- black .
+ ruff format
About HD44780
diff --git a/RPLCD/__init__.py b/RPLCD/__init__.py
index cd57f62..5bc2ea1 100644
--- a/RPLCD/__init__.py
+++ b/RPLCD/__init__.py
@@ -11,7 +11,7 @@ def __new__(cls, *args, **kwargs):
from .gpio import CharLCD as GpioCharLCD
warnings.warn(
- "Using RPLCD.CharLCD directly is deprecated. Use RPLCD.gpio.CharLCD instead!",
+ 'Using RPLCD.CharLCD directly is deprecated. Use RPLCD.gpio.CharLCD instead!',
DeprecationWarning,
)
return GpioCharLCD(*args, **kwargs)
diff --git a/RPLCD/i2c.py b/RPLCD/i2c.py
index 3f369ef..bb82078 100644
--- a/RPLCD/i2c.py
+++ b/RPLCD/i2c.py
@@ -148,8 +148,8 @@ def __init__(
if expander_params is None:
if self._i2c_expander == 'MCP23017':
raise ValueError(
- 'MCP23017: expander_params[\'gpio_bank\'] is not defined, '
- 'must be either \'A\' or \'B\''
+ "MCP23017: expander_params['gpio_bank'] is not defined, "
+ "must be either 'A' or 'B'"
)
else:
self._expander_params = {}
@@ -160,8 +160,8 @@ def __init__(
self._expander_params['gpio_bank'] = expander_params['gpio_bank']
else:
raise ValueError(
- 'MCP23017: expander_params[\'gpio_bank\'] is \'%s\', '
- 'must be either \'A\' or \'B\'' % expander_params['gpio_bank']
+ "MCP23017: expander_params['gpio_bank'] is '%s', "
+ "must be either 'A' or 'B'" % expander_params['gpio_bank']
)
# Currently the I2C mode only supports 4 bit communication
diff --git a/RPLCD/lcd.py b/RPLCD/lcd.py
index a58ed2d..0d03b55 100644
--- a/RPLCD/lcd.py
+++ b/RPLCD/lcd.py
@@ -33,7 +33,6 @@
class BaseCharLCD(object):
-
# Init, setup, teardown
def __init__(self, cols=20, rows=4, dotsize=8, charmap='A02', auto_linebreaks=True):
@@ -284,7 +283,6 @@ def write_string(self, value):
ignored = False
for [char, lookahead] in c.sliding_window(encoded, lookahead=1):
-
# If the previous character has been ignored, skip this one too.
if ignored is True:
ignored = False
diff --git a/RPLCD/pigpio.py b/RPLCD/pigpio.py
index 0815c7a..ae1147e 100644
--- a/RPLCD/pigpio.py
+++ b/RPLCD/pigpio.py
@@ -258,7 +258,6 @@ def _init_connection(self):
self._writescript = self.pi.store_script(bytes(piscript, 'utf-8'))
def _close_connection(self):
-
while self.pi.script_status(self._writescript) == pigpio.PI_SCRIPT_RUNNING:
c.msleep(10)
self.pi.delete_script(self._writescript)
diff --git a/RPLCD_Tests/entrypoint.py b/RPLCD_Tests/entrypoint.py
index 52ee1e3..dedfdc7 100755
--- a/RPLCD_Tests/entrypoint.py
+++ b/RPLCD_Tests/entrypoint.py
@@ -72,7 +72,6 @@ def print_usage(error=None):
# Options for GPIO mode
elif (len(sys.argv) > 1) and (sys.argv[1] == 'gpio'):
-
print(' gpio options:')
print('')
print(' mode - GPIO numbering mode, either BOARD or BCM')
@@ -98,7 +97,6 @@ def print_usage(error=None):
)
# Options for PIGPIO mode
elif (len(sys.argv) > 1) and (sys.argv[1] == 'pigpio'):
-
print(' pigpio options:')
print('')
print(' host - Host name of the Pi on which the pigpio daemon is running.')
@@ -142,11 +140,11 @@ def print_usage(error=None):
def options_pop(value, default=no_default):
- '''Pops value from options with error checking
+ """Pops value from options with error checking
value: which option to pop and check.
default: optional, sets a default if not defined.
returns: a string corresponding to the option on the command line
- '''
+ """
global options
try:
# If no default value is defined
@@ -161,7 +159,7 @@ def options_pop(value, default=no_default):
except Exception as e:
raise e
if return_value == '':
- print_usage('Option %s can\'t be blank.' % value)
+ print_usage("Option %s can't be blank." % value)
return return_value
@@ -184,7 +182,6 @@ def run():
rows = int(options_pop('rows'))
charmap = options_pop('charmap', 'A00')
if lcdmode == 'i2c':
-
from RPLCD import i2c
if len(sys.argv) < 5:
@@ -210,7 +207,6 @@ def run():
'or device not connected properly'
)
elif lcdmode == 'gpio':
-
import RPi.GPIO as GPIO
from RPLCD import gpio
@@ -251,7 +247,6 @@ def run():
charmap=charmap,
)
elif lcdmode == 'pigpio':
-
from pigpio import pi
from RPLCD import pigpio
@@ -308,4 +303,4 @@ def run():
else:
print_usage('%sx%s displays are not supported in this test.' % (cols, rows))
else:
- print_usage('Test \'%s\' is not supported.' % test)
+ print_usage("Test '%s' is not supported." % test)
diff --git a/RPLCD_Tests/show_charmap.py b/RPLCD_Tests/show_charmap.py
index 3779b53..3d2f9aa 100644
--- a/RPLCD_Tests/show_charmap.py
+++ b/RPLCD_Tests/show_charmap.py
@@ -25,7 +25,6 @@
def run(lcd, rows, cols):
-
print('This tool shows the character map of your LCD on the display.')
print('Press ctrl+c at any time to abort.\n')
diff --git a/RPLCD_Tests/testsuite_16x2.py b/RPLCD_Tests/testsuite_16x2.py
index 5bc3a74..9d057ca 100644
--- a/RPLCD_Tests/testsuite_16x2.py
+++ b/RPLCD_Tests/testsuite_16x2.py
@@ -23,7 +23,6 @@
def run(lcd):
-
lcd.backlight = True
input('Display should be blank. ')
diff --git a/RPLCD_Tests/testsuite_20x4.py b/RPLCD_Tests/testsuite_20x4.py
index b67333b..7274685 100644
--- a/RPLCD_Tests/testsuite_20x4.py
+++ b/RPLCD_Tests/testsuite_20x4.py
@@ -23,7 +23,6 @@
def run(lcd):
-
lcd.backlight = True
input('Display should be blank. ')
diff --git a/pyproject.toml b/pyproject.toml
index 2a28038..915db1e 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,9 +1,7 @@
-[tool.black]
+[tool.ruff]
line-length = 99
-target-version = ["py38", "py39", "py310", "py311", "py312"]
-extend-exclude = '''
-(^/RPLCD/codecs/.*\.py$
-|^/docs/conf.py$
-)
-'''
-skip-string-normalization = true
+target-version = "py38"
+
+[tool.ruff.format]
+exclude = ["RPLCD/codecs/*.py", "docs/conf.py"]
+quote-style = "single"
diff --git a/setup.py b/setup.py
index a4c535a..a4b3cca 100644
--- a/setup.py
+++ b/setup.py
@@ -2,37 +2,37 @@
from setuptools import setup
-readme = open("README.rst").read()
+readme = open('README.rst').read()
setup(
- name="RPLCD",
- version="1.3.1",
- description="A Raspberry Pi LCD library for the widely used Hitachi HD44780 controller.",
+ name='RPLCD',
+ version='1.3.1',
+ description='A Raspberry Pi LCD library for the widely used Hitachi HD44780 controller.',
long_description=readme,
- author="Danilo Bargen",
- author_email="mail@dbrgn.ch",
- url="https://github.com/dbrgn/RPLCD",
- license="MIT",
- keywords="raspberry, raspberry pi, lcd, liquid crystal, hitachi, hd44780",
- packages=["RPLCD", "RPLCD.codecs", "RPLCD_Tests"],
+ author='Danilo Bargen',
+ author_email='mail@dbrgn.ch',
+ url='https://github.com/dbrgn/RPLCD',
+ license='MIT',
+ keywords='raspberry, raspberry pi, lcd, liquid crystal, hitachi, hd44780',
+ packages=['RPLCD', 'RPLCD.codecs', 'RPLCD_Tests'],
entry_points={
- "console_scripts": ["rplcd-tests=RPLCD_Tests.entrypoint:run"],
+ 'console_scripts': ['rplcd-tests=RPLCD_Tests.entrypoint:run'],
},
- platforms=["any"],
- python_requires=">=3.8",
+ platforms=['any'],
+ python_requires='>=3.8',
classifiers=[
- "Development Status :: 5 - Production/Stable",
- "Environment :: Other Environment",
- "Intended Audience :: Developers",
- "License :: OSI Approved :: MIT License",
- "Operating System :: POSIX",
- "Programming Language :: Python :: 3",
- "Programming Language :: Python :: 3.8",
- "Programming Language :: Python :: 3.9",
- "Programming Language :: Python :: 3.10",
- "Programming Language :: Python :: 3.11",
- "Programming Language :: Python :: 3.12",
- "Topic :: System :: Hardware :: Hardware Drivers",
- "Topic :: Software Development :: Libraries :: Python Modules",
+ 'Development Status :: 5 - Production/Stable',
+ 'Environment :: Other Environment',
+ 'Intended Audience :: Developers',
+ 'License :: OSI Approved :: MIT License',
+ 'Operating System :: POSIX',
+ 'Programming Language :: Python :: 3',
+ 'Programming Language :: Python :: 3.8',
+ 'Programming Language :: Python :: 3.9',
+ 'Programming Language :: Python :: 3.10',
+ 'Programming Language :: Python :: 3.11',
+ 'Programming Language :: Python :: 3.12',
+ 'Topic :: System :: Hardware :: Hardware Drivers',
+ 'Topic :: Software Development :: Libraries :: Python Modules',
],
)