Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: temporarily enable a renderer #113

Merged
merged 11 commits into from
Apr 20, 2023
Merged

feat: temporarily enable a renderer #113

merged 11 commits into from
Apr 20, 2023

Conversation

manzt
Copy link
Member

@manzt manzt commented Mar 15, 2023

Description

What was changed in this pull request?

Adds a context manager to higlass._display.RendererRegistry, which allows for temporarily enabling a renderer with a context manager.

with hg.renderers.enable("custom") as custom_render:
    custom_render(...)

assert hg.renderers.active == "default"

I think this will be useful for creating a separate (Jupyter-less) renderer for higlass-python, allowing for opening through a script (addressing #95):

For example, a simple script example:

import higlass as hg


def open_browser(conf)
    with hg.renderers.enable("html") as render:
        html = render(conf.dict())
    encoded = urllib.parse.quote(html)
    # there is a limit on data URL sizes, so might need to integrate
    # with hg server here to dynamically create and HTML endpoint
    webbrowser.open("data:text/html," + encoded)


if __name__ == "__main__":
    ts = hg.cooler("../data/dataset.mcool")
    track = ts.track("heatmap")
    view = hg.view(track)
    open_browser(view.viewconf())
    input("Press any key to exit.")

Why is it necessary?

Fixes #___

Checklist

  • Unit tests added or updated
  • Ran black on the root directory

@manzt manzt force-pushed the tmp-enable-renderer branch 2 times, most recently from b41a285 to 5be170c Compare March 15, 2023 14:21
@manzt manzt requested a review from nvictus March 15, 2023 17:22
@manzt
Copy link
Member Author

manzt commented Mar 15, 2023

please ignore the linting stuff. There seems to be some issue with how higlass is detected in CI vs on my local machine for ruff's (isort) import sorting for things outside of src/.

Locally, for test_test*.py ruff wants :

import pytest # third party

import higlass as hg # local

whereas in CI it wants:

import higlass as hg 
import pytest

which makes me think for some reason higlass is being detected as a third-party module outside of src in CI. The current config just turns off this rule when looking outside of src (but in CI only). This way we still enforce import sorting locally (and it will be automatically fixed with ruff --fix .), but we just don't make it a criteria for passing CI.

@manzt manzt merged commit 3bc97e0 into main Apr 20, 2023
@manzt manzt deleted the tmp-enable-renderer branch April 20, 2023 02:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant