pre-commit: Add codespell and other checks (#263)

This commit is contained in:
Christian Clauss
2022-05-06 23:23:14 +02:00
committed by GitHub
parent 990b0b2797
commit fadb4a67e7
9 changed files with 69 additions and 28 deletions

View File

@@ -6,24 +6,59 @@ repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
hooks:
- id: check-builtin-literals
- id: check-case-conflict
- id: check-docstring-first
- id: check-toml
- id: check-xml
- id: check-yaml
- id: detect-private-key
- id: end-of-file-fixer
exclude: \.min\.js$
- id: trailing-whitespace
- id: check-json
exclude: tsconfig.json
- id: check-yaml
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.3.0
- repo: https://github.com/PyCQA/bandit
rev: 1.7.4
hooks:
- id: pretty-format-yaml
args: [--autofix, --indent, '4']
- id: bandit
args:
- --skip=B201
- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
- repo: https://github.com/codespell-project/codespell
rev: v2.1.0
hooks:
- id: codespell # See 'setup.cfg' for args
- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
hooks:
- id: flake8 # See 'setup.cfg' for args
additional_dependencies: [flake8-bugbear, flake8-comprehensions]
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
name: isort (python)
args: [--profile, black]
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.3.0
hooks:
- id: pretty-format-yaml
args: [--autofix, --indent, '4']
- repo: https://github.com/asottile/pyupgrade
rev: v2.32.1
hooks:
- id: pyupgrade
args:
- --py310-plus

View File

@@ -1,5 +1,3 @@
from typing import Tuple
import numpy as np
from numpy.polynomial import Polynomial
@@ -14,7 +12,7 @@ def mandelbrot(
max_iterations: int = 100
) -> np.array:
"""
From https://www.learnpythonwithrune.org/numpy-compute-mandelbrot-set-by-vectorization/.
https://www.learnpythonwithrune.org/numpy-compute-mandelbrot-set-by-vectorization
"""
# To make navigation easier we calculate these values
x_width, y_height = 1.5, 1.5 * height / width
@@ -56,7 +54,7 @@ def julia(
max_iterations: int = 100
) -> np.array:
"""
From https://www.learnpythonwithrune.org/numpy-calculate-the-julia-set-with-vectorization/.
https://www.learnpythonwithrune.org/numpy-calculate-the-julia-set-with-vectorization
"""
# To make navigation easier we calculate these values
x_width, y_height = 1.5, 1.5 * height / width
@@ -84,7 +82,7 @@ def julia(
return div_time
Range = Tuple[float, float]
Range = tuple[float, float]
def newton(
@@ -96,7 +94,7 @@ def newton(
xr: Range = (-2.5, 1),
yr: Range = (-1, 1),
max_iterations: int = 100
) -> (np.array, np.array):
) -> tuple[np.array, np.array]:
""" """
# To make navigation easier we calculate these values
x_from, x_to = xr

File diff suppressed because one or more lines are too long

View File

@@ -42,7 +42,7 @@
<p>
Currently the <code>&gt;</code> symbol is being imported incorrectly as <code>&ampgt;</code> into the REPL's.
In this app the <code>&gt;</code> symbol has been replaced with <code>().__gt__()</code> so you can run the code
without issue. Ex: intead of <code>a &gt; b</code>, you will see <code>(a).__gt__(b)</code> instead. <br>
without issue. Ex: instead of <code>a &gt; b</code>, you will see <code>(a).__gt__(b)</code> instead. <br>
</p>
<p>
<py-script>import js; js.document.getElementById('python-status').innerHTML = 'Python is now ready. You may proceed.'</py-script>

View File

@@ -8,7 +8,7 @@ import numpy as np
# cell
from micrograd.engine import Value
from micrograd.nn import MLP, Layer, Neuron
from micrograd.nn import MLP
print_statements = []
@@ -43,7 +43,8 @@ def micrograd_demo(*args, **kwargs):
random.seed(1337)
# cell
# An adaptation of sklearn's make_moons function https://scikit-learn.org/stable/modules/generated/sklearn.datasets.make_moons.html
# An adaptation of sklearn's make_moons function
# https://scikit-learn.org/stable/modules/generated/sklearn.datasets.make_moons.html
def make_moons(n_samples=100, noise=None):
n_samples_out, n_samples_in = n_samples, n_samples
@@ -102,7 +103,7 @@ def micrograd_demo(*args, **kwargs):
data_loss = sum(losses) * (1.0 / len(losses))
# L2 regularization
alpha = 1e-4
reg_loss = alpha * sum((p * p for p in model.parameters()))
reg_loss = alpha * sum(p * p for p in model.parameters())
total_loss = data_loss + reg_loss
# also get accuracy
@@ -120,7 +121,7 @@ def micrograd_demo(*args, **kwargs):
for k in range(20): # was 100
# forward
total_loss, acc = loss()
total_loss, _ = loss()
# backward
model.zero_grad()
@@ -146,7 +147,7 @@ def micrograd_demo(*args, **kwargs):
Z = np.array([(s.data).__gt__(0) for s in scores])
Z = Z.reshape(xx.shape)
fig = plt.figure()
_ = plt.figure()
plt.contourf(xx, yy, Z, cmap=plt.cm.Spectral, alpha=0.8)
plt.scatter(X[:, 0], X[:, 1], c=y, s=40, cmap=plt.cm.Spectral)
plt.xlim(xx.min(), xx.max())

View File

@@ -1,6 +1,5 @@
from datetime import datetime as dt
from js import console
from utils import add_class, remove_class
tasks = []
@@ -27,7 +26,8 @@ def add_task(*ags, **kws):
tasks.append(task)
# add the task element to the page as new node in the list by cloning from a template
# add the task element to the page as new node in the list by cloning from a
# template
task_html = task_template.clone(task_id, to=task_list)
task_html_content = task_html.select("p")
task_html_content.element.innerText = task["content"]

View File

@@ -16,7 +16,7 @@ export class PyButton extends BaseEvalElement {
if (this.hasAttribute('label')) {
this.label = this.getAttribute('label');
}
// Styling does the same thing as class in normal HTML. Using the name "class" makes the style to malfunction
if (this.hasAttribute('styling')) {
let klass = this.getAttribute('styling');
@@ -25,7 +25,7 @@ export class PyButton extends BaseEvalElement {
}else{
klass = klass.trim()
const newClassArray = klass.split(' ');
// trim each element to remove unecessary spaces which makes the button style to malfunction
// trim each element to remove unnecessary spaces which makes the button style to malfunction
this.class = (() => {const concatenatedString = []; for (let i = 0; i < newClassArray.length; i++) {if (newClassArray[i].trim() !== '')(concatenatedString.push(newClassArray[i].trim()));} return concatenatedString;})();
}
}

View File

@@ -4,8 +4,8 @@ import io
import sys
import time
import micropip
from js import console, document, setInterval, setTimeout
import micropip # noqa: F401
from js import console, document
loop = asyncio.get_event_loop()
@@ -72,10 +72,9 @@ def format_mime(obj):
mimebundle = eval_formatter(obj, "_repr_mimebundle_")
if isinstance(mimebundle, tuple):
format_dict, md_dict = mimebundle
format_dict, _ = mimebundle
else:
format_dict = mimebundle
md_dict = {}
output, not_available = None, []
for method, mime_type in reversed(MIME_METHODS.items()):
@@ -130,7 +129,7 @@ class PyScript:
@staticmethod
def run_until_complete(f):
p = loop.run_until_complete(f)
_ = loop.run_until_complete(f)
class Element:
@@ -311,7 +310,6 @@ class PyListTemplate:
return [c.data for c in self._children]
def render_children(self):
out = []
binds = {}
for i, c in enumerate(self._children):
txt = c.element.innerHTML
@@ -328,7 +326,7 @@ class PyListTemplate:
srcEl.element.onclick()
evtEl.classList = srcEl.element.classList
for new_id, old_id in binds.items():
for new_id in binds:
Element(new_id).element.onclick = foo
def connect(self):

9
setup.cfg Normal file
View File

@@ -0,0 +1,9 @@
[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