Skip to content
This repository was archived by the owner on Feb 28, 2024. It is now read-only.

Commit 1bf5bfc

Browse files
authored
feat: Migrate to anywidget (#3)
1 parent 3ab6003 commit 1bf5bfc

File tree

19 files changed

+177
-18001
lines changed

19 files changed

+177
-18001
lines changed

.github/workflows/ci.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
Lint:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v3
15+
16+
- name: Setup Python
17+
uses: actions/setup-python@v4
18+
with:
19+
python-version: "3.x"
20+
21+
- name: Install dependencies
22+
run: |
23+
python -m pip install --upgrade pip
24+
pip install -e .[dev]
25+
26+
- name: Check formatting with Black
27+
run: black --check .
28+
29+
- name: Check linting with Ruff
30+
run: ruff .
31+
32+
Build:
33+
runs-on: ubuntu-latest
34+
steps:
35+
- name: Checkout
36+
uses: actions/checkout@v3
37+
38+
- name: Setup Python
39+
uses: actions/setup-python@v4
40+
with:
41+
python-version: "3.x"
42+
43+
- name: Install dependencies
44+
run: |
45+
python -m pip install --upgrade pip
46+
pip install build
47+
48+
- name: Build
49+
run: python -m build .

.github/workflows/publish.yml

Lines changed: 0 additions & 52 deletions
This file was deleted.

.github/workflows/release.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Release
2+
3+
permissions:
4+
contents: write
5+
6+
on:
7+
push:
8+
tags:
9+
- "v*" # Push events to matching v*, i.e. v1.0, v20.15.10
10+
11+
jobs:
12+
Release:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v3
16+
with:
17+
fetch-depth: 0
18+
19+
- uses: actions/setup-python@v4
20+
with:
21+
python-version: "3.x"
22+
23+
- name: Install dependencies
24+
run: |
25+
python -m pip install --upgrade pip
26+
pip install build
27+
28+
- name: Build
29+
run: python -m build .
30+
31+
- name: Publish distribution 📦 to PyPI
32+
uses: pypa/gh-action-pypi-publish@release/v1
33+
with:
34+
password: ${{ secrets.TWINE_API_KEY }}
35+
36+
- run: npx changelogithub@0.12
37+
env:
38+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

MANIFEST.in

Lines changed: 0 additions & 12 deletions
This file was deleted.

higlass-widget.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

higlass_widget/__init__.py

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,8 @@
1-
import sys
2-
3-
from ._version import __version__
4-
from .widget import HiGlassWidget
1+
import importlib.metadata
52

63
try:
7-
if "google.colab" in sys.modules:
8-
from google.colab import output
9-
10-
output.enable_custom_widget_manager()
11-
except ImportError:
12-
pass
13-
14-
15-
def _jupyter_labextension_paths():
16-
return [{"src": "labextension", "dest": "higlass-widget"}]
17-
4+
__version__ = importlib.metadata.version("higlass-widget")
5+
except importlib.metadata.PackageNotFoundError:
6+
__version__ = "unknown"
187

19-
def _jupyter_nbextension_paths():
20-
return [
21-
{
22-
"section": "notebook",
23-
"src": "nbextension",
24-
"dest": "higlass-widget",
25-
"require": "higlass-widget/extension",
26-
}
27-
]
8+
from .widget import HiGlassWidget # noqa

higlass_widget/_version.py

Lines changed: 0 additions & 10 deletions
This file was deleted.

higlass_widget/nbextension/extension.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

higlass_widget/widget.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import hglib from "https://esm.sh/higlass@1.12?deps=react@17,react-dom@17,pixi.js@6"
2+
3+
/**
4+
* @param {{
5+
* xDomain: [number, number],
6+
* yDomain: [number, number],
7+
* }} location
8+
*/
9+
function toPts({ xDomain, yDomain }) {
10+
let [x, xe] = xDomain;
11+
let [y, ye] = yDomain;
12+
return [x, xe, y, ye];
13+
}
14+
15+
export async function render(view) {
16+
let viewconf = JSON.parse(view.model.get("_viewconf"));
17+
let api = await hglib.viewer(view.el, viewconf);
18+
19+
view.model.on("msg:custom", (msg) => {
20+
msg = JSON.parse(msg);
21+
let [fn, ...args] = msg;
22+
api[fn](...args);
23+
});
24+
25+
if (viewconf.views.length === 1) {
26+
api.on("location", (loc) => {
27+
view.model.set("location", toPts(loc));
28+
view.model.save_changes();
29+
}, viewconf.views[0].uid);
30+
} else {
31+
viewconf.views.forEach((view, idx) => {
32+
api.on("location", (loc) => {
33+
let copy = view.model.get("location").slice();
34+
copy[idx] = toPts(loc);
35+
view.model.set("location", copy);
36+
view.model.save_changes();
37+
}, view.uid);
38+
});
39+
}
40+
}

higlass_widget/widget.py

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,20 @@
1+
from __future__ import annotations
12
import json
2-
from typing import Any, Dict
3+
import pathlib
34

4-
import ipywidgets
5-
import traitlets.traitlets as t
5+
import anywidget
6+
import traitlets as t
67

7-
from ._version import __version__
8-
9-
10-
class HiGlassWidget(ipywidgets.DOMWidget):
11-
_model_name = t.Unicode("HiGlassModel").tag(sync=True)
12-
_model_module = t.Unicode("higlass-widget").tag(sync=True)
13-
_model_module_version = t.Unicode(__version__).tag(sync=True)
14-
15-
_view_name = t.Unicode("HiGlassView").tag(sync=True)
16-
_view_module = t.Unicode("higlass-widget").tag(sync=True)
17-
_view_module_version = t.Unicode(__version__).tag(sync=True)
188

9+
class HiGlassWidget(anywidget.AnyWidget):
10+
_esm = pathlib.Path(__file__).parent / "widget.js"
11+
_css = "https://esm.sh/higlass@1.12/dist/hglib.css"
1912
_viewconf = t.Unicode("null").tag(sync=True)
2013

2114
# readonly properties
2215
location = t.List(t.Union([t.Float(), t.Tuple()]), read_only=True).tag(sync=True)
2316

24-
def __init__(self, viewconf: Dict[str, Any], **kwargs):
17+
def __init__(self, viewconf: dict, **kwargs):
2518
super().__init__(_viewconf=json.dumps(viewconf), **kwargs)
2619

2720
def reload(self, *items):
@@ -33,8 +26,8 @@ def zoom_to(
3326
view_id: str,
3427
start1: int,
3528
end1: int,
36-
start2: int = None,
37-
end2: int = None,
29+
start2: int | None = None,
30+
end2: int | None = None,
3831
animate_time: int = 500,
3932
):
4033
msg = json.dumps(["zoomTo", view_id, start1, end1, start2, end2, animate_time])

0 commit comments

Comments
 (0)