Skip to content

Commit bfa682f

Browse files
authored
chore: remove importing directly from marimo (#6780)
This reduces the dependency graph that `pytest-changed` picks up
1 parent 008599b commit bfa682f

File tree

4 files changed

+24
-20
lines changed

4 files changed

+24
-20
lines changed

marimo/_output/formatters/sympy_formatters.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,37 @@
88

99

1010
def patch_sympy(*objs: Any) -> None:
11-
import marimo as mo
12-
13-
"""adds the _mime_() method to sympy objects
11+
"""Adds the _mime_() method to sympy objects
1412
e.g.
1513
Symbol._mime_ = sympy_html
1614
example:
1715
patch_sympy(Symbol, Integral)
1816
"""
1917
from sympy import latex # type: ignore
2018

19+
from marimo._output.md import md
20+
2121
for obj in objs:
2222
# the lambda below is our sympy_html
2323
obj._mime_ = lambda obj: (
2424
"text/html",
25-
mo.md(f"""\\[{latex(obj)}\\]""").text,
25+
md(f"""\\[{latex(obj)}\\]""").text,
2626
)
2727

2828

2929
def sympy_as_html(obj: Any) -> tuple[KnownMimeType, str]:
30-
from sympy import latex
31-
32-
import marimo as mo
33-
34-
"""creates HTML output from a Printable Sympy object
30+
"""Creates HTML output from a Printable Sympy object
3531
e.g.
36-
example:
32+
33+
Example:
3734
integral = Integral(x**2, x)
3835
sympy_as_html(integral)
3936
"""
40-
return ("text/html", mo.md(f"""\\[{latex(obj)}\\]""").text)
37+
from sympy import latex
38+
39+
from marimo._output.md import md
40+
41+
return ("text/html", md(f"""\\[{latex(obj)}\\]""").text)
4142

4243

4344
class SympyFormatter(FormatterFactory):

marimo/_runtime/marimo_browser.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ def browser_open_fallback(
1717
"""
1818
import inspect
1919

20-
import marimo as mo
20+
import marimo._runtime.output._output as output
21+
from marimo._output.hypertext import Html
22+
from marimo._plugins.stateless.image import image
2123

2224
del new, autoraise # unused
2325

@@ -44,8 +46,8 @@ def browser_open_fallback(
4446
stack[2].filename.endswith("antigravity.py")
4547
or (stack[1].filename.endswith("antigravity.py"))
4648
):
47-
mo.output.append(
48-
mo.image(
49+
output.append(
50+
image(
4951
"https://marimo.app/images/antigravity.png",
5052
alt=(
5153
"The image shows 2 stick figures in XKCD style. The one "
@@ -67,8 +69,8 @@ def browser_open_fallback(
6769
)
6870
)
6971
else:
70-
mo.output.append(
71-
mo.Html(
72+
output.append(
73+
Html(
7274
f"<iframe src='{url}' style='width:100%;height:500px'></iframe>",
7375
)
7476
)

marimo/_runtime/pytest.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
from dataclasses import dataclass
88
from typing import TYPE_CHECKING, Any, Callable, Optional
99

10-
import marimo
10+
from marimo._ast.cell import Cell
1111
from marimo._ast.pytest import MARIMO_TEST_STUB_NAME
1212
from marimo._cli.print import bold, green
1313
from marimo._dependencies.dependencies import DependencyManager
1414
from marimo._runtime.capture import capture_stdout
1515
from marimo._runtime.context import safe_get_context
16+
from marimo._runtime.runtime import notebook_location
1617

1718
MARIMO_TEST_BLOCK_REGEX = re.compile(rf"{MARIMO_TEST_STUB_NAME}_\d+[(?::)\.]+")
1819

@@ -60,7 +61,7 @@ def _to_marimo_uri(uri: str) -> str:
6061
return uri
6162
cell_id = uri.split("_")[6]
6263

63-
notebook = os.path.relpath(_get_name(), marimo.notebook_location())
64+
notebook = os.path.relpath(_get_name(), notebook_location())
6465
return f"marimo://{notebook}#cell_id={cell_id}"
6566

6667

@@ -69,7 +70,7 @@ def _sub_function(
6970
) -> _pytest.Item:
7071
# Directly execute the cell, since this means it's a toplevel function with no deps.
7172
# Or a cell where which we already wrapped in skip.
72-
if isinstance(old_item.obj, marimo._ast.cell.Cell):
73+
if isinstance(old_item.obj, Cell):
7374
return old_item
7475

7576
import pytest # type: ignore

tests/_cli/test_file_path.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import click
1010
import pytest
1111

12-
from docs.blocks import uri_encode_component
1312
from marimo._cli.file_path import (
1413
FileContentReader,
1514
GenericURLReader,
@@ -23,6 +22,7 @@
2322
is_github_src,
2423
validate_name,
2524
)
25+
from marimo._output.utils import uri_encode_component
2626
from marimo._utils.requests import Response
2727
from tests.mocks import EDGE_CASE_FILENAMES
2828

0 commit comments

Comments
 (0)