Skip to content

Commit

Permalink
Update pre-commit
Browse files Browse the repository at this point in the history
I also reordered prettier to come last since it's the slowest. I switched from
using black to ruff-format which says its defaults are nearly the same as black.
  • Loading branch information
hoodmane committed Jan 28, 2024
1 parent d6ccedf commit 1bce703
Show file tree
Hide file tree
Showing 48 changed files with 261 additions and 279 deletions.
6 changes: 3 additions & 3 deletions .devcontainer/conda/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// For config options, see https://github.com/devcontainers/features/tree/main/src/conda
"ghcr.io/devcontainers/features/conda": {
"version": "latest",
"addCondaForge": "true"
}
}
"addCondaForge": "true",
},
},
}
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
// keep in sync with "run_docker"
"image": "pyodide/pyodide-env:20230506-chrome112-firefox112-py311",
"remoteUser": "root",
"onCreateCommand": ".devcontainer/onCreate-docker.sh"
"onCreateCommand": ".devcontainer/onCreate-docker.sh",
}
30 changes: 13 additions & 17 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ default_language_version:
python: "3.11"
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: "v4.4.0"
rev: "v4.5.0"
hooks:
- id: check-added-large-files
- id: check-case-conflict
Expand All @@ -17,27 +17,18 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.0.254"
rev: "v0.1.14"
hooks:
- id: ruff
args: [--fix]

- repo: https://github.com/psf/black
rev: "23.1.0"
hooks:
- id: black
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-clang-format
rev: "v15.0.7"
rev: "v17.0.6"
hooks:
- id: clang-format
types_or: [c++, c, cuda]

- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v3.0.0-alpha.6"
hooks:
- id: prettier

- repo: https://github.com/pre-commit/pygrep-hooks
rev: "v1.10.0"
hooks:
Expand All @@ -48,24 +39,24 @@ repos:
- id: rst-inline-touching-normal

- repo: https://github.com/shellcheck-py/shellcheck-py
rev: "v0.9.0.2"
rev: "v0.9.0.6"
hooks:
- id: shellcheck
exclude: ^src/templates/python$

- repo: https://github.com/codespell-project/codespell
rev: "v2.2.4"
rev: "v2.2.6"
hooks:
- id: codespell
args:
[
"--ignore-words-list",
"ags,aray,asend,ba,classs,crate,falsy,feld,inflight,lits,nd,slowy,te",
"ags,aray,asend,ba,classs,crate,falsy,feld,inflight,lits,nd,slowy,te,oint",
]
exclude: ^(benchmark/benchmarks/pystone_benchmarks/pystone\.py|src/js/package-lock\.json)$

- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v1.1.1"
rev: "v1.8.0"
hooks:
- id: mypy
files: ^(packages/.*/src|src|pyodide-build/pyodide_build)
Expand Down Expand Up @@ -94,5 +85,10 @@ repos:
exclude: (^packages/.*/setup.py|/src|^packages/aiohttp/aiohttp_patch.py$)
additional_dependencies: *mypy-deps

- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v4.0.0-alpha.8"
hooks:
- id: prettier

ci:
autoupdate_schedule: "quarterly"
7 changes: 4 additions & 3 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Various common utilities for testing.
"""

import os
import pathlib
import re
Expand Down Expand Up @@ -92,7 +93,7 @@ def maybe_skip_test(item, delayed=False):

# Common package import test. Skip it if the package is not built.
if skip_msg is None and is_common_test and item.name.startswith("test_import"):
if not pytest.pyodide_runtimes:
if not pytest.pyodide_runtimes: # type: ignore[attr-defined]
skip_msg = "Not running browser tests"

else:
Expand Down Expand Up @@ -139,7 +140,7 @@ def cwd_relative_nodeid(*args):

config.cwd_relative_nodeid = cwd_relative_nodeid

pytest.pyodide_dist_dir = config.getoption("--dist-dir")
pytest.pyodide_dist_dir = config.getoption("--dist-dir") # type: ignore[attr-defined]


def pytest_collection_modifyitems(config, items):
Expand Down Expand Up @@ -255,7 +256,7 @@ def extra_checks_test_wrapper(browser, trace_hiwire_refs, trace_pyproxies):


def package_is_built(package_name):
return _package_is_built(package_name, pytest.pyodide_dist_dir)
return _package_is_built(package_name, pytest.pyodide_dist_dir) # type: ignore[attr-defined]


def strip_assertions_stderr(messages: Sequence[str]) -> list[str]:
Expand Down
7 changes: 5 additions & 2 deletions docs/_static/css/pyodide.css
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@ code.literal {
white-space: nowrap;
vertical-align: baseline;
border-radius: 0.25rem;
transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out,
border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
transition:
color 0.15s ease-in-out,
background-color 0.15s ease-in-out,
border-color 0.15s ease-in-out,
box-shadow 0.15s ease-in-out;
}
@media (prefers-reduced-motion: reduce) {
.badge {
Expand Down
3 changes: 2 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@
autosummary_generate = True
autodoc_default_flags = ["members", "inherited-members"]

micropip_version = micropip.__version__ # type:ignore[attr-defined]
intersphinx_mapping = {
"python": ("https://docs.python.org/3.11", None),
"micropip": (f"https://micropip.pyodide.org/en/v{micropip.__version__}/", None),
"micropip": (f"https://micropip.pyodide.org/en/v{micropip_version}/", None),
"numpy": ("https://numpy.org/doc/stable/", None),
}

Expand Down
2 changes: 1 addition & 1 deletion docs/project/roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ See {issue}`scipy/scipy#15290`.

Some of the challenges that Pyodide faces, such as maintaining a collection of
build recipes, dependency resolution from PyPI, etc are already solved in either
Python or JavaScript ecosystems. We should therefore strive to better re-use
Python or JavaScript ecosystems. We should therefore strive to better reuse
existing tooling, and seeking synergies with existing initiatives in this space,
such as conda-forge.

Expand Down
2 changes: 1 addition & 1 deletion packages/RobotRaconteur/test_robotraconteur_pyodide.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ def test_robotraconteur_exceptions(selenium):
RRN = RR.RobotRaconteurNode.s
RRN.SetNodeName("test_node")
assert RRN.NodeName == "test_node"
with pytest.raises(Exception):
with pytest.raises(Exception): # noqa: B017
RRN.SetNodeName("test_node")
2 changes: 1 addition & 1 deletion packages/aiohttp/test_aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ async def aiohttp_test_helper(selenium, patch, base_url, lock_data):

def test_aiohttp(selenium):
patch = (Path(__file__).parent / "aiohttp_patch.py").read_text()
dist_dir = cast(str, pytest.pyodide_dist_dir)
dist_dir = cast(str, pytest.pyodide_dist_dir) # type:ignore[attr-defined]
lock_data = (Path(dist_dir) / "pyodide-lock.json").read_text()
aiohttp_test_helper(selenium, patch, selenium.base_url, lock_data)
2 changes: 1 addition & 1 deletion packages/astropy/test_astropy.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async def test_astropy(selenium, package, specific_test):

import micropip

await micropip.install(
await micropip.install( # type:ignore[attr-defined]
["pytest_remotedata", "pytest_doctestplus", "pytest_astropy_header"]
)
assert (
Expand Down
55 changes: 23 additions & 32 deletions packages/cpp-exceptions-test/test_cpp_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@

@pytest.mark.requires_dynamic_linking
def test_uncaught_cpp_exceptions(selenium):
assert (
selenium.run_js(
"""
assert selenium.run_js(
"""
await pyodide.loadPackage("cpp-exceptions-test");
const Tests = pyodide._api.tests;
const throwlib = pyodide._module.LDSO.loadedLibsByName["/usr/lib/cpp-exceptions-test-throw.so"].exports;
Expand All @@ -20,25 +19,22 @@ def test_uncaught_cpp_exceptions(selenium):
}
return [t(1), t(2), t(3), t(4), t(5)];
"""
)
== [
"CppException int: The exception is an object of type int at address xxx "
"which does not inherit from std::exception",
"CppException char: The exception is an object of type char at address xxx "
"which does not inherit from std::exception",
"CppException std::runtime_error: abc",
"CppException myexception: My exception happened",
"CppException char const*: The exception is an object of type char const* at "
"address xxx which does not inherit from std::exception",
]
)
) == [
"CppException int: The exception is an object of type int at address xxx "
"which does not inherit from std::exception",
"CppException char: The exception is an object of type char at address xxx "
"which does not inherit from std::exception",
"CppException std::runtime_error: abc",
"CppException myexception: My exception happened",
"CppException char const*: The exception is an object of type char const* at "
"address xxx which does not inherit from std::exception",
]


@pytest.mark.requires_dynamic_linking
def test_cpp_exception_catching(selenium):
assert (
selenium.run_js(
"""
assert selenium.run_js(
"""
await pyodide.loadPackage("cpp-exceptions-test");
const Module = pyodide._module;
const catchlib = pyodide._module.LDSO.loadedLibsByName["/usr/lib/cpp-exceptions-test-catch.so"].exports;
Expand All @@ -51,28 +47,23 @@ def test_cpp_exception_catching(selenium):
return [t(1), t(2), t(3), t(5)];
"""
)
== [
"caught int 1000",
"caught char 99",
"caught runtime_error abc",
"caught ????",
]
)
) == [
"caught int 1000",
"caught char 99",
"caught runtime_error abc",
"caught ????",
]


@pytest.mark.requires_dynamic_linking
def test_sjlj(selenium):
assert (
(
selenium.run_js(
"""
selenium.run_js(
"""
await pyodide.loadPackage("cpp-exceptions-test");
const Module = pyodide._module;
const catchlib = pyodide._module.LDSO.loadedLibsByName["/usr/lib/cpp-exceptions-test-catch.so"].exports;
return catchlib.set_jmp_func();
"""
)
)
== 5
)
) == 5
2 changes: 1 addition & 1 deletion packages/fpcast-test/fpcast-test/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
"Operating System :: OS Independent",
],
# packages=["fpcast_test"],
ext_modules=[Extension("fpcast_test", ["fpcast-test.c"])]
ext_modules=[Extension("fpcast_test", ["fpcast-test.c"])],
# python_requires='>=3.6',
)
4 changes: 2 additions & 2 deletions packages/fpcast-test/test_fpcast_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ def test_fpcasts(selenium):
t.kwargs2()
t.kwargs3()

t.getset0
t.getset1
t.getset0 # noqa: B018
t.getset1 # noqa: B018
t.getset1 = 5
2 changes: 1 addition & 1 deletion packages/frozenlist/test_frozenlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ def test_dict_key(selenium):

_list = FrozenList([1, 2])
with pytest.raises(RuntimeError):
{_list: "hello"}
{_list: "hello"} # noqa: B018
_list.freeze()
{_list: "hello"} # noqa: B018

Expand Down
2 changes: 1 addition & 1 deletion packages/hashlib/test_hashlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ def test_hashlib_algorithms(selenium):
assert openssl_algorithm in algorithms_available

for algorithm in algorithms_available:
hashlib.new(algorithm).digest_size
hashlib.new(algorithm).digest_size # noqa: B018
2 changes: 1 addition & 1 deletion packages/libhdf5/settings/H5Tinit.c
Original file line number Diff line number Diff line change
Expand Up @@ -1060,7 +1060,7 @@ H5T__init_native(void)
/****************************************/
/* ALIGNMENT and signal-handling status */
/****************************************/
/* ALIGNAMENT test is not available */
/* ALIGNMENT test is not available */
/* Signal handlers verify test is not available */
/* Signal() support: no */
/* setjmp() support: yes */
Expand Down
11 changes: 4 additions & 7 deletions packages/micropip/test_micropip.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ def selenium_standalone_micropip(selenium_standalone):

def test_install_simple(selenium_standalone_micropip):
selenium = selenium_standalone_micropip
assert (
selenium.run_js(
"""
assert selenium.run_js(
"""
return await pyodide.runPythonAsync(`
import os
import micropip
Expand All @@ -63,9 +62,7 @@ def test_install_simple(selenium_standalone_micropip):
to_js(stemmer.stemWords('go going goes gone'.split()))
`);
"""
)
== ["go", "go", "goe", "gone"]
)
) == ["go", "go", "goe", "gone"]


@pytest.mark.parametrize("base_url", ["'{base_url}'", "'.'"])
Expand Down Expand Up @@ -233,7 +230,7 @@ async def run_test(selenium, url, wheel_name):

resp = await pyfetch(url + wheel_name)
await resp._into_file(open(wheel_name, "wb"))
await micropip.install("emfs:" + wheel_name)
await micropip.install("emfs:" + wheel_name) # type: ignore[attr-defined]
import snowballstemmer

stemmer = snowballstemmer.stemmer("english")
Expand Down
8 changes: 2 additions & 6 deletions packages/numcodecs/test_numcodecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,8 @@ def check_encode_decode(arr, codec, precision=None):
np.random.randint(-(2**63), -(2**63) + 20, size=1000, dtype="i8").view(
"m8[ns]"
),
np.random.randint(-(2**63), -(2**63) + 20, size=1000, dtype="i8").view(
"M8[m]"
),
np.random.randint(-(2**63), -(2**63) + 20, size=1000, dtype="i8").view(
"m8[m]"
),
np.random.randint(-(2**63), -(2**63) + 20, size=1000, dtype="i8").view("M8[m]"),
np.random.randint(-(2**63), -(2**63) + 20, size=1000, dtype="i8").view("m8[m]"),
]

codecs = [
Expand Down
1 change: 0 additions & 1 deletion pyodide-build/pyodide_build/_py_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from packaging.tags import Tag
from packaging.utils import parse_wheel_filename

from pyodide_build.common import _get_sha256_checksum

from .logger import logger, set_log_level
Expand Down
2 changes: 1 addition & 1 deletion pyodide-build/pyodide_build/build_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from io import StringIO
from pathlib import Path

if sys.version_info < (3, 11, 0):
if sys.version_info < (3, 11, 0): # noqa: UP036
import tomli as tomllib
else:
import tomllib
Expand Down
Loading

0 comments on commit 1bce703

Please sign in to comment.