Skip to content

Commit 25f4c87

Browse files
[pre-commit.ci] pre-commit autoupdate (#144)
1 parent c121096 commit 25f4c87

19 files changed

Lines changed: 113 additions & 178 deletions

.pre-commit-config.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ default_language_version:
22
python: "3.10"
33
repos:
44
- repo: https://github.com/pre-commit/pre-commit-hooks
5-
rev: "v4.4.0"
5+
rev: "v6.0.0"
66
hooks:
77
- id: check-added-large-files
88
- id: check-case-conflict
@@ -15,19 +15,19 @@ repos:
1515
- id: mixed-line-ending
1616
- id: trailing-whitespace
1717

18-
- repo: https://github.com/charliermarsh/ruff-pre-commit
19-
rev: "v0.9.7"
18+
- repo: https://github.com/astral-sh/ruff-pre-commit
19+
rev: "v0.15.20"
2020
hooks:
2121
- id: ruff
2222
args: [--fix]
2323

24-
- repo: https://github.com/psf/black
25-
rev: "23.1.0"
24+
- repo: https://github.com/psf/black-pre-commit-mirror
25+
rev: "26.5.1"
2626
hooks:
2727
- id: black
2828

2929
- repo: https://github.com/pre-commit/mirrors-mypy
30-
rev: "v1.15.0"
30+
rev: "v2.1.0"
3131
hooks:
3232
- id: mypy
3333
exclude: (setup.py|^tests|conftest.py)
@@ -41,12 +41,12 @@ repos:
4141
- pytest
4242

4343
- repo: https://github.com/shellcheck-py/shellcheck-py
44-
rev: "v0.9.0.2"
44+
rev: "v0.11.0.1"
4545
hooks:
4646
- id: shellcheck
4747

4848
- repo: https://github.com/codespell-project/codespell
49-
rev: "v2.2.4"
49+
rev: "v2.4.2"
5050
hooks:
5151
- id: codespell
5252
args: ["-L", "te,slowy,aray,ba,nd,classs,crate,feld,lits"]

examples/test_install_package.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,11 @@ def test_install_from_custom_server(selenium_standalone):
1010
url = base_url + "snowballstemmer-2.2.0-py2.py3-none-any.whl"
1111

1212
selenium = selenium_standalone
13-
selenium.run_js(
14-
f"""
13+
selenium.run_js(f"""
1514
await pyodide.loadPackage({url!r});
16-
"""
17-
)
18-
selenium.run(
19-
"""
15+
""")
16+
selenium.run("""
2017
import snowballstemmer
2118
stemmer = snowballstemmer.stemmer('english')
2219
assert stemmer.stemWords(["university"]) == ["univers"]
23-
"""
24-
)
20+
""")

pyproject.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,12 @@ lint.select = [
9393
"RET505",
9494
"RET506",
9595
]
96-
lint.ignore = ["E402", "E501", "E731", "E741"]
97-
# line-length = 219 # E501: Recommended goal is 88 to match black
98-
target-version = "py312"
96+
lint.ignore = [
97+
"E402", # import not at top of file
98+
"E501", # line too long
99+
"PLC0415", # import outside top level
100+
]
101+
target-version = "py311"
99102

100103

101104
[tool.ruff.lint.isort]

pytest_pyodide/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ def set_initialize_script(self, initialize_script: str):
5252
def get_initialize_script(self) -> str:
5353
return self.initialize_script
5454

55-
def add_node_extra_globals(self, l: Iterable[str]):
56-
self.node_extra_globals.extend(l)
55+
def add_node_extra_globals(self, extra_globals: Iterable[str]):
56+
self.node_extra_globals.extend(extra_globals)
5757

5858
def get_node_extra_globals(self) -> Sequence[str]:
5959
return self.node_extra_globals

pytest_pyodide/copy_files_to_pyodide.py

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ def copy_files_to_emscripten_fs(
9292
# fetch all files into the pyodide
9393
# n.b. this might be slow for big packages
9494

95-
selenium.run(
96-
"""
95+
selenium.run("""
9796
import os
9897
from pathlib import Path
9998
from pyodide.http import pyfetch
@@ -107,37 +106,28 @@ async def _fetch_file(src,dest):
107106
byte_data = await response.bytes()
108107
fp.write(byte_data)
109108
110-
"""
111-
)
109+
""")
112110
for file, dest in new_files:
113111
_copied_files[selenium].append((file, dest))
114112
file_url = base_url + str(file.relative_to(base_path).as_posix())
115113
if file.suffix == ".whl" and install_wheels:
116114
# wheel - install the wheel on the pyodide side before
117115
# any fetches (and don't copy it)
118-
selenium.run_async(
119-
f"""
116+
selenium.run_async(f"""
120117
all_wheels.append("{file_url}")
121-
"""
122-
)
118+
""")
123119
else:
124120
# add file to fetches
125-
selenium.run_async(
126-
f"""
121+
selenium.run_async(f"""
127122
all_fetches.append(_fetch_file("{file_url}",Path("{dest}")))
128-
"""
129-
)
123+
""")
130124
# install all wheels with micropip
131-
selenium.run_async(
132-
"""
125+
selenium.run_async("""
133126
import micropip
134127
await micropip.install(all_wheels)
135-
"""
136-
)
128+
""")
137129
# fetch everything all at once
138-
selenium.run_async(
139-
"""
130+
selenium.run_async("""
140131
import asyncio, os, os.path
141132
await asyncio.gather(*all_fetches)
142-
"""
143-
)
133+
""")

pytest_pyodide/decorator.py

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,17 @@ class SeleniumType(Protocol):
2727
JavascriptException: type
2828
browser: str
2929

30-
def load_package(self, pkgs: str | list[str]):
31-
...
30+
def load_package(self, pkgs: str | list[str]): ...
3231

33-
def run_async(self, code: str):
34-
...
32+
def run_async(self, code: str): ...
3533

36-
def run_js(self, code: str):
37-
...
34+
def run_js(self, code: str): ...
3835

3936

4037
class _ReadableFileobj(Protocol):
41-
def read(self, __n: int) -> bytes:
42-
...
38+
def read(self, __n: int) -> bytes: ...
4339

44-
def readline(self) -> bytes:
45-
...
40+
def readline(self) -> bytes: ...
4641

4742

4843
class Unpickler(pickle.Unpickler):
@@ -86,11 +81,9 @@ def __del__(self):
8681
return
8782
ptr = self.ptr
8883
self.ptr = None
89-
self.selenium.run_js(
90-
f"""
84+
self.selenium.run_js(f"""
9185
pyodide._module._Py_DecRef({ptr});
92-
"""
93-
)
86+
""")
9487

9588

9689
def _encode(obj: Any) -> str:
@@ -246,12 +239,10 @@ def <func_name>(<selenium_arg_name>, arg1, arg2, arg3):
246239
# Make onwards call with two args:
247240
# 1. <selenium_arg_name>
248241
# 2. all other arguments in a tuple
249-
func_body = ast.parse(
250-
"""\
242+
func_body = ast.parse("""\
251243
__tracebackhide__ = True; \
252244
return run(selenium_arg_name, (arg1, arg2, ...)) \
253-
""".strip()
254-
).body
245+
""".strip()).body
255246
onwards_call = func_body[1].value # type: ignore[attr-defined]
256247
onwards_call.func = ast.Name(id=run_id, ctx=ast.Load())
257248
onwards_call.args[0].id = selenium_arg_name # Set variable name
@@ -293,8 +284,7 @@ def initialize_decorator(selenium):
293284
_decorator_in_pyodide = (
294285
Path(__file__).parent / "_decorator_in_pyodide.py"
295286
).read_text()
296-
selenium.run(
297-
f"""
287+
selenium.run(f"""
298288
def temp():
299289
_decorator_in_pyodide = '''{_decorator_in_pyodide}'''
300290
from importlib.machinery import ModuleSpec
@@ -315,8 +305,7 @@ def temp():
315305
sys.modules[modname] = mod
316306
temp()
317307
del temp
318-
"""
319-
)
308+
""")
320309

321310

322311
def _locate_funcdef(
@@ -547,24 +536,20 @@ def __init__(
547536

548537
def _get_code_prelude(self):
549538
"""Start coverage with the coverage_args passed from the host"""
550-
return dedent(
551-
f"""
539+
return dedent(f"""
552540
from pytest_pyodide.decorator import start_coverage
553541
coverage = start_coverage({_encode(self._coverage_args)!r})
554-
"""
555-
)
542+
""")
556543

557544
def _get_code_epilogue(self):
558545
"""Stop coverage and append the data to the result"""
559-
return dedent(
560-
"""
546+
return dedent("""
561547
from pytest_pyodide.decorator import end_coverage
562548
coverage_outdata = end_coverage(coverage)
563549
result = (*result, coverage_outdata)
564-
"""
565-
)
550+
""")
566551

567-
def _process_extra(self, coverage_out_binary): # type:ignore[override]
552+
def _process_extra(self, coverage_out_binary): # type: ignore[override]
568553
"""Write coverage data to the file system"""
569554
_get_coverage_path().write_bytes(b64decode(coverage_out_binary))
570555

pytest_pyodide/doctest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def collect(self):
6969
"""Call super and then if test includes the RUN_IN_PYODIDE option on the
7070
first line, make one copy for each Pyodide runtime environment
7171
"""
72-
for item in super().collect(): # type:ignore[misc]
72+
for item in super().collect(): # type: ignore[misc]
7373
pyodide_test = RUN_IN_PYODIDE in item.dtest.examples[0].options
7474
item.dtest.pyodide_test = pyodide_test
7575
if not pyodide_test:
@@ -140,7 +140,7 @@ def run_doctest_in_pyodide_outer(
140140
# So we just take the DocTestRunner apart and put it back together inside
141141
# Pyodide.
142142
optionflags = self.optionflags
143-
continue_on_failure = self.continue_on_failure # type:ignore[attr-defined]
143+
continue_on_failure = self.continue_on_failure # type: ignore[attr-defined]
144144

145145
return run_doctest_in_pyodide_inner(
146146
selenium, optionflags, continue_on_failure, test, compileflags, out, clear_globs

pytest_pyodide/fixture.py

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def wrapper(*args, **kwargs):
161161
kwargs[orig_name] = kwargs.pop(new_name)
162162
return f(*args, **kwargs)
163163

164-
wrapper.__signature__ = new_sig # type:ignore[attr-defined]
164+
wrapper.__signature__ = new_sig # type: ignore[attr-defined]
165165
return wrapper
166166

167167
return use_variant
@@ -295,10 +295,11 @@ def selenium_context_manager(selenium_module_scope):
295295

296296
@pytest.fixture
297297
def selenium(request, selenium_module_scope):
298-
with selenium_context_manager(
299-
selenium_module_scope
300-
) as selenium, set_webdriver_script_timeout(
301-
selenium, script_timeout=parse_driver_timeout(request.node)
298+
with (
299+
selenium_context_manager(selenium_module_scope) as selenium,
300+
set_webdriver_script_timeout(
301+
selenium, script_timeout=parse_driver_timeout(request.node)
302+
),
302303
):
303304
yield selenium
304305

@@ -337,10 +338,11 @@ def selenium_worker_context_manager(selenium_worker_module_scope):
337338

338339
@pytest.fixture
339340
def selenium_worker(request, selenium_worker_module_scope):
340-
with selenium_worker_context_manager(
341-
selenium_worker_module_scope
342-
) as selenium, set_webdriver_script_timeout(
343-
selenium, script_timeout=parse_driver_timeout(request.node)
341+
with (
342+
selenium_worker_context_manager(selenium_worker_module_scope) as selenium,
343+
set_webdriver_script_timeout(
344+
selenium, script_timeout=parse_driver_timeout(request.node)
345+
),
344346
):
345347
yield selenium
346348

@@ -368,15 +370,18 @@ def selenium_jspi_inner(
368370
pytest.skip(f"jspi not supported in {runtime}")
369371
if request.config.option.runner.lower() == "playwright":
370372
pytest.skip("jspi not supported with playwright")
371-
with selenium_common(
372-
request,
373-
runtime,
374-
web_server_main,
375-
browsers=playwright_browsers,
376-
jspi=True,
377-
worker=worker,
378-
) as selenium, set_webdriver_script_timeout(
379-
selenium, script_timeout=parse_driver_timeout(request.node)
373+
with (
374+
selenium_common(
375+
request,
376+
runtime,
377+
web_server_main,
378+
browsers=playwright_browsers,
379+
jspi=True,
380+
worker=worker,
381+
) as selenium,
382+
set_webdriver_script_timeout(
383+
selenium, script_timeout=parse_driver_timeout(request.node)
384+
),
380385
):
381386
yield selenium
382387

pytest_pyodide/run_tests_inside_pyodide.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,17 +127,15 @@ def run_test_in_pyodide(node_tree_id, selenium, ignore_fail=False):
127127
"-o",
128128
"junit_logging=out-err",
129129
]
130-
ret_xml = selenium.run_async(
131-
f"""
130+
ret_xml = selenium.run_async(f"""
132131
import pytest
133132
retcode = pytest.main({all_args})
134133
135134
output_xml=""
136135
with open("test_output.xml","r") as f:
137136
output_xml=f.read()
138137
output_xml
139-
"""
140-
)
138+
""")
141139
# get the error from junitxml
142140
root = ET.fromstring(ret_xml)
143141
fails = root.findall("*/testcase[failure]")

0 commit comments

Comments
 (0)