Skip to content

Commit

Permalink
Merge pull request #3551 from davidhewitt/ruff
Browse files Browse the repository at this point in the history
ci: switch from black to ruff
  • Loading branch information
adamreichold committed Oct 27, 2023
2 parents aa6622b + 3042ab1 commit 579af5e
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 55 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
3 changes: 3 additions & 0 deletions examples/decorator/tests/example.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from decorator import Counter


@Counter
def say_hello():
print("hello")
Expand Down
2 changes: 1 addition & 1 deletion examples/decorator/tests/test_.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
6 changes: 4 additions & 2 deletions examples/maturin-starter/maturin_starter/__init__.py
Original file line number Diff line number Diff line change
@@ -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"]

Expand Down
2 changes: 1 addition & 1 deletion examples/plugin/plugin_api/tests/test_import.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
def test_import():
import plugin_api
import plugin_api # noqa: F401
Original file line number Diff line number Diff line change
@@ -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"]

Expand Down
8 changes: 4 additions & 4 deletions examples/string-sum/tests/test_.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand All @@ -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)
21 changes: 8 additions & 13 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -234,7 +229,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:
Expand Down
21 changes: 2 additions & 19 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
9 changes: 3 additions & 6 deletions pytests/tests/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions pytests/tests/test_objstore.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import gc
import platform
import sys

import pytest
from pyo3_pytests.objstore import ObjStore


Expand Down
2 changes: 0 additions & 2 deletions pytests/tests/test_subclassing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import platform

from pyo3_pytests.subclassing import Subclassable


Expand Down

0 comments on commit 579af5e

Please sign in to comment.