Liking cljdoc? Tell your friends :D

com.blockether.ruff

Clojure binding to ruff (https://github.com/astral-sh/ruff) for Python code FORMATTING ONLY, through the JDK Foreign Function & Memory API.

ruff does not publish a C-ABI library — only a CLI. So this binds a tiny first-party cdylib, ruff-c (native/ruff-c, a thin extern "C" wrapper over ruff's ruff_python_formatter crate), exactly the way clj-fff binds fff-c. Formatting runs IN-PROCESS via a downcall — no subprocess, no CLI, no config discovery. format takes Python source and returns it reformatted (long calls/collections wrapped multiline, black-compatible style).

Run the JVM with --enable-native-access=ALL-UNNAMED so the foreign linker may load the library without a restricted-method warning.

The library is resolved ONCE, lazily, the first time it's needed:

  1. RUFF_NATIVE_PATH env / com.blockether.ruff.native.path system property — an explicit path to the cdylib (used verbatim).
  2. A bundled classpath resource prebuilds/<platform>/<lib>, shipped by com.blockether/ruff-native-<platform> (extracted to the cache dir). This is the native-image path.
  3. A runtime download: the ruff-native-<platform> jar resolved through clojure.tools.deps (honouring Maven repos/mirrors/settings.xml), extracted + cached. Disable with RUFF_DISABLE_DOWNLOAD=1.

<platform> ∈ { linux-x64 linux-arm64 darwin-arm64 darwin-x64 windows-x64 }.

Clojure binding to ruff (https://github.com/astral-sh/ruff) for Python code
FORMATTING ONLY, through the JDK Foreign Function & Memory API.

ruff does not publish a C-ABI library — only a CLI. So this binds a tiny
first-party cdylib, `ruff-c` (native/ruff-c, a thin `extern "C"` wrapper over
ruff's `ruff_python_formatter` crate), exactly the way clj-fff binds `fff-c`.
Formatting runs IN-PROCESS via a downcall — no subprocess, no CLI, no config
discovery. `format` takes Python source and returns it reformatted (long
calls/collections wrapped multiline, black-compatible style).

Run the JVM with `--enable-native-access=ALL-UNNAMED` so the foreign linker
may load the library without a restricted-method warning.

The library is resolved ONCE, lazily, the first time it's needed:
  1. RUFF_NATIVE_PATH env / `com.blockether.ruff.native.path` system property
     — an explicit path to the cdylib (used verbatim).
  2. A bundled classpath resource `prebuilds/<platform>/<lib>`, shipped by
     `com.blockether/ruff-native-<platform>` (extracted to the cache dir).
     This is the native-image path.
  3. A runtime download: the `ruff-native-<platform>` jar resolved through
     `clojure.tools.deps` (honouring Maven repos/mirrors/settings.xml),
     extracted + cached. Disable with RUFF_DISABLE_DOWNLOAD=1.

`<platform>` ∈ { linux-x64 linux-arm64 darwin-arm64 darwin-x64 windows-x64 }.
raw docstring

available?clj

(available?)

True if the ruff native library can be resolved + linked on this platform.

True if the ruff native library can be resolved + linked on this platform.
sourceraw docstring

formatclj

(format code)
(format code {:keys [line-length]})

Format Python code and return the reformatted source as a String.

Options: :line-length int — wrap width (0 / omitted => ruff default 88).

Runs entirely in-process (no subprocess, no pyproject.toml / ruff.toml discovery): output depends only on code and :line-length. Throws ex-info when ruff can't format the input (syntactically invalid Python); callers that want a verbatim fallback should use format-or or catch.

Format Python `code` and return the reformatted source as a String.

Options:
  :line-length  int — wrap width (0 / omitted => ruff default 88).

Runs entirely in-process (no subprocess, no pyproject.toml / ruff.toml
discovery): output depends only on `code` and `:line-length`. Throws ex-info
when ruff can't format the input (syntactically invalid Python); callers that
want a verbatim fallback should use `format-or` or catch.
sourceraw docstring

format-orclj

(format-or code)
(format-or code opts)

Like format, but returns code unchanged if ruff is unavailable or fails (the convenient display-side default — never lose the original source).

Like `format`, but returns `code` unchanged if ruff is unavailable or fails
(the convenient display-side default — never lose the original source).
sourceraw docstring

versionclj

(version)

The bundled ruff release string (clj-ruff-cdylib (ruff X.Y.Z)).

The bundled ruff release string (`clj-ruff-cdylib (ruff X.Y.Z)`).
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close