Skip to content

Commit

Permalink
🎨 Switch to ruff for linting & formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
foosel committed Apr 30, 2024
1 parent 8b488bc commit e81830b
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 107 deletions.
22 changes: 5 additions & 17 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,12 @@ repos:
hooks:
- id: pyupgrade
args: ["--py37-plus"]
- repo: https://github.com/OctoPrint/codemods
rev: "0.6.3"
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.2
hooks:
- id: codemod_not_in
- repo: https://github.com/pre-commit/mirrors-isort
rev: v5.10.1
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 23.1.0
hooks:
- id: black
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
- id: flake8
additional_dependencies:
- flake8-bugbear
- id: ruff
args: ["--fix"]
- id: ruff-format
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.0-alpha.4
hooks:
Expand Down
32 changes: 16 additions & 16 deletions octoprint_file_check/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ def on_api_get(self, request):
if octoprint.access.permissions.Permissions.FILES_LIST.can():
# only return the check result if the user has permissions
# to see a file list, otherwise we might leak data
response[
"check_result"
] = self._gather_from_local_metadata() # TODO: caching?
response["check_result"] = (
self._gather_from_local_metadata()
) # TODO: caching?

return flask.jsonify(**response)

Expand Down Expand Up @@ -183,31 +183,31 @@ def get_additional_permissions(self):
##~~ SoftwareUpdate hook

def get_update_information(self):
return dict(
file_check=dict(
displayName="File Check Plugin",
displayVersion=self._plugin_version,
return {
"file_check": {
"displayName": "File Check Plugin",
"displayVersion": self._plugin_version,
# version check: github repository
type="github_release",
user="OctoPrint",
repo="OctoPrint-FileCheck",
current=self._plugin_version,
stable_branch={
"type": "github_release",
"user": "OctoPrint",
"repo": "OctoPrint-FileCheck",
"current": self._plugin_version,
"stable_branch": {
"name": "Stable",
"branch": "master",
"commitish": ["devel", "master"],
},
prerelease_branches=[
"prerelease_branches": [
{
"name": "Prerelease",
"branch": "devel",
"commitish": ["devel", "master"],
}
],
# update method: pip
pip="https://github.com/OctoPrint/OctoPrint-FileCheck/archive/{target_version}.zip",
)
)
"pip": "https://github.com/OctoPrint/OctoPrint-FileCheck/archive/{target_version}.zip",
}
}

##~~ Internal logic & helpers

Expand Down
99 changes: 83 additions & 16 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,84 @@
[tool.black]
[build-system]
requires = ["setuptools>=40.8.0", "wheel"]
build-backend = "setuptools.build_meta"

[tool.ruff]
exclude = [
# standard stuff
".bzr",
".direnv",
".eggs",
".git",
".git-rewrite",
".hg",
".ipynb_checkpoints",
".mypy_cache",
".nox",
".pants.d",
".pyenv",
".pytest_cache",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
".vscode",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"site-packages",
"venv",
]

line-length = 90
include = '''
(
(
src
).*\.pyi?$
)|(
setup\.py
)
'''
exclude = '''
(
)
'''
indent-width = 4

# Assume Python 3.7
target-version = "py37"

[tool.ruff.lint]
select = ["B", "C", "E", "F", "I", "W", "B9"]
ignore = [
"E203",
"E231",
"E265",
"E266",
"E402",
"E501",
"E731",
"E741",
"W605",
"C901",
]
fixable = ["I", "C4", "E"]

# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

[tool.ruff.lint.isort]
known-first-party = [
"octoprint_file_check",
]

[tool.ruff.format]
quote-style = "double"
indent-style = "space"
skip-magic-trailing-comma = false
line-ending = "lf"

# Enable auto-formatting of code examples in docstrings. Markdown,
# reStructuredText code/literal blocks and doctests are all supported.
#
# This is currently disabled by default, but it is planned for this
# to be opt-out in the future.
docstring-code-format = false

# Set the line length limit used when formatting code snippets in
# docstrings.
#
# This only has an effect when the `docstring-code-format` setting is
# enabled.
docstring-code-line-length = "dynamic"
Loading

0 comments on commit e81830b

Please sign in to comment.