mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-19 10:17:23 -05:00
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:
@@ -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:
|
||||
|
||||
@@ -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
39
pyproject.toml
Normal 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
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user