Skip to content

Commit

Permalink
use ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhewitt committed Oct 25, 2023
1 parent 04108e5 commit 2a7a5df
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 20 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ concurrency:
cancel-in-progress: true

jobs:
fmt:
ruff:
runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@v4
Expand All @@ -20,9 +20,9 @@ jobs:
with:
python-version: "3.x"

- run: pip install black
- run: pip install nox

- run: black --check .
- run: nox -s ruff

mypy:
runs-on: "ubuntu-latest"
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ dist
build
target
.pytest_cache
.ruff_cache
*.egg-info
pyo3
docs/_build
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![github actions](https://github.com/PyO3/setuptools-rust/actions/workflows/ci.yml/badge.svg)](https://github.com/PyO3/setuptools-rust/actions/workflows/ci.yml)
[![pypi package](https://badge.fury.io/py/setuptools-rust.svg)](https://pypi.org/project/setuptools-rust/)
[![readthedocs](https://readthedocs.org/projects/pip/badge/)](https://setuptools-rust.readthedocs.io/en/latest/)
[![code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)
[![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)

`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).

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

The following is a very basic tutorial that shows how to use `setuptools-rust` in `pyproject.toml`.
It assumes that you already have a bunch of Python and Rust files that you want
to distribute. You can see examples for these files in the
to distribute. You can see examples for these files in the
[`examples/hello-world`](https://github.com/PyO3/setuptools-rust/tree/main/examples/hello-world)
directory in the [github repository](https://github.com/PyO3/setuptools-rust).
The [PyO3 docs](https://pyo3.rs) have detailed information on how to write Python
Expand Down
14 changes: 8 additions & 6 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

from sphinx.transforms import SphinxTransform

# -- Path setup --------------------------------------------------------------

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

from sphinx.transforms import SphinxTransform

DOCS_URL = "https://setuptools-rust.readthedocs.io/en/latest/"


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

baseref = lambda o: (
isinstance(o, reference) and o.get("refuri", "").startswith(DOCS_URL)
)
basetext = lambda o: (isinstance(o, Text) and o.startswith(DOCS_URL))
def baseref(o):
return isinstance(o, reference) and o.get("refuri", "").startswith(DOCS_URL)

def basetext(o):
return isinstance(o, Text) and o.startswith(DOCS_URL)

for node in self.document.traverse(baseref):
target = node["refuri"].replace(DOCS_URL, "", 1)
node.replace_attr("refuri", target)
Expand Down
1 change: 0 additions & 1 deletion examples/hello-world/python/hello_world/sum_cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import argparse
import sys

from ._lib import sum_as_string

Expand Down
6 changes: 2 additions & 4 deletions examples/html-py-ever/tests/run_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@

try:
import lxml

HAVE_LXML = True
except ImportError:
HAVE_LXML = False
lxml = None


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

if HAVE_LXML:
if lxml is not None:
count_lxml, parse_lxml, select_lxml = python(filename, "lxml")
assert count_rs == count_lxml
print(f"Parse lxml {parse_lxml:6f}s {parse_lxml/parse_rs:6.3f}x")
Expand Down
7 changes: 7 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,13 @@ def test_crossenv(session: nox.Session):
)


@nox.session()
def ruff(session: nox.Session):
session.install("ruff")
session.run("ruff", "format", "--check", ".")
session.run("ruff", ".")


@nox.session()
def mypy(session: nox.Session):
session.install("mypy", "fat_macho", "types-setuptools", ".")
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ Changelog = "https://github.com/PyO3/setuptools-rust/blob/main/CHANGELOG.md"
requires = ["setuptools>=62.4", "setuptools_scm"]
build-backend = "setuptools.build_meta"

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

[tool.pytest.ini_options]
minversion = "6.0"
Expand Down
2 changes: 1 addition & 1 deletion setuptools_rust/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .build import build_rust
from .clean import clean_rust
from .extension import Binding, RustBin, RustExtension, Strip
from .version import version as __version__
from .version import version as __version__ # noqa: F401

__all__ = ("Binding", "RustBin", "RustExtension", "Strip", "build_rust", "clean_rust")
2 changes: 1 addition & 1 deletion tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ def test_adjusted_local_rust_target_windows_gnu():
assert _adjusted_local_rust_target("win-amd64") == "x86_64-pc-windows-gnu"


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

0 comments on commit 2a7a5df

Please sign in to comment.