Skip to content

Commit f2de034

Browse files
committed
pre-commit update
1 parent 22af9d3 commit f2de034

File tree

7 files changed

+57
-50
lines changed

7 files changed

+57
-50
lines changed

.eslintrc.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
parserOptions:
2+
ecmaVersion: 2018
3+
4+
overrides:
5+
- files:
6+
- "octoprint_pi_support/static/js/**.js"
7+
env:
8+
browser: true
9+
jquery: true
10+
es6: true

.pre-commit-config.yaml

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
exclude: ^(octoprint_pi_support/translations|extras/|translations/|.*\.css|.*\.svg)
22
repos:
33
- repo: https://github.com/pre-commit/pre-commit-hooks
4-
rev: v2.3.0
4+
rev: v4.1.0
55
hooks:
66
- id: end-of-file-fixer
77
- id: trailing-whitespace
@@ -11,32 +11,42 @@ repos:
1111
- id: check-toml
1212
- id: check-merge-conflict
1313
- id: fix-encoding-pragma
14+
args: ["--remove"]
1415
- repo: https://github.com/asottile/pyupgrade
15-
rev: v2.10.0
16+
rev: v2.31.0
1617
hooks:
1718
- id: pyupgrade
19+
args: ["--py37-plus"]
1820
- repo: https://github.com/OctoPrint/codemods
19-
rev: devel
21+
rev: "0.6.3"
2022
hooks:
2123
- id: codemod_not_in
2224
- repo: https://github.com/pre-commit/mirrors-isort
23-
rev: v5.5.4
25+
rev: v5.10.1
2426
hooks:
2527
- id: isort
2628
- repo: https://github.com/psf/black
27-
rev: 20.8b1
29+
rev: 22.1.0
2830
hooks:
2931
- id: black
3032
args: ["--config", "black.toml"]
3133
additional_dependencies:
3234
- click==8.0.4
33-
- repo: https://gitlab.com/pycqa/flake8
34-
rev: 3.8.1
35+
- repo: https://github.com/pycqa/flake8
36+
rev: 3.9.2
3537
hooks:
3638
- id: flake8
3739
additional_dependencies:
3840
- flake8-bugbear
3941
- repo: https://github.com/pre-commit/mirrors-prettier
40-
rev: v2.1.2
42+
rev: v2.5.1
4143
hooks:
4244
- id: prettier
45+
- repo: https://github.com/pre-commit/mirrors-eslint
46+
rev: v8.8.0
47+
hooks:
48+
- id: eslint
49+
additional_dependencies:
50+
51+
52+
files: \.js$

octoprint_pi_support/__init__.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
# -*- coding: utf-8 -*-
2-
from __future__ import absolute_import, division, print_function, unicode_literals
3-
41
__license__ = "GNU Affero General Public License http://www.gnu.org/licenses/agpl.html"
52
__copyright__ = "Copyright (C) 2017 The OctoPrint Project - Released under terms of the AGPLv3 License"
63

7-
import io
84
import os
95
from getpass import getuser
106

@@ -71,7 +67,7 @@
7167
_UNRECOMMENDED_MODELS = ("Zero", "Zero W")
7268

7369

74-
class ThrottleState(object):
70+
class ThrottleState:
7571
@classmethod
7672
def from_value(cls, value=0):
7773
if value == 0:
@@ -99,7 +95,7 @@ def __init__(self, **kwargs):
9995
self._past_throttled = False
10096

10197
for key, value in kwargs.items():
102-
local_key = "_{}".format(key)
98+
local_key = f"_{key}"
10399
if hasattr(self, local_key) and isinstance(value, bool):
104100
setattr(self, local_key, value)
105101

@@ -145,7 +141,7 @@ def raw_value(self):
145141

146142
@property
147143
def raw_value_hex(self):
148-
return "0x{:X}".format(self._raw_value)
144+
return f"0x{self._raw_value:X}"
149145

150146
def __eq__(self, other):
151147
if not isinstance(other, ThrottleState):
@@ -180,7 +176,7 @@ def get_proc_dt_model():
180176
global _proc_dt_model
181177

182178
if _proc_dt_model is None:
183-
with io.open(_PROC_DT_MODEL_PATH, "rt", encoding="utf-8") as f:
179+
with open(_PROC_DT_MODEL_PATH, encoding="utf-8") as f:
184180
_proc_dt_model = f.readline().strip(" \t\r\n\0")
185181

186182
return _proc_dt_model
@@ -200,9 +196,7 @@ def get_vcgencmd_throttled_state(command):
200196
output, error = sarge.get_both(command, close_fds=CLOSE_FDS)
201197

202198
if "throttled=0x" not in output:
203-
raise ValueError(
204-
'Cannot parse "{}" output: {}'.format(command, error if error else output)
205-
)
199+
raise ValueError(f"Cannot parse {command!r} output: {error if error else output}")
206200

207201
value = output[len("throttled=") :].strip(" \t\r\n\0")
208202
value = int(value, 0)
@@ -220,7 +214,7 @@ def is_octopiuptodate():
220214
def is_model_any_of(model, *args):
221215
model = model.lower()
222216
for arg in map(lambda x: x.lower(), args):
223-
if "{} rev".format(arg) in model or model.endswith(arg):
217+
if f"{arg} rev" in model or model.endswith(arg):
224218
return True
225219
return False
226220

@@ -232,7 +226,7 @@ def get_octopi_version():
232226
global _octopi_version
233227

234228
if _octopi_version is None:
235-
with io.open(_OCTOPI_VERSION_PATH, "rt", encoding="utf-8") as f:
229+
with open(_OCTOPI_VERSION_PATH, encoding="utf-8") as f:
236230
_octopi_version = f.readline().strip(" \t\r\n\0")
237231

238232
return _octopi_version
@@ -245,7 +239,7 @@ def get_octopiuptodate_build():
245239
global _octopiuptodate_build
246240

247241
if _octopiuptodate_build is None:
248-
with io.open(_OCTOPIUPTODATE_BUILD_PATH, "rt", encoding="utf-8") as f:
242+
with open(_OCTOPIUPTODATE_BUILD_PATH, encoding="utf-8") as f:
249243
_octopiuptodate_build = f.readline().strip(" \t\r\n\0")
250244

251245
return _octopiuptodate_build
@@ -476,7 +470,7 @@ def _check_throttled_state(self):
476470

477471
command = self._settings.get(["vcgencmd_throttle_check_command"])
478472

479-
self._logger.debug('Retrieving throttle state via "{}"'.format(command))
473+
self._logger.debug(f"Retrieving throttle state via {command!r}")
480474
try:
481475
state = get_vcgencmd_throttled_state(command)
482476
except ValueError as ex:

octoprint_pi_support/static/js/pi_support.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,13 @@ $(function () {
252252
return content;
253253
});
254254

255-
self.onStartup = self.onServerReconnect = self.onUserLoggedIn = self.onUserLoggedOut = function () {
256-
self.requestData();
257-
};
255+
self.onStartup =
256+
self.onServerReconnect =
257+
self.onUserLoggedIn =
258+
self.onUserLoggedOut =
259+
function () {
260+
self.requestData();
261+
};
258262

259263
self.onDataUpdaterPluginMessage = function (plugin, data) {
260264
if (plugin !== "pi_support") return;

setup.py

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
31
########################################################################################################################
42
### Do not forget to adjust the following variables to your own plugin.
53

@@ -453,9 +451,7 @@ def run(self):
453451
shutil.rmtree(target_path)
454452

455453
print(
456-
"Copying translations for locale {locale} from {source_path} to {target_path}...".format(
457-
**locals()
458-
)
454+
f"Copying translations for locale {locale} from {source_path} to {target_path}..."
459455
)
460456
shutil.copytree(source_path, target_path)
461457

@@ -523,7 +519,7 @@ def run(self):
523519
date=now.strftime("%Y%m%d%H%M%S"),
524520
),
525521
)
526-
print("Packing translation to {zip_path}".format(**locals()))
522+
print(f"Packing translation to {zip_path}")
527523

528524
def add_recursively(zip, path, prefix):
529525
if not os.path.isdir(path):
@@ -535,12 +531,12 @@ def add_recursively(zip, path, prefix):
535531
if os.path.isdir(entry_path):
536532
add_recursively(zip, entry_path, new_prefix)
537533
elif os.path.isfile(entry_path):
538-
print("Adding {entry_path} as {new_prefix}".format(**locals()))
534+
print(f"Adding {entry_path} as {new_prefix}")
539535
zip.write(entry_path, new_prefix)
540536

541-
meta_str = "last_update: {date}\n".format(date=now.isoformat())
537+
meta_str = f"last_update: {now.isoformat()}\n"
542538
if self.author:
543-
meta_str += "author: {author}\n".format(author=self.author)
539+
meta_str += f"author: {self.author}\n"
544540

545541
zip_locale_root = self.__class__.pack_path_prefix + locale
546542

@@ -549,7 +545,7 @@ def add_recursively(zip, path, prefix):
549545
with zipfile.ZipFile(zip_path, "w") as zip:
550546
add_recursively(zip, locale_dir, zip_locale_root)
551547

552-
print("Adding meta.yaml as {zip_locale_root}/meta.yaml".format(**locals()))
548+
print(f"Adding meta.yaml as {zip_locale_root}/meta.yaml")
553549
zip.writestr(zip_locale_root + "/meta.yaml", meta_str)
554550

555551

@@ -620,7 +616,7 @@ def create_plugin_setup_parameters(
620616
import pkg_resources
621617

622618
if package is None:
623-
package = "octoprint_{identifier}".format(**locals())
619+
package = f"octoprint_{identifier}"
624620

625621
if additional_data is None:
626622
additional_data = list()
@@ -676,8 +672,8 @@ def create_plugin_setup_parameters(
676672
pot_file=pot_file,
677673
output_dir=translation_dir,
678674
bundled_dir=bundled_dir,
679-
pack_name_prefix="{name}-i18n-".format(**locals()),
680-
pack_path_prefix="_plugins/{identifier}/".format(**locals()),
675+
pack_name_prefix=f"{name}-i18n-",
676+
pack_path_prefix=f"_plugins/{identifier}/",
681677
)
682678
)
683679

@@ -687,13 +683,13 @@ def create_plugin_setup_parameters(
687683
[package]
688684
+ list(
689685
filter(
690-
lambda x: x.startswith("{package}.".format(package=package)),
686+
lambda x: x.startswith(f"{package}."),
691687
find_packages(where=source_folder, exclude=ignored_packages),
692688
)
693689
)
694690
+ additional_packages
695691
)
696-
print("Found packages: {packages!r}".format(**locals()))
692+
print(f"Found packages: {packages!r}")
697693

698694
return dict(
699695
name=name,
@@ -723,9 +719,7 @@ def create_plugin_setup_parameters(
723719
dependency_links=dependency_links,
724720
# Hook the plugin into the "octoprint.plugin" entry point, mapping the plugin_identifier to the plugin_package.
725721
# That way OctoPrint will be able to find the plugin and load it.
726-
entry_points={
727-
"octoprint.plugin": ["{identifier} = {package}".format(**locals())]
728-
},
722+
entry_points={"octoprint.plugin": [f"{identifier} = {package}"]},
729723
)
730724

731725

tests/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +0,0 @@
1-
# -*- coding: utf-8 -*-
2-
from __future__ import absolute_import, division, print_function, unicode_literals

tests/test_pi_support.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
# -*- coding: utf-8 -*-
2-
from __future__ import absolute_import, division, print_function, unicode_literals
3-
41
import unittest
2+
from unittest import mock
53

64
import ddt
7-
import mock
85
from octoprint.util.platform import CLOSE_FDS
96

107
OCTOPI_VERSION = "0.14.0"

0 commit comments

Comments
 (0)