Skip to content

Commit

Permalink
yield renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
manzt committed Mar 15, 2023
1 parent ae75f80 commit 5be170c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/higlass/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from higlass_schema import *

import higlass.tilesets
from higlass._display import renderers
from higlass.api import *
from higlass.fuse import fuse
from higlass.server import server
Expand Down
10 changes: 3 additions & 7 deletions src/higlass/_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,8 @@ def __call__(self, viewconf: dict, **metadata):
return {"text/html": html}


class PluginRegistry(Protocol):
active: str | None


@contextlib.contextmanager
def managed_enable(registry: PluginRegistry, reset: str | None):
def managed_enable(registry: RendererRegistry, reset: str | None):
"""Temporarily enables a renderer.
Parameters
Expand All @@ -158,13 +154,13 @@ def managed_enable(registry: PluginRegistry, reset: str | None):
The previous name of the active plugin.
"""
try:
yield registry
yield registry.get()
finally:
registry.active = reset


@dataclass
class RendererRegistry(PluginRegistry):
class RendererRegistry:
"""A registery for multiple HiGlass renderers.
Allows for multiple renders to be registered, and dynamically enabled/disabled
Expand Down
4 changes: 2 additions & 2 deletions test/test_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ def renderer(viewconf: dict, **metadata):

registry.enable("foo")

with registry.enable("mock"):
with registry.enable("mock") as render:
assert registry.active == "mock"
registry.get()({"hello": "world"})
render({"hello": "world"})

mock.assert_called_once_with({"hello": "world"})

Expand Down

0 comments on commit 5be170c

Please sign in to comment.