mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-19 18:27:29 -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$
|
exclude: \.min\.js$
|
||||||
- id: trailing-whitespace
|
- id: trailing-whitespace
|
||||||
|
|
||||||
- repo: https://github.com/PyCQA/bandit
|
- repo: https://github.com/charliermarsh/ruff-pre-commit
|
||||||
rev: 1.7.4
|
rev: v0.0.247
|
||||||
hooks:
|
hooks:
|
||||||
- id: bandit
|
- id: ruff
|
||||||
args:
|
|
||||||
- --skip=B101,B201
|
|
||||||
|
|
||||||
- repo: https://github.com/psf/black
|
- repo: https://github.com/psf/black
|
||||||
rev: 23.1.0
|
rev: 23.1.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: black
|
- id: black
|
||||||
|
|
||||||
|
|
||||||
- repo: https://github.com/codespell-project/codespell
|
- repo: https://github.com/codespell-project/codespell
|
||||||
rev: v2.2.2
|
rev: v2.2.2
|
||||||
hooks:
|
hooks:
|
||||||
- id: codespell # See 'setup.cfg' for args
|
- id: codespell # See 'pyproject.toml' for args
|
||||||
|
additional_dependencies:
|
||||||
- repo: https://github.com/PyCQA/flake8
|
- tomli
|
||||||
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]
|
|
||||||
|
|
||||||
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
|
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
|
||||||
rev: v2.7.0
|
rev: v2.7.0
|
||||||
@@ -58,13 +44,6 @@ repos:
|
|||||||
args: [--autofix, --indent, '4']
|
args: [--autofix, --indent, '4']
|
||||||
exclude: .github/ISSUE_TEMPLATE/.*\.yml$
|
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
|
- repo: https://github.com/pre-commit/mirrors-eslint
|
||||||
rev: v8.35.0
|
rev: v8.35.0
|
||||||
hooks:
|
hooks:
|
||||||
|
|||||||
@@ -99,7 +99,9 @@ def micrograd_demo(*args, **kwargs):
|
|||||||
scores = list(map(model, inputs))
|
scores = list(map(model, inputs))
|
||||||
|
|
||||||
# svm "max-margin" loss
|
# 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))
|
data_loss = sum(losses) * (1.0 / len(losses))
|
||||||
# L2 regularization
|
# L2 regularization
|
||||||
alpha = 1e-4
|
alpha = 1e-4
|
||||||
@@ -109,7 +111,7 @@ def micrograd_demo(*args, **kwargs):
|
|||||||
# also get accuracy
|
# also get accuracy
|
||||||
accuracy = [
|
accuracy = [
|
||||||
((yi).__gt__(0)) == ((scorei.data).__gt__(0))
|
((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)
|
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
|
If check_js_errors is True (the default), it also checks that no JS
|
||||||
errors were raised during the waiting.
|
errors were raised during the waiting.
|
||||||
"""
|
"""
|
||||||
pred = lambda msg: msg.text == text
|
|
||||||
|
def pred(msg):
|
||||||
|
return msg.text == text
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with self.page.expect_console_message(pred, timeout=timeout):
|
with self.page.expect_console_message(pred, timeout=timeout):
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -233,7 +233,10 @@ class TestOutput(PyScriptTest):
|
|||||||
class Circle:
|
class Circle:
|
||||||
r = 0
|
r = 0
|
||||||
def _repr_svg_(self):
|
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()
|
circle = Circle()
|
||||||
|
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ class TestExamples(PyScriptTest):
|
|||||||
else:
|
else:
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
else:
|
else:
|
||||||
assert False, "Espresso time not found :("
|
raise AssertionError("Espresso time not found :(")
|
||||||
self.assert_no_banners()
|
self.assert_no_banners()
|
||||||
self.check_tutor_generated_code()
|
self.check_tutor_generated_code()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user