From 04af02f15561b590676339bae28957a637547ce8 Mon Sep 17 00:00:00 2001 From: David Hewitt <1939362+davidhewitt@users.noreply.github.com> Date: Thu, 26 Oct 2023 08:52:07 +0100 Subject: [PATCH] ci: switch from black to ruff --- .github/workflows/ci.yml | 6 +++--- examples/decorator/tests/example.py | 3 +++ examples/decorator/tests/test_.py | 2 +- .../maturin_starter/__init__.py | 6 ++++-- .../plugin/plugin_api/tests/test_import.py | 2 +- .../setuptools_rust_starter/__init__.py | 6 ++++-- examples/string-sum/tests/test_.py | 8 +++---- noxfile.py | 21 +++++++------------ pyproject.toml | 21 ++----------------- pytests/tests/test_datetime.py | 9 +++----- pytests/tests/test_objstore.py | 2 -- pytests/tests/test_subclassing.py | 2 -- 12 files changed, 33 insertions(+), 55 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 55bacb77..ba78ca84 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,10 +27,10 @@ jobs: - uses: dtolnay/rust-toolchain@stable with: components: rustfmt - - name: Check python formatting (black) - run: nox -s fmt-py + - name: Check python formatting and lints (ruff) + run: nox -s ruff - name: Check rust formatting (rustfmt) - run: nox -s fmt-rust + run: nox -s rustfmt check-msrv: needs: [fmt] diff --git a/examples/decorator/tests/example.py b/examples/decorator/tests/example.py index 5725a2ed..7be4b33e 100644 --- a/examples/decorator/tests/example.py +++ b/examples/decorator/tests/example.py @@ -1,3 +1,6 @@ +from decorator import Counter + + @Counter def say_hello(): print("hello") diff --git a/examples/decorator/tests/test_.py b/examples/decorator/tests/test_.py index 26056713..d97bf27d 100644 --- a/examples/decorator/tests/test_.py +++ b/examples/decorator/tests/test_.py @@ -45,7 +45,7 @@ def test_discussion_2598(): @Counter def say_hello(): if say_hello.count < 2: - print(f"hello from decorator") + print("hello from decorator") say_hello() say_hello() diff --git a/examples/maturin-starter/maturin_starter/__init__.py b/examples/maturin-starter/maturin_starter/__init__.py index 5fe00cb5..d0525f19 100644 --- a/examples/maturin-starter/maturin_starter/__init__.py +++ b/examples/maturin-starter/maturin_starter/__init__.py @@ -1,7 +1,9 @@ # import the contents of the Rust library into the Python extension -# optional: include the documentation from the Rust module from .maturin_starter import * -from .maturin_starter import __all__, __doc__ +from .maturin_starter import __all__ + +# optional: include the documentation from the Rust module +from .maturin_starter import __doc__ # noqa: F401 __all__ = __all__ + ["PythonClass"] diff --git a/examples/plugin/plugin_api/tests/test_import.py b/examples/plugin/plugin_api/tests/test_import.py index ae1d6f67..2a728920 100644 --- a/examples/plugin/plugin_api/tests/test_import.py +++ b/examples/plugin/plugin_api/tests/test_import.py @@ -1,2 +1,2 @@ def test_import(): - import plugin_api + import plugin_api # noqa: F401 diff --git a/examples/setuptools-rust-starter/setuptools_rust_starter/__init__.py b/examples/setuptools-rust-starter/setuptools_rust_starter/__init__.py index 1dcb91e0..ecca1d15 100644 --- a/examples/setuptools-rust-starter/setuptools_rust_starter/__init__.py +++ b/examples/setuptools-rust-starter/setuptools_rust_starter/__init__.py @@ -1,7 +1,9 @@ # import the contents of the Rust library into the Python extension -# optional: include the documentation from the Rust module from ._setuptools_rust_starter import * -from ._setuptools_rust_starter import __all__, __doc__ +from ._setuptools_rust_starter import __all__ + +# optional: include the documentation from the Rust module +from ._setuptools_rust_starter import __doc__ # noqa: F401 __all__ = __all__ + ["PythonClass"] diff --git a/examples/string-sum/tests/test_.py b/examples/string-sum/tests/test_.py index d9b5ab5f..a3e88a63 100644 --- a/examples/string-sum/tests/test_.py +++ b/examples/string-sum/tests/test_.py @@ -14,7 +14,7 @@ def test_err1(): with pytest.raises( TypeError, match="sum_as_string expected an int for positional argument 1" - ) as e: + ): sum_as_string(a, b) @@ -23,19 +23,19 @@ def test_err2(): with pytest.raises( TypeError, match="sum_as_string expected an int for positional argument 2" - ) as e: + ): sum_as_string(a, b) def test_overflow1(): a, b = 0, 1 << 43 - with pytest.raises(OverflowError, match="cannot fit 8796093022208 in 32 bits") as e: + with pytest.raises(OverflowError, match="cannot fit 8796093022208 in 32 bits"): sum_as_string(a, b) def test_overflow2(): a, b = 1 << 30, 1 << 30 - with pytest.raises(OverflowError, match="arguments too large to add") as e: + with pytest.raises(OverflowError, match="arguments too large to add"): sum_as_string(a, b) diff --git a/noxfile.py b/noxfile.py index 583b6051..27f8befb 100644 --- a/noxfile.py +++ b/noxfile.py @@ -66,22 +66,17 @@ def coverage(session: nox.Session) -> None: ) -@nox.session -def fmt(session: nox.Session): - fmt_rust(session) - fmt_py(session) - - -@nox.session(name="fmt-rust", venv_backend="none") -def fmt_rust(session: nox.Session): +@nox.session(venv_backend="none") +def rustfmt(session: nox.Session): _run_cargo(session, "fmt", "--all", "--check") _run_cargo(session, "fmt", _FFI_CHECK, "--all", "--check") -@nox.session(name="fmt-py") -def fmt_py(session: nox.Session): - session.install("black==22.3.0") - _run(session, "black", ".", "--check") +@nox.session(name="ruff") +def ruff(session: nox.Session): + session.install("ruff") + _run(session, "ruff", "format", ".", "--check") + _run(session, "ruff", "check", ".") @nox.session(name="clippy", venv_backend="none") @@ -221,7 +216,7 @@ def contributors(session: nox.Session) -> None: for commit in body["commits"]: try: authors.add(commit["author"]["login"]) - except: + except Exception: continue if "next" in resp.links: diff --git a/pyproject.toml b/pyproject.toml index 70263bcf..29626e97 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,22 +1,5 @@ -[tool.black] -target_version = ['py35'] -include = '\.pyi?$' -exclude = ''' - -( - /( - \.eggs # exclude a few common directories in the - | \.git # root of the project - | \.mypy_cache - | \.tox - | \.nox - | \.venv - | venv - | target - | dist - )/ -) -''' +[tool.ruff.extend-per-file-ignores] +"__init__.py" = ["F403"] [tool.towncrier] filename = "CHANGELOG.md" diff --git a/pytests/tests/test_datetime.py b/pytests/tests/test_datetime.py index d4c1b60e..c81d13a9 100644 --- a/pytests/tests/test_datetime.py +++ b/pytests/tests/test_datetime.py @@ -118,16 +118,15 @@ def test_time(args, kwargs): @given(t=st.times()) -def test_time(t): +def test_time_hypothesis(t): act = rdt.get_time_tuple(t) exp = (t.hour, t.minute, t.second, t.microsecond) assert act == exp -@pytest.mark.xfail(PYPY, reason="Feature not available on PyPy") @given(t=st.times()) -def test_time_fold(t): +def test_time_tuple_fold(t): t_nofold = t.replace(fold=0) t_fold = t.replace(fold=1) @@ -138,9 +137,8 @@ def test_time_fold(t): assert act == exp -@pytest.mark.xfail(PYPY, reason="Feature not available on PyPy") @pytest.mark.parametrize("fold", [False, True]) -def test_time_fold(fold): +def test_time_with_fold(fold): t = rdt.time_with_fold(0, 0, 0, 0, None, fold) assert t.fold == fold @@ -206,7 +204,6 @@ def test_datetime_tuple(dt): assert act == exp -@pytest.mark.xfail(PYPY, reason="Feature not available on PyPy") @given(dt=st.datetimes()) def test_datetime_tuple_fold(dt): dt_fold = dt.replace(fold=1) diff --git a/pytests/tests/test_objstore.py b/pytests/tests/test_objstore.py index 0b1f46f4..bfd8bad8 100644 --- a/pytests/tests/test_objstore.py +++ b/pytests/tests/test_objstore.py @@ -1,8 +1,6 @@ import gc -import platform import sys -import pytest from pyo3_pytests.objstore import ObjStore diff --git a/pytests/tests/test_subclassing.py b/pytests/tests/test_subclassing.py index 5851c033..2cee283d 100644 --- a/pytests/tests/test_subclassing.py +++ b/pytests/tests/test_subclassing.py @@ -1,5 +1,3 @@ -import platform - from pyo3_pytests.subclassing import Subclassable