diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 4c055cdc..5112338e 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -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:
diff --git a/examples/micrograd_ai.py b/examples/micrograd_ai.py
index 5e4a41a4..8fb0f8e5 100644
--- a/examples/micrograd_ai.py
+++ b/examples/micrograd_ai.py
@@ -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)
diff --git a/pyproject.toml b/pyproject.toml
new file mode 100644
index 00000000..fdf96a22
--- /dev/null
+++ b/pyproject.toml
@@ -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
diff --git a/pyscriptjs/tests/integration/support.py b/pyscriptjs/tests/integration/support.py
index ac7b53b9..4da6a4a7 100644
--- a/pyscriptjs/tests/integration/support.py
+++ b/pyscriptjs/tests/integration/support.py
@@ -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
diff --git a/pyscriptjs/tests/integration/test_02_display.py b/pyscriptjs/tests/integration/test_02_display.py
index 1a2b7e5f..b51ab771 100644
--- a/pyscriptjs/tests/integration/test_02_display.py
+++ b/pyscriptjs/tests/integration/test_02_display.py
@@ -233,7 +233,10 @@ class TestOutput(PyScriptTest):
class Circle:
r = 0
def _repr_svg_(self):
- return f'' # noqa: E501
+ return (
+ f''
+ )
circle = Circle()
diff --git a/pyscriptjs/tests/integration/test_zz_examples.py b/pyscriptjs/tests/integration/test_zz_examples.py
index a1ab402a..0041e863 100644
--- a/pyscriptjs/tests/integration/test_zz_examples.py
+++ b/pyscriptjs/tests/integration/test_zz_examples.py
@@ -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()
diff --git a/setup.cfg b/setup.cfg
deleted file mode 100644
index cd01ef61..00000000
--- a/setup.cfg
+++ /dev/null
@@ -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