Skip to content

Commit e81830b

Browse files
committed
🎨 Switch to ruff for linting & formatting
1 parent 8b488bc commit e81830b

File tree

4 files changed

+162
-107
lines changed

4 files changed

+162
-107
lines changed

‎.pre-commit-config.yaml

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +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-
- repo: https://github.com/pycqa/flake8
33-
rev: 6.0.0
34-
hooks:
35-
- id: flake8
36-
additional_dependencies:
37-
- flake8-bugbear
23+
- id: ruff
24+
args: ["--fix"]
25+
- id: ruff-format
3826
- repo: https://github.com/pre-commit/mirrors-prettier
3927
rev: v3.0.0-alpha.4
4028
hooks:

‎octoprint_file_check/__init__.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ def on_api_get(self, request):
112112
if octoprint.access.permissions.Permissions.FILES_LIST.can():
113113
# only return the check result if the user has permissions
114114
# to see a file list, otherwise we might leak data
115-
response[
116-
"check_result"
117-
] = self._gather_from_local_metadata() # TODO: caching?
115+
response["check_result"] = (
116+
self._gather_from_local_metadata()
117+
) # TODO: caching?
118118

119119
return flask.jsonify(**response)
120120

@@ -183,31 +183,31 @@ def get_additional_permissions(self):
183183
##~~ SoftwareUpdate hook
184184

185185
def get_update_information(self):
186-
return dict(
187-
file_check=dict(
188-
displayName="File Check Plugin",
189-
displayVersion=self._plugin_version,
186+
return {
187+
"file_check": {
188+
"displayName": "File Check Plugin",
189+
"displayVersion": self._plugin_version,
190190
# version check: github repository
191-
type="github_release",
192-
user="OctoPrint",
193-
repo="OctoPrint-FileCheck",
194-
current=self._plugin_version,
195-
stable_branch={
191+
"type": "github_release",
192+
"user": "OctoPrint",
193+
"repo": "OctoPrint-FileCheck",
194+
"current": self._plugin_version,
195+
"stable_branch": {
196196
"name": "Stable",
197197
"branch": "master",
198198
"commitish": ["devel", "master"],
199199
},
200-
prerelease_branches=[
200+
"prerelease_branches": [
201201
{
202202
"name": "Prerelease",
203203
"branch": "devel",
204204
"commitish": ["devel", "master"],
205205
}
206206
],
207207
# update method: pip
208-
pip="https://github.com/OctoPrint/OctoPrint-FileCheck/archive/{target_version}.zip",
209-
)
210-
)
208+
"pip": "https://github.com/OctoPrint/OctoPrint-FileCheck/archive/{target_version}.zip",
209+
}
210+
}
211211

212212
##~~ Internal logic & helpers
213213

‎pyproject.toml

Lines changed: 83 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,84 @@
1-
[tool.black]
1+
[build-system]
2+
requires = ["setuptools>=40.8.0", "wheel"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[tool.ruff]
6+
exclude = [
7+
# standard stuff
8+
".bzr",
9+
".direnv",
10+
".eggs",
11+
".git",
12+
".git-rewrite",
13+
".hg",
14+
".ipynb_checkpoints",
15+
".mypy_cache",
16+
".nox",
17+
".pants.d",
18+
".pyenv",
19+
".pytest_cache",
20+
".pytype",
21+
".ruff_cache",
22+
".svn",
23+
".tox",
24+
".venv",
25+
".vscode",
26+
"__pypackages__",
27+
"_build",
28+
"buck-out",
29+
"build",
30+
"dist",
31+
"node_modules",
32+
"site-packages",
33+
"venv",
34+
]
35+
236
line-length = 90
3-
include = '''
4-
5-
(
6-
(
7-
src
8-
).*\.pyi?$
9-
)|(
10-
setup\.py
11-
)
12-
'''
13-
exclude = '''
14-
15-
(
16-
)
17-
'''
37+
indent-width = 4
38+
39+
# Assume Python 3.7
40+
target-version = "py37"
41+
42+
[tool.ruff.lint]
43+
select = ["B", "C", "E", "F", "I", "W", "B9"]
44+
ignore = [
45+
"E203",
46+
"E231",
47+
"E265",
48+
"E266",
49+
"E402",
50+
"E501",
51+
"E731",
52+
"E741",
53+
"W605",
54+
"C901",
55+
]
56+
fixable = ["I", "C4", "E"]
57+
58+
# Allow unused variables when underscore-prefixed.
59+
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
60+
61+
[tool.ruff.lint.isort]
62+
known-first-party = [
63+
"octoprint_file_check",
64+
]
65+
66+
[tool.ruff.format]
67+
quote-style = "double"
68+
indent-style = "space"
69+
skip-magic-trailing-comma = false
70+
line-ending = "lf"
71+
72+
# Enable auto-formatting of code examples in docstrings. Markdown,
73+
# reStructuredText code/literal blocks and doctests are all supported.
74+
#
75+
# This is currently disabled by default, but it is planned for this
76+
# to be opt-out in the future.
77+
docstring-code-format = false
78+
79+
# Set the line length limit used when formatting code snippets in
80+
# docstrings.
81+
#
82+
# This only has an effect when the `docstring-code-format` setting is
83+
# enabled.
84+
docstring-code-line-length = "dynamic"

0 commit comments

Comments
 (0)