Skip to content

Commit

Permalink
pre-commit: Add ruff to replace bandit, flake8, isort, and pyupgrade (p…
Browse files Browse the repository at this point in the history
…yscript#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
  • Loading branch information
cclauss authored Mar 6, 2023
1 parent 71d24a4 commit 7ffe6a5
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 42 deletions.
33 changes: 6 additions & 27 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
6 changes: 4 additions & 2 deletions examples/micrograd_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ def loss(batch_size=None):
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
Expand All @@ -109,7 +111,7 @@ def loss(batch_size=None):
# 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)

Expand Down
39 changes: 39 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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
5 changes: 4 additions & 1 deletion pyscriptjs/tests/integration/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,10 @@ def wait_for_console(self, text, *, timeout=None, check_js_errors=True):
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
Expand Down
5 changes: 4 additions & 1 deletion pyscriptjs/tests/integration/test_02_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,10 @@ def test_display_multiple_append_false_with_target(self):
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()
Expand Down
2 changes: 1 addition & 1 deletion pyscriptjs/tests/integration/test_zz_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_simple_clock(self):
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()

Expand Down
10 changes: 0 additions & 10 deletions setup.cfg

This file was deleted.

0 comments on commit 7ffe6a5

Please sign in to comment.