pre-commit: Add ruff to replace bandit, flake8, isort, and pyupgrade (#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
This commit is contained in:
Christian Clauss
2023-03-06 15:20:08 +01:00
committed by GitHub
parent 71d24a445e
commit 7ffe6a598e
7 changed files with 58 additions and 42 deletions

View File

@@ -20,36 +20,22 @@ repos:
exclude: \.min\.js$
- id: trailing-whitespace
- repo: https://github.com/PyCQA/bandit
rev: 1.7.4
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.247
hooks:
- id: bandit
args:
- --skip=B101,B201
- id: ruff
- repo: https://github.com/psf/black
rev: 23.1.0
hooks:
- id: black
- repo: https://github.com/codespell-project/codespell
rev: v2.2.2
hooks:
- id: codespell # See 'setup.cfg' for args
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8 # See 'setup.cfg' for args
additional_dependencies: [flake8-bugbear, flake8-comprehensions]
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
name: isort (python)
args: [--profile, black]
- id: codespell # See 'pyproject.toml' for args
additional_dependencies:
- tomli
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.7.0
@@ -58,13 +44,6 @@ repos:
args: [--autofix, --indent, '4']
exclude: .github/ISSUE_TEMPLATE/.*\.yml$
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
hooks:
- id: pyupgrade
args:
- --py310-plus
- repo: https://github.com/pre-commit/mirrors-eslint
rev: v8.35.0
hooks:

View File

@@ -99,7 +99,9 @@ def micrograd_demo(*args, **kwargs):
scores = list(map(model, inputs))
# svm "max-margin" loss
losses = [(1 + -yi * scorei).relu() for yi, scorei in zip(yb, scores)]
losses = [
(1 + -yi * scorei).relu() for yi, scorei in zip(yb, scores, strict=True)
]
data_loss = sum(losses) * (1.0 / len(losses))
# L2 regularization
alpha = 1e-4
@@ -109,7 +111,7 @@ def micrograd_demo(*args, **kwargs):
# also get accuracy
accuracy = [
((yi).__gt__(0)) == ((scorei.data).__gt__(0))
for yi, scorei in zip(yb, scores)
for yi, scorei in zip(yb, scores, strict=True)
]
return total_loss, sum(accuracy) / len(accuracy)

39
pyproject.toml Normal file
View File

@@ -0,0 +1,39 @@
[build-system]
requires = ["setuptools>=61.2"]
build-backend = "setuptools.build_meta"
[project]
dynamic = ["version"]
[tool.codespell]
skip = "pyscriptjs/node_modules/*,*.js,*.json"
[tool.ruff]
builtins = [
"Element",
"PyItemTemplate",
"PyListTemplate",
"pyscript",
]
ignore = [
"S101",
"S113",
]
line-length = 100
select = [
"B",
"C9",
"E",
"F",
"I",
"S",
"UP",
"W",
]
target-version = "py310"
[tool.ruff.mccabe]
max-complexity = 10
[tool.setuptools]
include-package-data = false

View File

@@ -219,7 +219,10 @@ class PyScriptTest:
If check_js_errors is True (the default), it also checks that no JS
errors were raised during the waiting.
"""
pred = lambda msg: msg.text == text
def pred(msg):
return msg.text == text
try:
with self.page.expect_console_message(pred, timeout=timeout):
pass

View File

@@ -233,7 +233,10 @@ class TestOutput(PyScriptTest):
class Circle:
r = 0
def _repr_svg_(self):
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
return (
f'<svg height="{self.r*2}" width="{self.r*2}">'
f'<circle cx="{self.r}" cy="{self.r}" r="{self.r}" fill="red" /></svg>'
)
circle = Circle()

View File

@@ -52,7 +52,7 @@ class TestExamples(PyScriptTest):
else:
time.sleep(1)
else:
assert False, "Espresso time not found :("
raise AssertionError("Espresso time not found :(")
self.assert_no_banners()
self.check_tutor_generated_code()

View File

@@ -1,10 +0,0 @@
[codespell]
skip = pyscriptjs/node_modules/*,*.js,*.json
[flake8]
builtins=Element,PyItemTemplate,PyListTemplate,pyscript
max-complexity = 10
max-line-length = 100
show-source = True
statistics = True
extend-ignore = E731,B011,E266,B028