8000 pre-commit: Add ruff to replace bandit, flake8, isort, and pyupgrade … · Conan520/pyscript@7ffe6a5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7ffe6a5

Browse files
authored
pre-commit: Add ruff to replace bandit, flake8, isort, and pyupgrade (pyscript#1210)
* pre-commit: Add ruff to replace bandit, flake8, isort, and pyupgrade * Upgrade ruff * Update .pre-commit-config.yaml * Update .pre-commit-config.yaml * Update .pre-commit-config.yaml
1 parent 71d24a4 commit 7ffe6a5

File tree

7 files changed

+58
-42
lines changed

7 files changed

+58
-42
lines changed

.pre-commit-config.yaml

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,36 +20,22 @@ repos:
2020
exclude: \.min\.js$
2121
- id: trailing-whitespace
2222

23-
- repo: https://github.com/PyCQA/bandit
24-
rev: 1.7.4
23+
- repo: https://github.com/charliermarsh/ruff-pre-commit
24+
rev: v0.0.247
2525
hooks:
26-
- id: bandit
27-
args:
28-
- --skip=B101,B201
26+
- id: ruff
2927

3028
- repo: https://github.com/psf/black
3129
rev: 23.1.0
3230
hooks:
3331
- id: black
3432

35-
3633
- repo: https://github.com/codespell-project/codespell
3734
rev: v2.2.2
3835
hooks:
39-
- id: codespell # See 'setup.cfg' for args
40-
41-
- repo: https://github.com/PyCQA/flake8
42-
rev: 6.0.0
43-
hooks:
44-
- id: flake8 # See 'setup.cfg' for args
45-
additional_dependencies: [flake8-bugbear, flake8-comprehensions]
46-
47-
- repo: https://github.com/pycqa/isort
48-
rev: 5.12.0
49-
hooks:
50-
- id: isort
51-
name: isort (python)
52-
args: [--profile, black]
36+
- id: codespell # See 'pyproject.toml' for args
37+
additional_dependencies:
38+
- tomli
5339

5440
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
5541
rev: v2.7.0
@@ -58,13 +44,6 @@ repos:
5844
args: [--autofix, --indent, '4']
5945
exclude: .github/ISSUE_TEMPLATE/.*\.yml$
6046

61-
- repo: https://github.com/asottile/pyupgrade
62-
rev: v3.3.1
63-
hooks:
64-
- id: pyupgrade
65-
args:
66-
- --py310-plus
67-
6847
- repo: https://github.com/pre-commit/mirrors-eslint
6948
rev: v8.35.0
7049
hooks:

examples/micrograd_ai.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ def loss(batch_size=None):
9999
scores = list(map(model, inputs))
100100

101101
# svm "max-margin" loss
102-
losses = [(1 + -yi * scorei).relu() for yi, scorei in zip(yb, scores)]
102+
losses = [
103+
(1 + -yi * scorei).relu() for yi, scorei in zip(yb, scores, strict=True)
104+
]
103105
data_loss = sum(losses) * (1.0 / len(losses))
104106
# L2 regularization
105107
alpha = 1e-4
@@ -109,7 +111,7 @@ def loss(batch_size=None):
109111
# also get accuracy
110112
accuracy = [
111113
((yi).__gt__(0)) == ((scorei.data).__gt__(0))
112-
for yi, scorei in zip(yb, scores)
114+
for yi, scorei in zip(yb, scores, strict=True)
113115
]
114116
return total_loss, sum(accuracy) / len(accuracy)
115117

pyproject.toml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
[build-system]
2+
requires = ["setuptools>=61.2"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
dynamic = ["version"]
7+
8+
[tool.codespell]
9+
skip = "pyscriptjs/node_modules/*,*.js,*.json"
10+
11+
[tool.ruff]
12+
builtins = [
13+
"Element",
14+
"PyItemTemplate",
15+
"PyListTemplate",
16+
"pyscript",
17+
]
18+
ignore = [
19+
"S101",
20+
"S113",
21+
]
22+
line-length = 100
23+
select = [
24+
"B",
25+
"C9",
26+
"E",
27+
"F",
28+
"I",
29+
"S",
30+
"UP",
31+
"W",
32+
]
33+
target-version = "py310"
34+
35+
[tool.ruff.mccabe]
36+
max-complexity = 10
37+
38+
[tool.setuptools]
39+ F438
include-package-data = false

pyscriptjs/tests/integration/support.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,10 @@ def wait_for_console(self, text, *, timeout=None, check_js_errors=True):
219219
If check_js_errors is True (the default), it also checks that no JS
220220
errors were raised during the waiting.
221221
"""
222-
pred = lambda msg: msg.text == text
222+
223+
def pred(msg):
224+
return msg.text == text
225+
223226
try:
224227
with self.page.expect_console_message(pred, timeout=timeout):
225228
pass

pyscriptjs/tests/integration/test_02_display.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,10 @@ def test_display_multiple_append_false_with_target(self):
233233
class Circle:
234234
r = 0
235235
def _repr_svg_(self):
236-
return f'<svg height="{self.r*2}" width="{self.r*2}"><circle cx="{self.r}" cy="{self.r}" r="{self.r}" fill="red" /></svg>' # noqa: E501
236+
return (
237+
f'<svg height="{self.r*2}" width="{self.r*2}">'
238+
f'<circle cx="{self.r}" cy="{self.r}" r="{self.r}" fill="red" /></svg>'
239+
)
237240
238241
circle = Circle()
239242

pyscriptjs/tests/integration/test_zz_examples.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def test_simple_clock(self):
5252
else:
5353
time.sleep(1)
5454
else:
55-
assert False, "Espresso time not found :("
55+
raise AssertionError("Espresso time not found :(")
5656
self.assert_no_banners()
5757
self.check_tutor_generated_code()
5858

setup.cfg

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

0 commit comments

Comments
 (0)
0