Skip to content

Commit

Permalink
chore: Update pre-commit (pyodide#4440)
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 authored Jan 28, 2024
1 parent 5da4725 commit b8287e4
Show file tree
Hide file tree
Showing 44 changed files with 246 additions and 267 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"
1 change: 1 addition & 0 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
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__
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")
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
9 changes: 3 additions & 6 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
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
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
4 changes: 3 additions & 1 deletion pyodide-build/pyodide_build/buildall.py
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,8 @@ def set_default_build_args(build_args: BuildArgs) -> BuildArgs:
if args.host_install_dir is None:
args.host_install_dir = build_env.get_build_flag("HOSTINSTALLDIR") # type: ignore[unreachable]
if args.compression_level is None:
args.compression_level = int(build_env.get_build_flag("PYODIDE_ZIP_COMPRESSION_LEVEL")) # type: ignore[unreachable]
args.compression_level = int( # type: ignore[unreachable]
build_env.get_build_flag("PYODIDE_ZIP_COMPRESSION_LEVEL")
)

return args
5 changes: 4 additions & 1 deletion pyodide-build/pyodide_build/buildpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ def _make_whlfile(

shutil.register_archive_format("whl", _make_whlfile, description="Wheel file")
shutil.register_unpack_format(
"whl", [".whl", ".wheel"], shutil._unpack_zipfile, description="Wheel file" # type: ignore[attr-defined]
"whl",
[".whl", ".wheel"],
shutil._unpack_zipfile, # type: ignore[attr-defined]
description="Wheel file",
)


Expand Down
8 changes: 2 additions & 6 deletions pyodide-build/pyodide_build/cli/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,7 @@ def source(

# simple 'pyodide build' command
def main(
source_location: Optional[ # noqa: typer does not accept list[str] | None yet.
str
] = typer.Argument(
source_location: Optional[str] = typer.Argument( # noqa: UP007 typer does not accept list[str] | None yet.
"",
help="Build source, can be source folder, pypi version specification, "
"or url to a source dist archive or wheel file. If this is blank, it "
Expand Down Expand Up @@ -162,9 +160,7 @@ def main(
compression_level: int = typer.Option(
6, help="Compression level to use for the created zip file"
),
config_setting: Optional[ # noqa: typer does not accept list[str] | None yet.
list[str]
] = typer.Option(
config_setting: Optional[list[str]] = typer.Option( # noqa: UP007 typer does not accept list[str] | None yet.
None,
"--config-setting",
"-C",
Expand Down
Loading

0 comments on commit b8287e4

Please sign in to comment.