ci: switch from black to ruff

This commit is contained in:
David Hewitt 2023-10-26 08:52:07 +01:00
parent 2b91fea94f
commit 3042ab1621
12 changed files with 33 additions and 55 deletions

View File

@ -27,10 +27,10 @@ jobs:
- uses: dtolnay/rust-toolchain@stable - uses: dtolnay/rust-toolchain@stable
with: with:
components: rustfmt components: rustfmt
- name: Check python formatting (black) - name: Check python formatting and lints (ruff)
run: nox -s fmt-py run: nox -s ruff
- name: Check rust formatting (rustfmt) - name: Check rust formatting (rustfmt)
run: nox -s fmt-rust run: nox -s rustfmt
check-msrv: check-msrv:
needs: [fmt] needs: [fmt]

View File

@ -1,3 +1,6 @@
from decorator import Counter
@Counter @Counter
def say_hello(): def say_hello():
print("hello") print("hello")

View File

@ -45,7 +45,7 @@ def test_discussion_2598():
@Counter @Counter
def say_hello(): def say_hello():
if say_hello.count < 2: if say_hello.count < 2:
print(f"hello from decorator") print("hello from decorator")
say_hello() say_hello()
say_hello() say_hello()

View File

@ -1,7 +1,9 @@
# import the contents of the Rust library into the Python extension # 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 *
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"] __all__ = __all__ + ["PythonClass"]

View File

@ -1,2 +1,2 @@
def test_import(): def test_import():
import plugin_api import plugin_api # noqa: F401

View File

@ -1,7 +1,9 @@
# import the contents of the Rust library into the Python extension # 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 *
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"] __all__ = __all__ + ["PythonClass"]

View File

@ -14,7 +14,7 @@ def test_err1():
with pytest.raises( with pytest.raises(
TypeError, match="sum_as_string expected an int for positional argument 1" TypeError, match="sum_as_string expected an int for positional argument 1"
) as e: ):
sum_as_string(a, b) sum_as_string(a, b)
@ -23,19 +23,19 @@ def test_err2():
with pytest.raises( with pytest.raises(
TypeError, match="sum_as_string expected an int for positional argument 2" TypeError, match="sum_as_string expected an int for positional argument 2"
) as e: ):
sum_as_string(a, b) sum_as_string(a, b)
def test_overflow1(): def test_overflow1():
a, b = 0, 1 << 43 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) sum_as_string(a, b)
def test_overflow2(): def test_overflow2():
a, b = 1 << 30, 1 << 30 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) sum_as_string(a, b)

View File

@ -66,22 +66,17 @@ def coverage(session: nox.Session) -> None:
) )
@nox.session @nox.session(venv_backend="none")
def fmt(session: nox.Session): def rustfmt(session: nox.Session):
fmt_rust(session)
fmt_py(session)
@nox.session(name="fmt-rust", venv_backend="none")
def fmt_rust(session: nox.Session):
_run_cargo(session, "fmt", "--all", "--check") _run_cargo(session, "fmt", "--all", "--check")
_run_cargo(session, "fmt", _FFI_CHECK, "--all", "--check") _run_cargo(session, "fmt", _FFI_CHECK, "--all", "--check")
@nox.session(name="fmt-py") @nox.session(name="ruff")
def fmt_py(session: nox.Session): def ruff(session: nox.Session):
session.install("black==22.3.0") session.install("ruff")
_run(session, "black", ".", "--check") _run(session, "ruff", "format", ".", "--check")
_run(session, "ruff", "check", ".")
@nox.session(name="clippy", venv_backend="none") @nox.session(name="clippy", venv_backend="none")
@ -234,7 +229,7 @@ def contributors(session: nox.Session) -> None:
for commit in body["commits"]: for commit in body["commits"]:
try: try:
authors.add(commit["author"]["login"]) authors.add(commit["author"]["login"])
except: except Exception:
continue continue
if "next" in resp.links: if "next" in resp.links:

View File

@ -1,22 +1,5 @@
[tool.black] [tool.ruff.extend-per-file-ignores]
target_version = ['py35'] "__init__.py" = ["F403"]
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.towncrier] [tool.towncrier]
filename = "CHANGELOG.md" filename = "CHANGELOG.md"

View File

@ -118,16 +118,15 @@ def test_time(args, kwargs):
@given(t=st.times()) @given(t=st.times())
def test_time(t): def test_time_hypothesis(t):
act = rdt.get_time_tuple(t) act = rdt.get_time_tuple(t)
exp = (t.hour, t.minute, t.second, t.microsecond) exp = (t.hour, t.minute, t.second, t.microsecond)
assert act == exp assert act == exp
@pytest.mark.xfail(PYPY, reason="Feature not available on PyPy")
@given(t=st.times()) @given(t=st.times())
def test_time_fold(t): def test_time_tuple_fold(t):
t_nofold = t.replace(fold=0) t_nofold = t.replace(fold=0)
t_fold = t.replace(fold=1) t_fold = t.replace(fold=1)
@ -138,9 +137,8 @@ def test_time_fold(t):
assert act == exp assert act == exp
@pytest.mark.xfail(PYPY, reason="Feature not available on PyPy")
@pytest.mark.parametrize("fold", [False, True]) @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) t = rdt.time_with_fold(0, 0, 0, 0, None, fold)
assert t.fold == fold assert t.fold == fold
@ -206,7 +204,6 @@ def test_datetime_tuple(dt):
assert act == exp assert act == exp
@pytest.mark.xfail(PYPY, reason="Feature not available on PyPy")
@given(dt=st.datetimes()) @given(dt=st.datetimes())
def test_datetime_tuple_fold(dt): def test_datetime_tuple_fold(dt):
dt_fold = dt.replace(fold=1) dt_fold = dt.replace(fold=1)

View File

@ -1,8 +1,6 @@
import gc import gc
import platform
import sys import sys
import pytest
from pyo3_pytests.objstore import ObjStore from pyo3_pytests.objstore import ObjStore

View File

@ -1,5 +1,3 @@
import platform
from pyo3_pytests.subclassing import Subclassable from pyo3_pytests.subclassing import Subclassable