Skip to content

Commit

Permalink
Refactor dependencies (#1104)
Browse files Browse the repository at this point in the history
* refactor dependencies

* lazy import

* Apply formatter

* lazy import rich

* remove rich test

Co-authored-by: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
sotetsuk and github-actions[bot] authored Aug 21, 2022
1 parent 4c7b231 commit 0b4310b
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 19 deletions.
3 changes: 2 additions & 1 deletion mjx/visualizer/svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.")
10 changes: 6 additions & 4 deletions mjx/visualizer/visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
3 changes: 3 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ flake8
mypy
mypy-protobuf
types-protobuf
matplotlib
ipython
rich
3 changes: 0 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
2 changes: 0 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 9 additions & 9 deletions tests_py/test_visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 0b4310b

Please sign in to comment.