Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruff is now compatible with Python pattern matching #3650

Merged
merged 6 commits into from
Mar 13, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ repos:
- id: trailing-whitespace

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

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

- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v0.991"
rev: "v1.1.1"
hooks:
- id: mypy
files: ^(packages/.*/src|src|pyodide-build/pyodide_build)
Expand All @@ -55,18 +55,18 @@ repos:
additional_dependencies: *mypy-deps

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

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

- repo: https://github.com/pre-commit/pygrep-hooks
rev: "v1.9.0"
rev: "v1.10.0"
hooks:
- id: python-use-type-annotations
exclude: docs/sphinx_pyodide/tests/test_directives\.py
Expand All @@ -81,13 +81,13 @@ repos:
exclude: ^src/templates/python$

- repo: https://github.com/codespell-project/codespell
rev: "v2.2.2"
rev: "v2.2.4"
hooks:
- id: codespell
args:
[
"-L",
"te,slowy,aray,ba,nd,classs,crate,feld,lits,inflight,falsy,asend",
"--ignore-words-list",
"ags,aray,asend,ba,classs,crate,falsy,feld,inflight,lits,nd,slowy,te",
]
exclude: ^benchmark/benchmarks/pystone_benchmarks/pystone\.py$

Expand Down
2 changes: 0 additions & 2 deletions benchmark/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ def parse_args(benchmarks):


def main():

BENCHMARKS = {
"pystone": get_pystone_benchmarks,
"numpy": get_numpy_benchmarks,
Expand All @@ -187,7 +186,6 @@ def main():
]

with spawn_web_server(args.dist_dir) as (hostname, port, log_path):

# selenium initialization time
result = {"native": float("NaN")}
for browser_name, cls in browser_cls:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# non-native
# setup: import matplotlib ; import numpy as np ; matplotlib.use('module://matplotlib_pyodide.html5_canvas_backend') ; from matplotlib import pyplot as plt ; from matplotlib.dates import (YEARLY, DateFormatter, rrulewrapper, RRuleLocator, drange) ; import datetime
# setup: import matplotlib ; import numpy as np ; matplotlib.use('module://matplotlib_pyodide.html5_canvas_backend') ; from matplotlib import pyplot as plt ; from matplotlib.dates import (YEARLY, DateFormatter, rrulewrapper, RRuleLocator, drange) ; import datetime # noqa: E501
# run: canvas_text_rotated()

# pythran export canvas_text_rotated()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# non-native
# setup: import matplotlib ; import numpy as np ; matplotlib.use('module://matplotlib_pyodide.wasm_backend') ; from matplotlib import pyplot as plt ; from matplotlib.dates import (YEARLY, DateFormatter, rrulewrapper, RRuleLocator, drange) ; import datetime
# setup: import matplotlib ; import numpy as np ; matplotlib.use('module://matplotlib_pyodide.wasm_backend') ; from matplotlib import pyplot as plt ; from matplotlib.dates import (YEARLY, DateFormatter, rrulewrapper, RRuleLocator, drange) ; import datetime # noqa: E501
# run: wasm_text_rotated()

# pythran export wasm_text_rotated()
Expand Down
1 change: 0 additions & 1 deletion benchmark/benchmarks/numpy_benchmarks/growcut.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ def growcut(image, state, state_next, window_radius):

for j in range(width):
for i in range(height):

winning_colony = state[i, j, 0]
defense_strength = state[i, j, 1]

Expand Down
1 change: 0 additions & 1 deletion benchmark/benchmarks/numpy_benchmarks/multiple_sum.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


def multiple_sum(array):

rows = array.shape[0]
cols = array.shape[1]

Expand Down
2 changes: 1 addition & 1 deletion benchmark/benchmarks/pandas_benchmarks/join_df.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# setup: import pandas as pd ; import numpy ; N = 1000000 ; df1 = pd.DataFrame(numpy.random.randint(0, 10, size=(N, 3)), columns=["col1", "col2", "col3"]) ; df2 = pd.DataFrame(numpy.random.randint(0, 10, size=(N, 3)), columns=["col4", "col5", "col6"])
# setup: import pandas as pd ; import numpy ; N = 1000000 ; df1 = pd.DataFrame(numpy.random.randint(0, 10, size=(N, 3)), columns=["col1", "col2", "col3"]) ; df2 = pd.DataFrame(numpy.random.randint(0, 10, size=(N, 3)), columns=["col4", "col5", "col6"]) # noqa: E501
# run: join_df(df1, df2)


Expand Down
3 changes: 1 addition & 2 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,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: # type: ignore[truthy-bool]
if not pytest.pyodide_runtimes:
skip_msg = "Not running browser tests"

else:
Expand Down Expand Up @@ -157,7 +157,6 @@ def pytest_terminal_summary(terminalreporter):
continue

for test in tr.stats[status]:

if test.when != "call": # discard results from setup/teardown
continue

Expand Down
6 changes: 3 additions & 3 deletions docs/project/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ _January 3, 2023_
`JsGenerator`s.
{pr}`3294`

- {{ Enhancement }} It is now possible to use aynchronous JavaScript iterables,
- {{ Enhancement }} It is now possible to use asynchronous JavaScript iterables,
iterators and generators from Python. This includes support for `aiter` for
async interables, `anext` and `asend` for async iterators, and `athrow` and
`aclose` for async generators.
Expand Down Expand Up @@ -332,8 +332,8 @@ _January 3, 2023_
error would have `e.type === "StopIteration"`)
{pr}`3289`

- {{ Enhancement }} It is now possible to use aynchronous Python generators from
JavaScript.
- {{ Enhancement }} It is now possible to use asynchronous Python generators
from JavaScript.
{pr}`3290`

- {{ Enhancement }} PyProxies of synchronous and asynchronous Python generators
Expand Down
6 changes: 3 additions & 3 deletions docs/sphinx_pyodide/sphinx_pyodide/jsdoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,10 +525,10 @@ def get_val():
pyproxy_subclasses = []
pyproxy_methods: dict[str, list[Any]] = {}

for (key, doclet) in self.doclets.items():
for key, doclet in self.doclets.items():
self.set_doclet_is_private(key, doclet)

for (key, doclet) in self.doclets.items():
for key, doclet in self.doclets.items():
if doclet.is_private:
continue

Expand Down Expand Up @@ -811,7 +811,7 @@ def get_items(self, names):
prefixes = get_import_prefixes_from_env(self.env)
items = orig_get_items(self, names)
new_items = []
for (name, item) in zip(names, items, strict=True):
for name, item in zip(names, items, strict=True):
name = name.removeprefix("~")
_, obj, *_ = self.import_by_name(name, prefixes=prefixes)
prefix = "**async** " if iscoroutinefunction(obj) else ""
Expand Down
1 change: 0 additions & 1 deletion packages/fiona/test_fiona.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def _run(selenium, data):
import pytest

def runtest(test_filter, ignore_filters):

ignore_filter = []
for ignore in ignore_filters:
ignore_filter.append("--ignore-glob")
Expand Down
1 change: 0 additions & 1 deletion packages/geopandas/test_geopandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ def test_runtest(selenium):
test_path = Path(geopandas.__file__).parent / "tests"

def runtest(test_filter, ignore_filters):

ignore_filter = []
for ignore in ignore_filters:
ignore_filter.append("--ignore-glob")
Expand Down
1 change: 0 additions & 1 deletion packages/numcodecs/test_numcodecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def compare_arrays(arr, res, precision=None):
assert_array_almost_equal(arr, res, decimal=precision)

def check_encode_decode(arr, codec, precision=None):

# N.B., watch out here with blosc compressor, if the itemsize of
# the source buffer is different then the results of encoding
# (i.e., compression) may be different. Hence we *do not* require that
Expand Down
4 changes: 1 addition & 3 deletions packages/numpy/test_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_numpy(selenium):
def test_typed_arrays(selenium):
selenium.load_package("numpy")
selenium.run("import numpy")
for (jstype, npytype) in (
for jstype, npytype in (
("Int8Array", "int8"),
("Uint8Array", "uint8"),
("Uint8ClampedArray", "uint8"),
Expand Down Expand Up @@ -65,7 +65,6 @@ def test_typed_arrays(selenium):
),
)
def test_python2js_numpy_dtype(selenium, order, dtype):

selenium.load_package("numpy")
selenium.run("import numpy as np")

Expand Down Expand Up @@ -145,7 +144,6 @@ def test_py2js_buffer_clear_error_flag(selenium):
),
)
def test_python2js_numpy_scalar(selenium, dtype):

selenium.load_package("numpy")
selenium.run("import numpy as np")
selenium.run(
Expand Down
5 changes: 2 additions & 3 deletions packages/opencv-python/test_opencv_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,6 @@ def drawAxis(img, p_, q_, colour, scale):
)

def getOrientation(pts, img):

sz = len(pts)
data_pts = np.empty((sz, 2), dtype=np.float64)
for i in range(data_pts.shape[0]):
Expand Down Expand Up @@ -484,14 +483,14 @@ def run(selenium, comp, img, ref_face):

faces = face_cascade.detectMultiScale(gray)
face_detected = src.copy()
for (x, y, w, h) in faces:
for x, y, w, h in faces:
center = (x + w // 2, y + h // 2)
face_detected = cv.ellipse(
face_detected, center, (w // 2, h // 2), 0, 0, 360, (255, 0, 255), 4
)
faceROI = gray[y : y + h, x : x + w]
eyes = eyes_cascade.detectMultiScale(faceROI)
for (x2, y2, w2, h2) in eyes:
for x2, y2, w2, h2 in eyes:
eye_center = (x + x2 + w2 // 2, y + y2 + h2 // 2)
radius = int(round((w2 + h2) * 0.25))
face_detected = cv.circle(
Expand Down
1 change: 0 additions & 1 deletion packages/pandas/test_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def generate_largish_json(n_rows: int = 91746) -> dict[str, Any]:

@pytest.mark.driver_timeout(30)
def test_extra_import(selenium, request):

selenium.load_package("pandas")
selenium.run("from pandas import Series, DataFrame")

Expand Down
1 change: 0 additions & 1 deletion packages/python-sat/test_python_sat.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
@pytest.mark.parametrize("name", solvers)
@run_in_pyodide(packages=["python-sat"])
def test_solvers(selenium, name):

from pysat.formula import CNF
from pysat.solvers import Solver

Expand Down
1 change: 0 additions & 1 deletion packages/sparseqr/test_sparseqr.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def test_scipy_linalg(selenium):
# print( abs( Q*R - M*sparseqr.permutation_vector_to_matrix(E) ).sum() ) # should be approximately zero

for ib in range(n_test):

b = numpy.zeros(10)
b[ib] = 1

Expand Down
1 change: 0 additions & 1 deletion packages/xgboost/test_xgboost.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def test_compat(selenium):
def test_basic_classification(selenium):
@run_in_pyodide(packages=["xgboost"])
def run(selenium, data_train):

with open("dermatology.data", "wb") as f:
f.write(data_train)

Expand Down
2 changes: 0 additions & 2 deletions pyodide-build/pyodide_build/buildall.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ def tests_path(self) -> Path | None:
return None

def build(self, build_args: BuildArgs) -> None:

p = subprocess.run(
[
sys.executable,
Expand Down Expand Up @@ -242,7 +241,6 @@ def __rich__(self):


def _validate_package_map(pkg_map: dict[str, BasePackage]) -> bool:

# Check if dependencies are valid
for pkg_name, pkg in pkg_map.items():
for runtime_dep_name in pkg.run_dependencies:
Expand Down
3 changes: 1 addition & 2 deletions pyodide-build/pyodide_build/cli/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import shutil
import tempfile
from pathlib import Path
from typing import Optional, cast
from typing import Optional
from urllib.parse import urlparse

import requests
Expand Down Expand Up @@ -68,7 +68,6 @@ def url(
curdir = Path.cwd()
(curdir / "dist").mkdir(exist_ok=True)
with requests.get(package_url, stream=True) as response:
response = cast(requests.Response, response) # pragma: no cover
parsed_url = urlparse(response.url)
filename = os.path.basename(parsed_url.path)
name_base, ext = os.path.splitext(filename)
Expand Down
2 changes: 1 addition & 1 deletion pyodide-build/pyodide_build/cli/xbuildenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def _install(
"""
Install xbuildenv.

The isntalled environment is the same as the one that would result from
The installed environment is the same as the one that would result from
`PYODIDE_PACKAGES='scipy' make` except that it is much faster.
The goal is to enable out-of-tree builds for binary packages that depend
on numpy or scipy.
Expand Down
1 change: 0 additions & 1 deletion pyodide-build/pyodide_build/mkpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ def update_package(
update_patched: bool = True,
source_fmt: Literal["wheel", "sdist"] | None = None,
) -> None:

yaml = YAML()

meta_path = root / package / "meta.yaml"
Expand Down
1 change: 0 additions & 1 deletion pyodide-build/pyodide_build/out_of_tree/pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ def get_metadata_for_wheel(url):


class PyPIProvider(APBase):

BUILD_FLAGS: list[str] = []
BUILD_SKIP: list[str] = []
BUILD_EXPORTS: str = ""
Expand Down
1 change: 0 additions & 1 deletion pyodide-build/pyodide_build/pyzip.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ def filterfunc(path: Path | str, names: list[str]) -> set[str]:

_names = []
for name in names:

fullpath = path / name

if _should_skip(fullpath) or fullpath in filtered_files:
Expand Down
2 changes: 1 addition & 1 deletion pyodide-build/pyodide_build/tests/fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def temp_xbuildenv(tmp_path_factory):

.output_vars:
set
"""
""" # noqa: W191
)
(pyodide_root / "dist").mkdir()
(pyodide_root / "dist" / "repodata.json").write_text(
Expand Down
1 change: 0 additions & 1 deletion pyodide-build/pyodide_build/tests/test_buildall.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ def test_requirements_executable(monkeypatch):

@pytest.mark.parametrize("exe", ["rustc", "cargo", "rustup"])
def test_is_rust_package(exe):

pkg = buildall.BasePackage(
pkgdir=Path(""),
name="test",
Expand Down
2 changes: 0 additions & 2 deletions pyodide-build/pyodide_build/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ def test_build_recipe_no_deps_continue(selenium, tmp_path):


def test_config_list():

result = runner.invoke(
config.app,
[
Expand All @@ -273,7 +272,6 @@ def test_config_list():

@pytest.mark.parametrize("cfg_name,env_var", config.PYODIDE_CONFIGS.items())
def test_config_get(cfg_name, env_var):

result = runner.invoke(
config.app,
[
Expand Down
4 changes: 2 additions & 2 deletions pyodide-build/pyodide_build/tests/test_pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,9 @@ def __init__(self, *args, **argv):
server_evt.wait()
# now ret_values[0] should be server
server = ret_values[0]
addr = f"http://{server.server_address[0]}:{server.server_address[1]}/simple"
addr = f"http://{server.server_address[0]}:{server.server_address[1]}/simple" # type: ignore[str-bytes-safe]

yield (addr, f"{server.server_address[0]}:{server.server_address[1]}")
yield (addr, f"{server.server_address[0]}:{server.server_address[1]}") # type: ignore[str-bytes-safe]
# cleanup
server.shutdown()

Expand Down
Loading