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
chore: lint for no print (#2930)
Myles Scolnickd508e615da79
diff --git a/marimo/_cli/cli.py b/marimo/_cli/cli.pyindex ca7ab0e50a..d32e671b8e 100644--- a/marimo/_cli/cli.py+++ b/marimo/_cli/cli.py@@ -654,7 +654,7 @@ def recover(name: str) -> None:if not path.is_file():raise click.UsageError("Invalid NAME - %s is not a file" % name)- print(codegen.recover(name))+ click.echo(codegen.recover(name))@main.command(@@ -758,7 +758,7 @@ def env() -> None:marimo env"""- print(json.dumps(get_system_info(), indent=2))+ click.echo(json.dumps(get_system_info(), indent=2))main.command()(convert)diff --git a/marimo/_server/api/interrupt.py b/marimo/_server/api/interrupt.pyindex 6ca3ca3cb5..f044b0d6eb 100644--- a/marimo/_server/api/interrupt.py+++ b/marimo/_server/api/interrupt.py@@ -8,6 +8,7 @@ from typing import Callablefrom marimo._config.settings import GLOBAL_SETTINGSfrom marimo._server.utils import (TAB,+ print_,)@@ -66,7 +67,7 @@ class InterruptHandler:self.shutdown()returnexcept (KeyboardInterrupt, EOFError, asyncio.CancelledError):- print()+ print_()self.shutdown()returndiff --git a/marimo/_server/print.py b/marimo/_server/print.pyindex b3b037120c..92bc069327 100644--- a/marimo/_server/print.py+++ b/marimo/_server/print.py@@ -1,9 +1,11 @@# Copyright 2024 Marimo. All rights reserved.+from __future__ import annotations+import osimport sysfrom typing import Optional-from marimo._server.utils import print_tabbed+from marimo._server.utils import print_, print_tabbedUTF8_SUPPORTED = False@@ -17,7 +19,7 @@ except Exception:def print_startup(file_name: Optional[str], url: str, run: bool, new: bool) -> None:- print()+ print_()if file_name is not None and not run:print_tabbed(f"\033[1;32mEdit {os.path.basename(file_name)} "@@ -38,15 +40,15 @@ def print_startup("\033[1;32mCreate or edit notebooks in your ""browser\033[0m " + _utf8("📝"))- print()+ print_()print_tabbed(f"\033[32mURL\033[0m: \033[1m{url}\033[0m")- print()+ print_()def print_shutdown() -> None:- print()+ print_()print_tabbed("\033[32mThanks for using marimo!\033[0m %s" % _utf8("🌊🍃"))- print()+ print_()def _utf8(msg: str) -> str:diff --git a/marimo/_server/sessions.py b/marimo/_server/sessions.pyindex 2db0b80be3..c348388e1d 100644--- a/marimo/_server/sessions.py+++ b/marimo/_server/sessions.py@@ -64,7 +64,7 @@ from marimo._server.recents import RecentFilesManagerfrom marimo._server.session.session_view import SessionViewfrom marimo._server.tokens import AuthToken, SkewProtectionTokenfrom marimo._server.types import QueueType-from marimo._server.utils import print_tabbed+from marimo._server.utils import print_, print_tabbedfrom marimo._tracer import server_tracerfrom marimo._utils.disposable import Disposablefrom marimo._utils.distributor import (@@ -313,7 +313,7 @@ class KernelManager:self.queue_manager.control_queue.put(requests.StopRequest())# Hack: Wait for kernel to exit and write out profile;# joining the process hangs, but not sure why.- print(+ print_("\tWriting profile statistics to",self.profile_path," ...",@@ -490,9 +490,9 @@ class Session:if not self.kernel_manager.is_alive():LOGGER.debug("Closing session because kernel died")self.close()- print()+ print_()print_tabbed(red("The Python kernel died unexpectedly."))- print()+ print_()sys.exit()# Start a heartbeat task, which checks if the kernel is alivediff --git a/marimo/_server/utils.py b/marimo/_server/utils.pyindex 04788f5d1c..30a15a4ab6 100644--- a/marimo/_server/utils.py+++ b/marimo/_server/utils.py@@ -21,7 +21,7 @@ LOGGER = _loggers.marimo_logger()def print_tabbed(string: str, n_tabs: int = 1) -> None:- print(f"{TAB * n_tabs}{string}")+ print_(f"{TAB * n_tabs}{string}")def canonicalize_filename(filename: str) -> str:@@ -109,3 +109,12 @@ def asyncio_run(coro: Coroutine[Any, Any, T], **kwargs: dict[Any, Any]) -> T:"""initialize_asyncio()return asyncio.run(coro, **kwargs) # type: ignore[arg-type]+++def print_(*args: Any, **kwargs: Any) -> None:+ try:+ import click++ click.echo(*args, **kwargs)+ except NameError:+ print(*args, **kwargs) # noqa: T201diff --git a/pyodide/build_and_serve.py b/pyodide/build_and_serve.pyindex f8b4639459..54dc9403b7 100644--- a/pyodide/build_and_serve.py+++ b/pyodide/build_and_serve.py@@ -35,22 +35,22 @@ class WheelBuilderHandler(PatternMatchingEventHandler):patterns = ["*.py"] # Watch for changes in Python filesdef on_any_event(self, event) -> None:- print(f"Change detected: {event.src_path}")- print("Building wheel...")+ print(f"Change detected: {event.src_path}") # noqa: T201+ print("Building wheel...") # noqa: T201subprocess.run(["hatch", "build"])- print("Wheel built successfully.")+ print("Wheel built successfully.") # noqa: T201def serve() -> None:with socketserver.TCPServer(("", 8000), CORSHTTPRequestHandler) as httpd:httpd.allow_reuse_address = True- print("Serving at http://localhost:8000")+ print("Serving at http://localhost:8000") # noqa: T201try:httpd.serve_forever()except KeyboardInterrupt:passhttpd.server_close()- print("Server stopped.")+ print("Server stopped.") # noqa: T201cwd = os.getcwd()@@ -65,8 +65,8 @@ if __name__ == "__main__":observer.schedule(WheelBuilderHandler(), path=path, recursive=True)observer.start()- print("Watching for changes. Press Ctrl+C to stop.")- print(f"Watching directory: {path}")+ print("Watching for changes. Press Ctrl+C to stop.") # noqa: T201+ print(f"Watching directory: {path}") # noqa: T201try:while True:observer.join(1)diff --git a/pyproject.toml b/pyproject.tomlindex 7348c2704f..554a1e7d14 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -341,13 +341,14 @@ extend-select = ["B017", # Checks for pytest.raises context managers that catch Exception or BaseException."B019", # Use of functools.lru_cache or functools.cache on methods can lead to memory leaks"TRY002", # Prohibit use of `raise Exception`, use specific exceptions instead.+ "T201", # No print statements]# Never try to fix `F401` (unused imports).unfixable = ["F401"][tool.ruff.lint.per-file-ignores]-"**/{tests}/*" = ["ANN201", "ANN202"]+"**/{tests}/*" = ["ANN201", "ANN202", "T201"]"dagger/*" = ["TID252"][tool.ruff.lint.isort]diff --git a/tests/_plugins/ui/_impl/dataframes/test_print_code.py b/tests/_plugins/ui/_impl/dataframes/test_print_code.pyindex 45cc85c1ba..b697e6e4f6 100644--- a/tests/_plugins/ui/_impl/dataframes/test_print_code.py+++ b/tests/_plugins/ui/_impl/dataframes/test_print_code.py@@ -370,8 +370,6 @@ def test_print_code_result_matches_actual_transform_pandas(loc = {"pd": pd, "my_df": my_df.copy()}exec(pandas_code, {}, loc)code_result = loc.get("my_df_next")- print("---")- print(pandas_code)except Exception as code_error:code_result = code_error@@ -384,8 +382,6 @@ def test_print_code_result_matches_actual_transform_pandas(except Exception as real_error:real_result = real_error- print("code_result", code_result)- print("real_result", real_result)if isinstance(code_result, Exception) or isinstance(real_result, Exception):@@ -475,8 +471,6 @@ def test_print_code_result_matches_actual_transform_polars(polars_code = python_print_transforms("my_df", my_df.columns, transformations.transforms, python_print_polars)- print("---")- print(polars_code)assert polars_codetry: