Skip to content

Commit 2a7a5df

Browse files
committed
use ruff
1 parent 04108e5 commit 2a7a5df

File tree

10 files changed

+27
-20
lines changed

10 files changed

+27
-20
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ concurrency:
1010
cancel-in-progress: true
1111

1212
jobs:
13-
fmt:
13+
ruff:
1414
runs-on: "ubuntu-latest"
1515
steps:
1616
- uses: actions/checkout@v4
@@ -20,9 +20,9 @@ jobs:
2020
with:
2121
python-version: "3.x"
2222

23-
- run: pip install black
23+
- run: pip install nox
2424

25-
- run: black --check .
25+
- run: nox -s ruff
2626

2727
mypy:
2828
runs-on: "ubuntu-latest"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ dist
77
build
88
target
99
.pytest_cache
10+
.ruff_cache
1011
*.egg-info
1112
pyo3
1213
docs/_build

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[![github actions](https://github.com/PyO3/setuptools-rust/actions/workflows/ci.yml/badge.svg)](https://github.com/PyO3/setuptools-rust/actions/workflows/ci.yml)
44
[![pypi package](https://badge.fury.io/py/setuptools-rust.svg)](https://pypi.org/project/setuptools-rust/)
55
[![readthedocs](https://readthedocs.org/projects/pip/badge/)](https://setuptools-rust.readthedocs.io/en/latest/)
6-
[![code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)
6+
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
77

88
`setuptools-rust` is a plugin for `setuptools` to build Rust Python extensions implemented with [PyO3](https://github.com/PyO3/pyo3) or [rust-cpython](https://github.com/dgrunwald/rust-cpython).
99

@@ -14,7 +14,7 @@ they were written in C.
1414

1515
The following is a very basic tutorial that shows how to use `setuptools-rust` in `pyproject.toml`.
1616
It assumes that you already have a bunch of Python and Rust files that you want
17-
to distribute. You can see examples for these files in the
17+
to distribute. You can see examples for these files in the
1818
[`examples/hello-world`](https://github.com/PyO3/setuptools-rust/tree/main/examples/hello-world)
1919
directory in the [github repository](https://github.com/PyO3/setuptools-rust).
2020
The [PyO3 docs](https://pyo3.rs) have detailed information on how to write Python

docs/conf.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
# list see the documentation:
55
# https://www.sphinx-doc.org/en/master/usage/configuration.html
66

7+
from sphinx.transforms import SphinxTransform
8+
79
# -- Path setup --------------------------------------------------------------
810

911
# If extensions (or modules to document with autodoc) are in another directory,
@@ -57,8 +59,6 @@
5759
# This is necessary because the README.md (for example) has links to the latest
5860
# documentation, but we want them to be relative to the specific docs version.
5961

60-
from sphinx.transforms import SphinxTransform
61-
6262
DOCS_URL = "https://setuptools-rust.readthedocs.io/en/latest/"
6363

6464

@@ -68,10 +68,12 @@ class RelativeDocLinks(SphinxTransform):
6868
def apply(self):
6969
from docutils.nodes import Text, reference
7070

71-
baseref = lambda o: (
72-
isinstance(o, reference) and o.get("refuri", "").startswith(DOCS_URL)
73-
)
74-
basetext = lambda o: (isinstance(o, Text) and o.startswith(DOCS_URL))
71+
def baseref(o):
72+
return isinstance(o, reference) and o.get("refuri", "").startswith(DOCS_URL)
73+
74+
def basetext(o):
75+
return isinstance(o, Text) and o.startswith(DOCS_URL)
76+
7577
for node in self.document.traverse(baseref):
7678
target = node["refuri"].replace(DOCS_URL, "", 1)
7779
node.replace_attr("refuri", target)

examples/hello-world/python/hello_world/sum_cli.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import argparse
2-
import sys
32

43
from ._lib import sum_as_string
54

examples/html-py-ever/tests/run_all.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@
99

1010
try:
1111
import lxml
12-
13-
HAVE_LXML = True
1412
except ImportError:
15-
HAVE_LXML = False
13+
lxml = None
1614

1715

1816
def rust(filename: str) -> Tuple[int, float, float]:
@@ -51,7 +49,7 @@ def main():
5149
print(f"Parse py {parse_py:6f}s {parse_py/parse_rs:6.3f}x")
5250
print(f"Select py {select_py:6f}s {select_py/select_rs:6.3f}x")
5351

54-
if HAVE_LXML:
52+
if lxml is not None:
5553
count_lxml, parse_lxml, select_lxml = python(filename, "lxml")
5654
assert count_rs == count_lxml
5755
print(f"Parse lxml {parse_lxml:6f}s {parse_lxml/parse_rs:6.3f}x")

noxfile.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,13 @@ def test_crossenv(session: nox.Session):
136136
)
137137

138138

139+
@nox.session()
140+
def ruff(session: nox.Session):
141+
session.install("ruff")
142+
session.run("ruff", "format", "--check", ".")
143+
session.run("ruff", ".")
144+
145+
139146
@nox.session()
140147
def mypy(session: nox.Session):
141148
session.install("mypy", "fat_macho", "types-setuptools", ".")

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ Changelog = "https://github.com/PyO3/setuptools-rust/blob/main/CHANGELOG.md"
4949
requires = ["setuptools>=62.4", "setuptools_scm"]
5050
build-backend = "setuptools.build_meta"
5151

52-
[tool.isort]
53-
profile = "black"
52+
[tool.ruff.extend-per-file-ignores]
53+
"__init__.py" = ["F403"]
5454

5555
[tool.pytest.ini_options]
5656
minversion = "6.0"

setuptools_rust/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from .build import build_rust
22
from .clean import clean_rust
33
from .extension import Binding, RustBin, RustExtension, Strip
4-
from .version import version as __version__
4+
from .version import version as __version__ # noqa: F401
55

66
__all__ = ("Binding", "RustBin", "RustExtension", "Strip", "build_rust", "clean_rust")

tests/test_build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ def test_adjusted_local_rust_target_windows_gnu():
1919
assert _adjusted_local_rust_target("win-amd64") == "x86_64-pc-windows-gnu"
2020

2121

22-
def test_adjusted_local_rust_target_windows_gnu():
22+
def test_adjusted_local_rust_target_macos():
2323
with mock.patch("platform.machine", lambda: "x86_64"):
2424
assert _adjusted_local_rust_target("macosx-") == "x86_64-apple-darwin"

0 commit comments

Comments
 (0)