Skip to content

Commit

Permalink
Significantly reduce import overhead (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
brentyi authored Jan 14, 2024
1 parent 8553022 commit ef57659
Show file tree
Hide file tree
Showing 11 changed files with 4,375 additions and 4,311 deletions.
1 change: 1 addition & 0 deletions docs/source/icons.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ specified using the :class:`viser.Icon` enum.

<!-- prettier-ignore-start -->

.. autoclass:: viser.IconName
.. autoclass:: viser.Icon

<!-- prettier-ignore-end -->
1 change: 1 addition & 0 deletions src/viser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from ._gui_handles import GuiTabGroupHandle as GuiTabGroupHandle
from ._gui_handles import GuiTabHandle as GuiTabHandle
from ._icons_enum import Icon as Icon
from ._icons_enum import IconName as IconName
from ._scene_handles import CameraFrustumHandle as CameraFrustumHandle
from ._scene_handles import FrameHandle as FrameHandle
from ._scene_handles import GlbHandle as GlbHandle
Expand Down
3 changes: 2 additions & 1 deletion src/viser/_client_autobuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import sys
from pathlib import Path

import psutil
import rich

client_dir = Path(__file__).absolute().parent / "client"
Expand All @@ -11,6 +10,8 @@

def _check_viser_yarn_running() -> bool:
"""Returns True if the viewer client has been launched via `yarn start`."""
import psutil

for process in psutil.process_iter():
try:
if Path(process.cwd()).as_posix().endswith("viser/client") and any(
Expand Down
4 changes: 2 additions & 2 deletions src/viser/_gui_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
_make_unique_id,
)
from ._icons import base64_from_icon
from ._icons_enum import Icon
from ._icons_enum import IconName
from ._message_api import MessageApi, cast_vector

if TYPE_CHECKING:
Expand Down Expand Up @@ -333,7 +333,7 @@ def add_gui_button(
"teal",
]
] = None,
icon: Optional[Icon] = None,
icon: Optional[IconName] = None,
order: Optional[float] = None,
) -> GuiButtonHandle:
"""Add a button to the GUI. The value of this input is set to `True` every time
Expand Down
4 changes: 2 additions & 2 deletions src/viser/_gui_handles.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from typing_extensions import Protocol

from ._icons import base64_from_icon
from ._icons_enum import Icon
from ._icons_enum import IconName
from ._message_api import _encode_image_base64
from ._messages import (
GuiAddDropdownMessage,
Expand Down Expand Up @@ -343,7 +343,7 @@ def order(self) -> float:
"""Read-only order value, which dictates the position of the GUI element."""
return self._order

def add_tab(self, label: str, icon: Optional[Icon] = None) -> GuiTabHandle:
def add_tab(self, label: str, icon: Optional[IconName] = None) -> GuiTabHandle:
"""Add a tab. Returns a handle we can use to add GUI elements to it."""

id = _make_unique_id()
Expand Down
5 changes: 2 additions & 3 deletions src/viser/_icons.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
import tarfile
from pathlib import Path

from ._icons_enum import Icon
from ._icons_enum import IconName

ICONS_DIR = Path(__file__).absolute().parent / "_icons"


def base64_from_icon(icon: Icon) -> str:
def base64_from_icon(icon_name: IconName) -> str:
"""Read an icon and encode it via base64."""
icon_name = icon.value
assert isinstance(icon_name, str)
icons_tarball = ICONS_DIR / "tabler-icons.tar"

Expand Down
Loading

0 comments on commit ef57659

Please sign in to comment.