From bb875c5a2ba21764340e92144bdb8d0dcf4a6761 Mon Sep 17 00:00:00 2001 From: kushalkolar Date: Fri, 23 Feb 2024 18:36:15 -0500 Subject: [PATCH 1/5] displaying fpl logo and gpu info works on import in nb --- fastplotlib/__init__.py | 12 ++++++ fastplotlib/utils/__init__.py | 1 + fastplotlib/utils/_gpu_info.py | 68 ++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 fastplotlib/utils/_gpu_info.py diff --git a/fastplotlib/__init__.py b/fastplotlib/__init__.py index 301412aff..af61c0737 100644 --- a/fastplotlib/__init__.py +++ b/fastplotlib/__init__.py @@ -3,6 +3,8 @@ from .layouts import Plot, GridPlot from .graphics import * from .graphics.selectors import * +from .legends import * +from .utils import print_adapter_info from wgpu.gui.auto import run @@ -13,6 +15,16 @@ else: from .widgets import ImageWidget +from wgpu.backends.wgpu_native import enumerate_adapters + +adapters = [a.request_adapter_info() for a in enumerate_adapters()] + +if len(adapters) < 1: + raise IndexError( + "No WGPU adapters found, fastplotlib will not work." + ) + +print_adapter_info() with open(Path(__file__).parent.joinpath("VERSION"), "r") as f: __version__ = f.read().split("\n")[0] diff --git a/fastplotlib/utils/__init__.py b/fastplotlib/utils/__init__.py index c8f754883..83867c477 100644 --- a/fastplotlib/utils/__init__.py +++ b/fastplotlib/utils/__init__.py @@ -1 +1,2 @@ from .functions import * +from ._gpu_info import print_adapter_info \ No newline at end of file diff --git a/fastplotlib/utils/_gpu_info.py b/fastplotlib/utils/_gpu_info.py new file mode 100644 index 000000000..2fe4e96bf --- /dev/null +++ b/fastplotlib/utils/_gpu_info.py @@ -0,0 +1,68 @@ +from pathlib import Path + +from wgpu.backends.wgpu_native import enumerate_adapters +from wgpu.utils import get_default_device + +try: + from wgpu.gui.jupyter import JupyterWgpuCanvas +except ImportError: + JupyterWgpuCanvas = False + +try: + from IPython.display import display + from ipywidgets import Image +except NameError: + pass + + +def print_adapter_info(): + try: + ip = get_ipython() + if not (ip.has_trait("kernel") and JupyterWgpuCanvas is not False): + return + except NameError: + return + + logo_path = Path(__file__).parent.parent.joinpath("assets", "fastplotlib_face_logo.png") + + with open(logo_path, "rb") as f: + logo_data = f.read() + + image = Image( + value=logo_data, + format="png", + width=300, + height=55 + ) + + display(image) + + # print logo and adapter info + adapters = [a for a in enumerate_adapters()] + adapters_info = [a.request_adapter_info() for a in adapters] + + ix_default = adapters_info.index(get_default_device().adapter.request_adapter_info()) + + if len(adapters) > 0: + print("Available devices:") + + for ix, adapter in enumerate(adapters_info): + atype = adapter["adapter_type"] + backend = adapter["backend_type"] + driver = adapter["description"] + device = adapter["device"] + + if atype == "DiscreteGPU" and backend != "OpenGL": + charactor = chr(0x2705) + elif atype == "IntegratedGPU" and backend != "OpenGL": + charactor = chr(0x0001FBC4) + else: + charactor = chr(0x2757) + + if ix == ix_default: + default = " (default) " + else: + default = " " + + output_str = f"{charactor}{default}| {device} | {atype} | {backend} | {driver}" + print(output_str) \ No newline at end of file From 364871ee82ff8da199d4233119a73d1cb7d0e88c Mon Sep 17 00:00:00 2001 From: kushalkolar Date: Fri, 23 Feb 2024 18:37:22 -0500 Subject: [PATCH 2/5] add face logo for nb and add to MANIFEST --- MANIFEST.in | 2 ++ fastplotlib/assets/fastplotlib_face_logo.png | 3 +++ 2 files changed, 5 insertions(+) create mode 100644 fastplotlib/assets/fastplotlib_face_logo.png diff --git a/MANIFEST.in b/MANIFEST.in index 121ea2fd0..b8debd28d 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,2 +1,4 @@ recursive-include fastplotlib/utils/colormaps/ * include fastplotlib/VERSION +recursive-include fastplotlib/assets/ * + diff --git a/fastplotlib/assets/fastplotlib_face_logo.png b/fastplotlib/assets/fastplotlib_face_logo.png new file mode 100644 index 000000000..a5a8bd90e --- /dev/null +++ b/fastplotlib/assets/fastplotlib_face_logo.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:84976200545d143f559b6840a332f3121d58f8d7de8dad7cb8a6d027d854c153 +size 10239 From 8b05dac71658bd3ba8f4336f348ece9b6efca6fb Mon Sep 17 00:00:00 2001 From: kushalkolar Date: Tue, 27 Feb 2024 00:26:29 -0500 Subject: [PATCH 3/5] remove line that snuck in from other branch --- fastplotlib/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/fastplotlib/__init__.py b/fastplotlib/__init__.py index af61c0737..85c13cebe 100644 --- a/fastplotlib/__init__.py +++ b/fastplotlib/__init__.py @@ -3,7 +3,6 @@ from .layouts import Plot, GridPlot from .graphics import * from .graphics.selectors import * -from .legends import * from .utils import print_adapter_info from wgpu.gui.auto import run From 4cd4d04590f56415a768ec498d675f9164b1a203 Mon Sep 17 00:00:00 2001 From: kushalkolar Date: Tue, 27 Feb 2024 00:30:14 -0500 Subject: [PATCH 4/5] git lfs to pypi build action --- .github/workflows/pypi-publish.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/pypi-publish.yml b/.github/workflows/pypi-publish.yml index 207d92351..9ebe52b87 100644 --- a/.github/workflows/pypi-publish.yml +++ b/.github/workflows/pypi-publish.yml @@ -21,7 +21,14 @@ jobs: runs-on: ubuntu-latest steps: + - name: Install git-lfs + run: | + sudo apt install --no-install-recommends -y git-lfs - uses: actions/checkout@v3 + - name: fetch git lfs files + run: | + git lfs fetch --all + git lfs pull - name: Set up Python uses: actions/setup-python@v3 with: From fdfdcb50b89874ff0195b0982a6fe5684f68802b Mon Sep 17 00:00:00 2001 From: kushalkolar Date: Tue, 27 Feb 2024 01:07:53 -0500 Subject: [PATCH 5/5] fix import and add easter egg --- fastplotlib/__init__.py | 4 +-- fastplotlib/assets/egg.gif | 3 +++ .../layouts/_frame/_ipywidget_toolbar.py | 16 ++++++++++++ fastplotlib/utils/__init__.py | 15 ++++++++++- fastplotlib/utils/_gpu_info.py | 26 +++++++++---------- 5 files changed, 47 insertions(+), 17 deletions(-) create mode 100644 fastplotlib/assets/egg.gif diff --git a/fastplotlib/__init__.py b/fastplotlib/__init__.py index 85c13cebe..b3434012f 100644 --- a/fastplotlib/__init__.py +++ b/fastplotlib/__init__.py @@ -3,7 +3,7 @@ from .layouts import Plot, GridPlot from .graphics import * from .graphics.selectors import * -from .utils import print_adapter_info +from .utils import _notebook_print_banner, config from wgpu.gui.auto import run @@ -23,7 +23,7 @@ "No WGPU adapters found, fastplotlib will not work." ) -print_adapter_info() +_notebook_print_banner() with open(Path(__file__).parent.joinpath("VERSION"), "r") as f: __version__ = f.read().split("\n")[0] diff --git a/fastplotlib/assets/egg.gif b/fastplotlib/assets/egg.gif new file mode 100644 index 000000000..0ff189075 --- /dev/null +++ b/fastplotlib/assets/egg.gif @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7251090fd17fa81eae8a5ad176608755b4a68d620b125ebd571acc6d68daa017 +size 4589 diff --git a/fastplotlib/layouts/_frame/_ipywidget_toolbar.py b/fastplotlib/layouts/_frame/_ipywidget_toolbar.py index f27856e61..552ee9827 100644 --- a/fastplotlib/layouts/_frame/_ipywidget_toolbar.py +++ b/fastplotlib/layouts/_frame/_ipywidget_toolbar.py @@ -3,6 +3,7 @@ from itertools import product from math import copysign from functools import partial +from pathlib import Path from typing import * @@ -17,10 +18,12 @@ BoundedIntText, Play, jslink, + Image, ) from ...graphics.selectors import PolygonSelector from ._toolbar import ToolBar +from ...utils import config class IpywidgetToolBar(HBox, ToolBar): @@ -92,6 +95,19 @@ def __init__(self, plot): self._record_button, ] + if config.party_parrot: + gif_path = Path(__file__).parent.parent.parent.joinpath("assets", "egg.gif") + with open(gif_path, "rb") as f: + gif = f.read() + + image = Image( + value=gif, + format="png", + width=35, + height=25, + ) + widgets.append(image) + if hasattr(self.plot, "_subplots"): positions = list(product(range(self.plot.shape[0]), range(self.plot.shape[1]))) values = list() diff --git a/fastplotlib/utils/__init__.py b/fastplotlib/utils/__init__.py index 83867c477..addea140d 100644 --- a/fastplotlib/utils/__init__.py +++ b/fastplotlib/utils/__init__.py @@ -1,2 +1,15 @@ +from dataclasses import dataclass + + from .functions import * -from ._gpu_info import print_adapter_info \ No newline at end of file +from ._gpu_info import _notebook_print_banner + + +@dataclass +class _Config: + party_parrot: bool + + +config = _Config( + party_parrot=False +) diff --git a/fastplotlib/utils/_gpu_info.py b/fastplotlib/utils/_gpu_info.py index 2fe4e96bf..9387f3ece 100644 --- a/fastplotlib/utils/_gpu_info.py +++ b/fastplotlib/utils/_gpu_info.py @@ -4,23 +4,21 @@ from wgpu.utils import get_default_device try: + ip = get_ipython() + from ipywidgets import Image from wgpu.gui.jupyter import JupyterWgpuCanvas -except ImportError: - JupyterWgpuCanvas = False - -try: +except (NameError, ModuleNotFoundError, ImportError): + NOTEBOOK = False +else: from IPython.display import display - from ipywidgets import Image -except NameError: - pass + if ip.has_trait("kernel") and (JupyterWgpuCanvas is not False): + NOTEBOOK = True + else: + NOTEBOOK = False -def print_adapter_info(): - try: - ip = get_ipython() - if not (ip.has_trait("kernel") and JupyterWgpuCanvas is not False): - return - except NameError: +def _notebook_print_banner(): + if NOTEBOOK is False: return logo_path = Path(__file__).parent.parent.joinpath("assets", "fastplotlib_face_logo.png") @@ -65,4 +63,4 @@ def print_adapter_info(): default = " " output_str = f"{charactor}{default}| {device} | {atype} | {backend} | {driver}" - print(output_str) \ No newline at end of file + print(output_str)