A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
feat: prioritize ruff over black in formatter, requirements, and documentation (#1765)
Miraia C33fc8be79088
diff --git a/README.md b/README.mdindex 311f53c410..0683c4d655 100644--- a/README.md+++ b/README.md@@ -70,7 +70,7 @@ statically analyzing your code.prevent them from automatically running, or configure the runtime to belazy and mark affected stales as stale instead of automatically running them.-**Batteries-included.** marimo comes with GitHub Copilot, Black code+**Batteries-included.** marimo comes with GitHub Copilot, Ruff codeformatting, HTML export, fast code completion, a [VS Codeextension](https://marketplace.visualstudio.com/items?itemName=marimo-team.vscode-marimo),and many more quality-of-life features.diff --git a/frontend/public/files/wasm-intro.py b/frontend/public/files/wasm-intro.pyindex 10f46022db..34490b347c 100644--- a/frontend/public/files/wasm-intro.py+++ b/frontend/public/files/wasm-intro.py@@ -463,8 +463,8 @@ def __():),"Code Formatting": ("""- If you have [black](https://github.com/psf/black) installed, you can format a cell with- the keyboard shortcut `Ctrl/Cmd+b`.+ If you have [ruff](https://github.com/astral-sh/ruff) installed,+ you can format a cell with the keyboard shortcut `Ctrl/Cmd+b`."""),"Command Palette": (diff --git a/marimo/_tutorials/fileformat.py b/marimo/_tutorials/fileformat.pyindex b925cd3ca0..7fabc93524 100644--- a/marimo/_tutorials/fileformat.py+++ b/marimo/_tutorials/fileformat.py@@ -195,7 +195,7 @@ def __():the generated code. For example, whitespace, line breaks, and so on areall preserved exactly. This means that you can touch up formatting inyour text editor, either manually or using automated formatters like- Black, and be confident that your changes will be preserved.+ Ruff, and be confident that your changes will be preserved.""","Cell functions can have names": """If you want to, you can replace the default names for cell functionsdiff --git a/marimo/_tutorials/intro.py b/marimo/_tutorials/intro.pyindex e08909ff5b..cab92ada54 100644--- a/marimo/_tutorials/intro.py+++ b/marimo/_tutorials/intro.py@@ -436,8 +436,8 @@ def __():),"Code Formatting": ("""- If you have [black](https://github.com/psf/black) installed, you can format a cell with- the keyboard shortcut `Ctrl/Cmd+b`.+ If you have [ruff](https://github.com/astral-sh/ruff) installed,+ you can format a cell with the keyboard shortcut `Ctrl/Cmd+b`."""),"Command Palette": (diff --git a/marimo/_utils/formatter.py b/marimo/_utils/formatter.pyindex 39e9a536b7..fa2d21d30a 100644--- a/marimo/_utils/formatter.py+++ b/marimo/_utils/formatter.py@@ -22,24 +22,32 @@ class Formatter:class DefaultFormatter(Formatter):"""- Tries black, then ruff, then no formatting.+ Tries ruff, then black, then no formatting."""def format(self, codes: CellCodes) -> CellCodes:- if DependencyManager.has("black"):- return BlackFormatter(self.line_length).format(codes)- elif DependencyManager.has("ruff"):+ if DependencyManager.has("ruff"):return RuffFormatter(self.line_length).format(codes)+ elif DependencyManager.has("black"):+ return BlackFormatter(self.line_length).format(codes)else:LOGGER.warning(- "To enable code formatting, install black (pip install black) "- "or ruff (pip install ruff)"+ "To enable code formatting, install ruff (pip install ruff) "+ "or black (pip install black)")return {}class RuffFormatter(Formatter):def format(self, codes: CellCodes) -> CellCodes:+ try:+ process = subprocess.run("ruff", capture_output=True)+ except FileNotFoundError:+ LOGGER.warning(+ "To enable code formatting, install ruff (pip install ruff)"+ )+ return {}+formatted_codes: CellCodes = {}for key, code in codes.items():try:@@ -74,7 +82,8 @@ class BlackFormatter(Formatter):import blackexcept ModuleNotFoundError:LOGGER.warning(- "To enable code formatting, install black (pip install black)"+ "To enable code formatting, install ruff (pip install ruff) "+ "or black (pip install black)")return {}diff --git a/marimo/_utils/health.py b/marimo/_utils/health.pyindex 40b3a7f227..ab0f962b42 100644--- a/marimo/_utils/health.py+++ b/marimo/_utils/health.py@@ -36,7 +36,7 @@ def get_required_modules_list() -> dict[str, str]:"starlette","websockets","typing-extensions",- "black",+ "ruff",]package_versions: dict[str, str] = {}diff --git a/pyproject.toml b/pyproject.tomlindex cf6532f179..ce87958ccd 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -45,7 +45,7 @@ dependencies = ["itsdangerous>=2.0.0",# for cell formatting; if user version is not compatible, no-op# so no lower bound needed- "black",+ "ruff",]readme = "README.md"license = { file = "LICENSE" }