Skip to content

Commit

Permalink
style: improve pre-commit (pyodide#2177)
Browse files Browse the repository at this point in the history
  • Loading branch information
henryiii authored Feb 19, 2022
1 parent 30ea13f commit 41b6db1
Show file tree
Hide file tree
Showing 19 changed files with 163 additions and 140 deletions.
5 changes: 5 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ jobs:
steps:
- checkout

- run:
name: Install lint requirements
command: |
python -m pip install pre-commit
- run:
name: lint
command: make lint
Expand Down
39 changes: 30 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,57 @@ default_language_version:
python: "3.9"
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
rev: "v4.1.0"
hooks:
- id: check-yaml
exclude: .clang-format
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/psf/black
rev: 20.8b1
rev: "22.1.0"
hooks:
- id: black

- repo: https://gitlab.com/pycqa/flake8
rev: 3.7.8
rev: 3.9.2
hooks:
- id: flake8
types: [file, python]
# only check for unused imports, as the rest is done by black
args: [--select=F401]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.812
rev: v0.931
hooks:
- id: mypy
args:
- --show-error-codes
- --ignore-missing-imports
- repo: local
files: ^(src/|packages/.*/test|conftest.py|docs/)
additional_dependencies: &mypy-deps
- packaging
- types-docutils
- types-pyyaml
- types-setuptools
- id: mypy
name: mypy-micropip
files: ^packages/micropip/src/
args: &mypy-args
- --show-error-codes
additional_dependencies: *mypy-deps
- id: mypy
name: mypy-pyodide-build
files: ^pyodide-build/pyodide_build/
args: *mypy-args
additional_dependencies: *mypy-deps

- repo: https://github.com/pre-commit/mirrors-clang-format
rev: "v13.0.0"
hooks:
- id: clang-format
name: clang-format-6.0
language: system
entry: ./tools/clang-format-precommit.sh

- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v2.3.2" # Use the sha / tag you want to point at
rev: "v2.5.1"
hooks:
- id: prettier
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ emsdk
cpython
.vscode
.pytest_cache
.clang-format
.clang-format
packages/CLAPACK/make.inc
30 changes: 3 additions & 27 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -136,33 +136,9 @@ update_base_url: \



lint: node_modules/.installed
# check for unused imports, the rest is done by black
flake8 --select=F401 src tools pyodide-build benchmark conftest.py docs packages/matplotlib/src/
mypy --ignore-missing-imports \
pyodide-build/pyodide_build/ \
src/ \
packages/*/test* \
conftest.py \
docs
#mypy gets upset about there being both : src / py / setup.py and
#packages / micropip / src / setup.py.There is no easy way to fix this right now
#see python / mypy #10428. This will also cause trouble with pre - commit if you
#modify both setup.py files in the same commit.
mypy --ignore-missing-imports \
packages/micropip/src/

# Format checks
for file in src/core/*.c src/core/*.h ; do \
clang-format-6.0 -output-replacements-xml $$file | grep '<replacement ' > /dev/null ; \
if [ $$? -eq 0 ] ; then \
echo clang-format errors for $$file ; \
exit 1 ; \
fi ; \
done
npx prettier --check .
black --check .

.PHONY: lint
lint:
pre-commit run -a --show-diff-on-failure

benchmark: all
$(HOSTPYTHON) benchmark/benchmark.py $(HOSTPYTHON) build/benchmarks.json
Expand Down
3 changes: 2 additions & 1 deletion docs/sphinx_pyodide/sphinx_pyodide/jsdoc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from docutils import nodes
from docutils.parsers.rst import Directive, Parser as RstParser, directives
from docutils.parsers.rst import Directive, Parser as RstParser
import docutils.parsers.rst.directives as directives
from docutils.statemachine import StringList
from docutils.utils import new_document

Expand Down
2 changes: 1 addition & 1 deletion packages/CLAPACK/make.inc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ F2CCFLAGS = $(CFLAGS)
# For gfortran compiler: SECOND and DSECND will use a call to the INTERNAL FUNCTION ETIME
# TIMER = INT_ETIME
# If your Fortran compiler does not provide etime (like Nag Fortran Compiler, etc...)
# SECOND and DSECND will use a call to the Fortran standard INTERNAL FUNCTION CPU_TIME
# SECOND and DSECND will use a call to the Fortran standard INTERNAL FUNCTION CPU_TIME
TIMER = INT_CPU_TIME
# If neither of this works...you can use the NONE value... In that case, SECOND and DSECND will always return 0
# TIMER = NONE
Expand Down
127 changes: 68 additions & 59 deletions packages/fpcast-test/fpcast-test/fpcast-test.c
Original file line number Diff line number Diff line change
@@ -1,69 +1,78 @@
#define PY_SSIZE_T_CLEAN
#include <Python.h>


static PyObject *zero(void){
Py_RETURN_NONE;
static PyObject*
zero(void)
{
Py_RETURN_NONE;
}

static PyObject *one(PyObject *self){
Py_RETURN_NONE;
static PyObject*
one(PyObject* self)
{
Py_RETURN_NONE;
}

static PyObject *two(PyObject *self, PyObject *args){
Py_RETURN_NONE;
static PyObject*
two(PyObject* self, PyObject* args)
{
Py_RETURN_NONE;
}

static PyObject *three(PyObject *self, PyObject *args, PyObject *kwargs){
Py_RETURN_NONE;
static PyObject*
three(PyObject* self, PyObject* args, PyObject* kwargs)
{
Py_RETURN_NONE;
}

static int set_two(PyObject* self, PyObject* value){
return 0;
static int
set_two(PyObject* self, PyObject* value)
{
return 0;
}

// These two structs are the same but it's important that they have to be
// duplicated here or else we miss test coverage.
static PyMethodDef Test_Functions[] = {
{"noargs0",(PyCFunction)zero, METH_NOARGS},
{"noargs1", (PyCFunction)one, METH_NOARGS},
{"noargs2", (PyCFunction)two, METH_NOARGS},
{"noargs3", (PyCFunction)three, METH_NOARGS},

{"varargs0",(PyCFunction)zero, METH_VARARGS},
{"varargs1", (PyCFunction)one, METH_VARARGS},
{"varargs2", (PyCFunction)two, METH_VARARGS},
{"varargs3", (PyCFunction)three, METH_VARARGS},

{"kwargs0", (PyCFunction)zero, METH_VARARGS | METH_KEYWORDS},
{"kwargs1", (PyCFunction)one, METH_VARARGS | METH_KEYWORDS},
{"kwargs2", (PyCFunction)two, METH_VARARGS | METH_KEYWORDS},
{"kwargs3", (PyCFunction)three, METH_VARARGS | METH_KEYWORDS},
{NULL, NULL, 0, NULL}
{ "noargs0", (PyCFunction)zero, METH_NOARGS },
{ "noargs1", (PyCFunction)one, METH_NOARGS },
{ "noargs2", (PyCFunction)two, METH_NOARGS },
{ "noargs3", (PyCFunction)three, METH_NOARGS },

{ "varargs0", (PyCFunction)zero, METH_VARARGS },
{ "varargs1", (PyCFunction)one, METH_VARARGS },
{ "varargs2", (PyCFunction)two, METH_VARARGS },
{ "varargs3", (PyCFunction)three, METH_VARARGS },

{ "kwargs0", (PyCFunction)zero, METH_VARARGS | METH_KEYWORDS },
{ "kwargs1", (PyCFunction)one, METH_VARARGS | METH_KEYWORDS },
{ "kwargs2", (PyCFunction)two, METH_VARARGS | METH_KEYWORDS },
{ "kwargs3", (PyCFunction)three, METH_VARARGS | METH_KEYWORDS },
{ NULL, NULL, 0, NULL }
};

static PyMethodDef Test_Methods[] = {
{"noargs0",(PyCFunction)zero, METH_NOARGS},
{"noargs1", (PyCFunction)one, METH_NOARGS},
{"noargs2", (PyCFunction)two, METH_NOARGS},
{"noargs3", (PyCFunction)three, METH_NOARGS},

{"varargs0",(PyCFunction)zero, METH_VARARGS},
{"varargs1", (PyCFunction)one, METH_VARARGS},
{"varargs2", (PyCFunction)two, METH_VARARGS},
{"varargs3", (PyCFunction)three, METH_VARARGS},

{"kwargs0", (PyCFunction)zero, METH_VARARGS | METH_KEYWORDS},
{"kwargs1", (PyCFunction)one, METH_VARARGS | METH_KEYWORDS},
{"kwargs2", (PyCFunction)two, METH_VARARGS | METH_KEYWORDS},
{"kwargs3", (PyCFunction)three, METH_VARARGS | METH_KEYWORDS},
{NULL, NULL, 0, NULL}
{ "noargs0", (PyCFunction)zero, METH_NOARGS },
{ "noargs1", (PyCFunction)one, METH_NOARGS },
{ "noargs2", (PyCFunction)two, METH_NOARGS },
{ "noargs3", (PyCFunction)three, METH_NOARGS },

{ "varargs0", (PyCFunction)zero, METH_VARARGS },
{ "varargs1", (PyCFunction)one, METH_VARARGS },
{ "varargs2", (PyCFunction)two, METH_VARARGS },
{ "varargs3", (PyCFunction)three, METH_VARARGS },

{ "kwargs0", (PyCFunction)zero, METH_VARARGS | METH_KEYWORDS },
{ "kwargs1", (PyCFunction)one, METH_VARARGS | METH_KEYWORDS },
{ "kwargs2", (PyCFunction)two, METH_VARARGS | METH_KEYWORDS },
{ "kwargs3", (PyCFunction)three, METH_VARARGS | METH_KEYWORDS },
{ NULL, NULL, 0, NULL }
};

static PyGetSetDef Test_GetSet[] = {
{ "getset0", .get = (getter)zero },
{ "getset1", .get = (getter)one, .set = (setter)set_two },
{ NULL }
{ "getset0", .get = (getter)zero },
{ "getset1", .get = (getter)one, .set = (setter)set_two },
{ NULL }
};

static PyTypeObject TestType = {
Expand Down Expand Up @@ -113,22 +122,22 @@ static PyTypeObject Callable3 = {
};

static struct PyModuleDef module = {
PyModuleDef_HEAD_INIT,
"fpcast_test", /* name of module */
"Tests for the fpcast handling", /* module documentation, may be NULL */
-1, /* size of per-interpreter state of the module,
or -1 if the module keeps state in global variables. */
Test_Methods
PyModuleDef_HEAD_INIT,
"fpcast_test", /* name of module */
"Tests for the fpcast handling", /* module documentation, may be NULL */
-1, /* size of per-interpreter state of the module,
or -1 if the module keeps state in global variables. */
Test_Methods
};


PyMODINIT_FUNC PyInit_fpcast_test(void)
PyMODINIT_FUNC
PyInit_fpcast_test(void)
{
PyObject* module_object = PyModule_Create(&module);
PyModule_AddType(module_object, &TestType);
PyModule_AddType(module_object, &Callable0);
PyModule_AddType(module_object, &Callable1);
PyModule_AddType(module_object, &Callable2);
PyModule_AddType(module_object, &Callable3);
return module_object;
PyObject* module_object = PyModule_Create(&module);
PyModule_AddType(module_object, &TestType);
PyModule_AddType(module_object, &Callable0);
PyModule_AddType(module_object, &Callable1);
PyModule_AddType(module_object, &Callable2);
PyModule_AddType(module_object, &Callable3);
return module_object;
}
3 changes: 0 additions & 3 deletions packages/joblib/test_joblib.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import pytest


def test_joblib_numpy_pickle(selenium, request):
selenium.load_package(["numpy", "joblib"])
selenium.run(
Expand Down
5 changes: 2 additions & 3 deletions packages/micropip/src/micropip/package.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from collections import UserDict
from dataclasses import dataclass, field, astuple
from pathlib import Path
from typing import List, Dict, Iterable
from dataclasses import dataclass, astuple
from typing import List, Iterable

__all__ = ["PackageDict"]

Expand Down
2 changes: 1 addition & 1 deletion packages/msgpack/test_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

@run_in_pyodide(standalone=True, packages=["msgpack"])
def test_pack():
from msgpack import packb, unpackb, Unpacker, Packer, pack
from msgpack import packb, unpackb, Unpacker, Packer, pack # noqa: F401

def check(data, use_list=False):
re = unpackb(packb(data), use_list=use_list, strict_map_key=False)
Expand Down
3 changes: 0 additions & 3 deletions packages/scipy/test_scipy.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import pytest
from conftest import selenium_context_manager
from pyodide_build import testing

run_in_pyodide = testing.run_in_pyodide(
Expand All @@ -13,7 +11,6 @@
@run_in_pyodide
def test_scipy_linalg():
import numpy as np
import scipy as sp
import scipy.linalg
from numpy.testing import assert_allclose

Expand Down
Loading

0 comments on commit 41b6db1

Please sign in to comment.