diff --git a/mjx/visualizer/svg.py b/mjx/visualizer/svg.py index 62ba70f0..9e03737d 100644 --- a/mjx/visualizer/svg.py +++ b/mjx/visualizer/svg.py @@ -3,7 +3,6 @@ from typing import List, Optional, Tuple, Union import svgwrite -from IPython.display import display_svg from svgwrite.drawing import Drawing import mjx.visualizer @@ -1031,6 +1030,8 @@ def show_svg( if "ipykernel" in sys.modules: # Jupyter Notebook + from IPython.display import display_svg + display_svg(dwg.tostring(), raw=True) else: sys.stdout.write("This function only works in Jupyter Notebook.") diff --git a/mjx/visualizer/visualizer.py b/mjx/visualizer/visualizer.py index 8996d66f..8b7b886b 100644 --- a/mjx/visualizer/visualizer.py +++ b/mjx/visualizer/visualizer.py @@ -6,10 +6,6 @@ from typing import List, Optional, Union from google.protobuf import json_format -from rich.console import Console -from rich.layout import Layout -from rich.panel import Panel -from rich.text import Text import mjxproto from mjx.action import Action @@ -562,6 +558,8 @@ def __init__(self, config: GameVisualConfig): self.config = config def get_layout(self): + from rich.layout import Layout + layout = Layout() if self.config.show_name: layout.split_column( @@ -955,6 +953,10 @@ def show_by_text(self, table: MahjongTable) -> str: return board_info + "".join(players_info) def show_by_rich(self, table: MahjongTable) -> None: + from rich.console import Console + from rich.panel import Panel + from rich.text import Text + layout = self.get_layout() layout["info"].update( diff --git a/requirements-dev.txt b/requirements-dev.txt index fef2395f..703e7d61 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -7,3 +7,6 @@ flake8 mypy mypy-protobuf types-protobuf +matplotlib +ipython +rich diff --git a/requirements.txt b/requirements.txt index bb9b3637..9ec3e0e0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,10 +1,7 @@ google==3.0.0 protobuf==3.17.3 grpcio==1.39.0 -rich==10.9.0 numpy pillow svgwrite inquirer -matplotlib -ipython diff --git a/setup.py b/setup.py index 1aebb6ad..32169543 100644 --- a/setup.py +++ b/setup.py @@ -155,12 +155,10 @@ def build_extension(self, ext): "google==3.0.0", "protobuf==3.17.3", "grpcio==1.39.0", - "rich==10.9.0", "numpy", "pillow", "svgwrite", "inquirer", - "ipython", ], extras_require={"test": ["pytest"]}, include_package_data=True, diff --git a/tests_py/test_visualizer.py b/tests_py/test_visualizer.py index 9a77013f..cfe4f07f 100644 --- a/tests_py/test_visualizer.py +++ b/tests_py/test_visualizer.py @@ -21,12 +21,12 @@ def test_visualizer(): if show: board_visualizer.print(mahjong_table) - board_visualizer = GameBoardVisualizer(GameVisualConfig(rich=True)) - for file in files: - proto_data_list = MahjongTable.load_proto_data(file) - for proto_data in proto_data_list: - mahjong_table = MahjongTable.from_proto(proto_data) - assert isinstance(mahjong_table, MahjongTable) - assert 4 == len(mahjong_table.players) - if show: - board_visualizer.print(mahjong_table) + # board_visualizer = GameBoardVisualizer(GameVisualConfig(rich=True)) + # for file in files: + # proto_data_list = MahjongTable.load_proto_data(file) + # for proto_data in proto_data_list: + # mahjong_table = MahjongTable.from_proto(proto_data) + # assert isinstance(mahjong_table, MahjongTable) + # assert 4 == len(mahjong_table.players) + # if show: + # board_visualizer.print(mahjong_table)