Skip to content

Commit 07761f4

Browse files
committed
chore: move to pyproject.toml & ruff
1 parent 1002bc7 commit 07761f4

9 files changed

Lines changed: 231 additions & 166 deletions

File tree

.pre-commit-config.yaml

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,12 @@ repos:
1717
hooks:
1818
- id: pyupgrade
1919
args: ["--py37-plus"]
20-
- repo: https://github.com/OctoPrint/codemods
21-
rev: "0.6.3"
20+
- repo: https://github.com/astral-sh/ruff-pre-commit
21+
rev: v0.4.2
2222
hooks:
23-
- id: codemod_not_in
24-
- repo: https://github.com/pre-commit/mirrors-isort
25-
rev: v5.10.1
26-
hooks:
27-
- id: isort
28-
- repo: https://github.com/psf/black
29-
rev: 23.1.0
30-
hooks:
31-
- id: black
32-
args: ["--config", "black.toml"]
33-
additional_dependencies:
34-
- click==8.0.4
35-
- repo: https://github.com/pycqa/flake8
36-
rev: 6.0.0
37-
hooks:
38-
- id: flake8
39-
additional_dependencies:
40-
- flake8-bugbear
23+
- id: ruff
24+
args: ["--fix"]
25+
- id: ruff-format
4126
- repo: https://github.com/pre-commit/mirrors-prettier
4227
rev: v3.0.0-alpha.4
4328
hooks:
@@ -50,10 +35,3 @@ repos:
5035
- eslint@7.19.0
5136
- eslint-plugin-es5@v1.3.0
5237
files: \.js$
53-
- repo: https://github.com/OctoPrint/pre-commit-lessc
54-
rev: 4.2.0
55-
hooks:
56-
- id: lessc
57-
args: ["--wrapper-quiet", "--clean-css=--s1 --advanced --compatibility=ie8"]
58-
additional_dependencies: ["less-plugin-clean-css"]
59-
files: \.less$

black.toml

Lines changed: 0 additions & 3 deletions
This file was deleted.

octoprint_firmware_check/__init__.py

Lines changed: 66 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -53,43 +53,47 @@ class FirmwareCheckPlugin(
5353
):
5454
# noinspection PyMissingConstructor
5555
def __init__(self):
56-
self._warnings = dict()
56+
self._warnings = {}
5757
self._scan_received = True
5858

5959
##~~ TemplatePlugin API
6060

6161
def get_template_configs(self):
6262
return [
63-
dict(
64-
type="sidebar",
65-
name=gettext("Attention!"),
66-
data_bind="visible: printerState.isOperational() && loginState.isAdmin() && warnings().length > 0",
67-
icon="exclamation-triangle",
68-
styles_wrapper=["display: none"],
69-
template="firmware_check_sidebar_warning.jinja2",
70-
suffix="_warning",
71-
),
72-
dict(
73-
type="sidebar",
74-
name=gettext("Info"),
75-
data_bind="visible: printerState.isOperational() && loginState.isAdmin() && infos().length > 0",
76-
icon="info-circle",
77-
styles_wrapper=["display: none"],
78-
template="firmware_check_sidebar_info.jinja2",
79-
suffix="_info",
80-
),
81-
dict(type="settings", name=gettext("Firmware Check"), custom_bindings=False),
63+
{
64+
"type": "sidebar",
65+
"name": gettext("Attention!"),
66+
"data_bind": "visible: printerState.isOperational() && loginState.isAdmin() && warnings().length > 0",
67+
"icon": "exclamation-triangle",
68+
"styles_wrapper": ["display: none"],
69+
"template": "firmware_check_sidebar_warning.jinja2",
70+
"suffix": "_warning",
71+
},
72+
{
73+
"type": "sidebar",
74+
"name": gettext("Info"),
75+
"data_bind": "visible: printerState.isOperational() && loginState.isAdmin() && infos().length > 0",
76+
"icon": "info-circle",
77+
"styles_wrapper": ["display: none"],
78+
"template": "firmware_check_sidebar_info.jinja2",
79+
"suffix": "_info",
80+
},
81+
{
82+
"type": "settings",
83+
"name": gettext("Firmware Check"),
84+
"custom_bindings": False,
85+
},
8286
]
8387

8488
##~~ AssetPlugin API
8589

8690
def get_assets(self):
87-
return dict(
88-
js=("js/firmware_check.js",),
89-
clientjs=("clientjs/firmware_check.js",),
90-
css=("css/firmware_check.css",),
91-
less=("less/firmware_check.less",),
92-
)
91+
return {
92+
"js": ("js/firmware_check.js",),
93+
"clientjs": ("clientjs/firmware_check.js",),
94+
"css": ("css/firmware_check.css",),
95+
"less": ("less/firmware_check.less",),
96+
}
9397

9498
##~~ EventHandlerPlugin API
9599

@@ -139,43 +143,43 @@ def on_firmware_cap_received(self, comm_instance, cap, enabled, all_caps):
139143

140144
def get_additional_permissions(self):
141145
return [
142-
dict(
143-
key="DISPLAY",
144-
name="Display firmware check warnings",
145-
description=gettext("Allows to see firmware check warnings"),
146-
roles=["display"],
147-
default_groups=[USER_GROUP],
148-
)
146+
{
147+
"key": "DISPLAY",
148+
"name": "Display firmware check warnings",
149+
"description": gettext("Allows to see firmware check warnings"),
150+
"roles": ["display"],
151+
"default_groups": [USER_GROUP],
152+
}
149153
]
150154

151155
##~~ Softwareupdate hook
152156

153157
def get_update_information(self):
154-
return dict(
155-
firmware_check=dict(
156-
displayName="Firmware Check Plugin",
157-
displayVersion=self._plugin_version,
158+
return {
159+
"firmware_check": {
160+
"displayName": "Firmware Check Plugin",
161+
"displayVersion": self._plugin_version,
158162
# version check: github repository
159-
type="github_release",
160-
user="OctoPrint",
161-
repo="OctoPrint-FirmwareCheck",
162-
current=self._plugin_version,
163-
stable_branch={
163+
"type": "github_release",
164+
"user": "OctoPrint",
165+
"repo": "OctoPrint-FirmwareCheck",
166+
"current": self._plugin_version,
167+
"stable_branch": {
164168
"name": "Stable",
165169
"branch": "master",
166170
"commitish": ["devel", "master"],
167171
},
168-
prerelease_branches=[
172+
"prerelease_branches": [
169173
{
170174
"name": "Prerelease",
171175
"branch": "devel",
172176
"commitish": ["devel", "master"],
173177
}
174178
],
175179
# update method: pip
176-
pip="https://github.com/OctoPrint/OctoPrint-FirmwareCheck/archive/{target_version}.zip",
177-
)
178-
)
180+
"pip": "https://github.com/OctoPrint/OctoPrint-FirmwareCheck/archive/{target_version}.zip",
181+
}
182+
}
179183

180184
##~~ Helpers
181185

@@ -220,18 +224,21 @@ def _run_checks(self, check_type, *args, **kwargs):
220224
url = check.url
221225

222226
self._register_warning(
223-
warning_type, message.format(**check.placeholders), severity, url
227+
warning_type,
228+
message.format(**check.placeholders),
229+
severity,
230+
url,
224231
)
225232

226233
# noinspection PyUnresolvedReferences
227234
self._event_bus.fire(
228235
Events.PLUGIN_FIRMWARE_CHECK_WARNING,
229-
dict(
230-
check_name=check.name,
231-
warning_type=warning_type,
232-
severity=severity,
233-
url=url,
234-
),
236+
{
237+
"check_name": check.name,
238+
"warning_type": warning_type,
239+
"severity": severity,
240+
"url": url,
241+
},
235242
)
236243
changes = True
237244
break
@@ -259,7 +266,11 @@ def _register_warning(self, warning_type, message, severity, url):
259266
url=url,
260267
)
261268
)
262-
self._warnings[warning_type] = dict(message=message, severity=severity, url=url)
269+
self._warnings[warning_type] = {
270+
"message": message,
271+
"severity": severity,
272+
"url": url,
273+
}
263274

264275
logline = f"{message}. More information at {url}"
265276
if severity == Severity.INFO:
@@ -289,7 +300,7 @@ def _log_to_terminal(self, message):
289300
self._printer.log_lines(*lines)
290301

291302
def _ping_clients(self):
292-
self._plugin_manager.send_plugin_message(self._identifier, dict(type="update"))
303+
self._plugin_manager.send_plugin_message(self._identifier, {"type": "update"})
293304

294305

295306
def register_custom_events(*args, **kwargs):

octoprint_firmware_check/checks/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def received(self, line):
142142

143143
lower_line = line.lower()
144144
if self.AUTHOR in lower_line:
145-
self._triggered = any(map(lambda x: x in lower_line, self.authors))
145+
self._triggered = any(x in lower_line for x in self.authors)
146146
self._active = False
147147

148148

octoprint_firmware_check/checks/firmware_broken.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@
1010
class FirmwareBrokenChecks:
1111
@classmethod
1212
def as_dict(cls):
13-
return dict(
14-
checks=(
13+
return {
14+
"checks": (
1515
CbdCheck(),
1616
ZwlfCheck(),
1717
CrealityDoubleTempCheck(),
1818
CrealityTFCardCheck(),
1919
),
20-
message=gettext(
20+
"message": gettext(
2121
"Your printer's firmware is known to have a broken implementation of the "
2222
"communication protocol. This may cause print failures or other annoyances. "
2323
"You'll need to take additional steps for OctoPrint to fully work with it."
2424
),
25-
severity=Severity.WARNING,
26-
)
25+
"severity": Severity.WARNING,
26+
}
2727

2828

2929
class CbdCheck(LineCheck):
@@ -87,8 +87,6 @@ def _is_ruled_out(self, line):
8787
# first thing that looks like a proper report stops scanning
8888
lower_line = line.lower()
8989
return not settings().getBoolean(["feature", "sdSupport"]) or any(
90-
map(
91-
lambda x: x in lower_line,
92-
("sd card ok", "sd init fail", "sd printing byte", "not sd printing"),
93-
)
90+
x in lower_line
91+
for x in ("sd card ok", "sd init fail", "sd printing byte", "not sd printing")
9492
)

octoprint_firmware_check/checks/firmware_development.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@
1212
class FirmwareDevelopmentChecks:
1313
@classmethod
1414
def as_dict(cls):
15-
return dict(
16-
checks=(
15+
return {
16+
"checks": (
1717
MarlinBugfixCheck(),
1818
MarlinMfsBugfixCheck(),
1919
),
20-
message=gettext(
20+
"message": gettext(
2121
"Your printer's firmware is a {buildtype} build of {firmware} "
2222
"(build date {builddate}). It might be more unstable "
2323
"than a release version and should be kept up-to-date."
2424
),
25-
severity=Severity.INFO,
26-
)
25+
"severity": Severity.INFO,
26+
}
2727

2828

2929
class MarlinBugfixCheck(Check):

octoprint_firmware_check/checks/firmware_unsafe.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
class FirmwareUnsafeChecks:
1111
@classmethod
1212
def as_dict(cls):
13-
return dict(
14-
checks=(
13+
return {
14+
"checks": (
1515
AnetA8Check(),
1616
AnycubicCheck(),
1717
CrealityCR10sCheck(),
@@ -23,12 +23,12 @@ def as_dict(cls):
2323
RepetierBefore092Check(),
2424
ThermalProtectionCapCheck(),
2525
),
26-
message=gettext(
26+
"message": gettext(
2727
"Your printer's firmware is known to lack mandatory safety features (e.g. "
2828
"thermal runaway protection). This is a fire risk."
2929
),
30-
severity=Severity.CRITICAL,
31-
)
30+
"severity": Severity.CRITICAL,
31+
}
3232

3333

3434
class AnetA8Check(Check):

0 commit comments

Comments
 (0)