Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v5
- uses: astral-sh/setup-uv@v7
Expand Down
56 changes: 24 additions & 32 deletions examples/Plugin.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "74b20970",
"id": "ea68ab39",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -13,7 +13,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "4b1a1665",
"id": "22ce47f6",
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -62,7 +62,7 @@
},
{
"cell_type": "markdown",
"id": "06263c4c",
"id": "019c7c7e",
"metadata": {},
"source": [
"The above config contains an unknown track type to `hg`, so we get a validation error because we don't know how to render the track!"
Expand All @@ -71,7 +71,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "8c4a4b38",
"id": "8f5f4294",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -82,7 +82,7 @@
},
{
"cell_type": "markdown",
"id": "d20a1b24",
"id": "5cc74c65",
"metadata": {},
"source": [
"# `hg.PluginTrack`\n",
Expand All @@ -93,13 +93,11 @@
{
"cell_type": "code",
"execution_count": null,
"id": "4d6149f1",
"id": "26813410",
"metadata": {},
"outputs": [],
"source": [
"from typing import ClassVar, Union\n",
"\n",
"from typing_extensions import Literal\n",
"from typing import ClassVar, Literal\n",
"\n",
"\n",
"class PileupTrack(hg.PluginTrack):\n",
Expand All @@ -109,17 +107,17 @@
" )\n",
"\n",
"\n",
"hg.Viewconf[Union[PileupTrack, hg.Track]](**config) # works!"
"hg.Viewconf[PileupTrack | hg.Track](**config) # works!"
]
},
{
"cell_type": "markdown",
"id": "66e046ce",
"id": "ec287f3e",
"metadata": {},
"source": [
"How does this work? The `hg.Viewconf` is a `pydantic.GenericModel` which is _generic_ over the track type. By default, only HiGlass's builtin track types are recognized, so `hg.Viewconf(**data)` will throw an error when a configuration contains an unknown track.\n",
"\n",
"By supplying a our plugin track as a type parameter explicity, `hg.Viewconf[Union[PileupTrack, hg.Track]]`, we extend the model to recognize the `PileupTrack` in our config.\n",
"By supplying a our plugin track as a type parameter explicity, `hg.Viewconf[PileupTrack | hg.Track]`, we extend the model to recognize the `PileupTrack` in our config.\n",
"\n",
"This can seem a bit verbose, but supplying the type parameter explicitly is only necessary when deserializing an unknown config, e.g.\n",
"\n",
Expand All @@ -134,21 +132,19 @@
{
"cell_type": "code",
"execution_count": null,
"id": "4fde003f",
"id": "736146c8",
"metadata": {},
"outputs": [],
"source": [
"from typing import ClassVar\n",
"\n",
"from typing_extensions import Literal\n",
"from typing import ClassVar, Literal\n",
"\n",
"import higlass as hg"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1210c425",
"id": "c178a248",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -166,13 +162,11 @@
{
"cell_type": "code",
"execution_count": null,
"id": "76a67f86",
"id": "d86e35fc",
"metadata": {},
"outputs": [],
"source": [
"from typing import ClassVar\n",
"\n",
"from typing_extensions import Literal\n",
"from typing import ClassVar, Literal\n",
"\n",
"import higlass as hg\n",
"\n",
Expand Down Expand Up @@ -218,7 +212,7 @@
},
{
"cell_type": "markdown",
"id": "bb20c39e",
"id": "0a28bebf",
"metadata": {},
"source": [
"## Extending plugins with `pydantic`\n",
Expand All @@ -231,12 +225,10 @@
{
"cell_type": "code",
"execution_count": null,
"id": "35355968",
"id": "6e397bed",
"metadata": {},
"outputs": [],
"source": [
"from typing import Optional\n",
"\n",
"from pydantic import BaseModel\n",
"\n",
"\n",
Expand All @@ -252,7 +244,7 @@
"\n",
"class SequenceTrack(hg.PluginTrack):\n",
" type: Literal[\"horizontal-sequence\"]\n",
" data: Optional[SeqeuenceTrackData] = None\n",
" data: SeqeuenceTrackData | None = None\n",
" plugin_url: ClassVar[str] = (\n",
" \"https://unpkg.com/higlass-sequence/dist/higlass-sequence.js\"\n",
" )\n",
Expand All @@ -279,7 +271,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "1328f1d6",
"id": "98794dcf",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -289,7 +281,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "27f99ea4",
"id": "9776449b",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -298,7 +290,7 @@
},
{
"cell_type": "markdown",
"id": "35965609",
"id": "93fb6b03",
"metadata": {},
"source": [
"And the track is faithfully rendered by HiGlass"
Expand All @@ -307,7 +299,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "7948b163",
"id": "aa4d7519",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -317,7 +309,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "ad082d7f",
"id": "62543d11",
"metadata": {},
"outputs": [],
"source": []
Expand All @@ -344,4 +336,4 @@
},
"nbformat": 4,
"nbformat_minor": 5
}
}
12 changes: 3 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,19 @@ classifiers = [
"Intended Audience :: Developers",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Operating System :: OS Independent",
]
license = { text = "MIT" }
dynamic = ["version"]
readme = "README.md"
dependencies = [
"higlass-schema>=0.2.0",
"anywidget>=0.9.0",
"typing-extensions ; python_version<'3.9'",
]
requires-python = ">=3.8"
requires-python = ">=3.10"
urls = { homepage = "https://github.com/higlass/higlass-python" }

[dependency-groups]
Expand All @@ -50,10 +48,6 @@ packages = ["src/higlass"]
[tool.hatch.version]
source = "vcs"

[tool.ruff]
line-length = 88
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the default in Ruff already

target-version = "py38"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ruff will infer a missing target-version from the requires-python field in a pyproject.toml


[tool.ruff.lint]
extend-select = [
"E", # style errors
Expand Down
4 changes: 2 additions & 2 deletions src/higlass/_scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import itertools
from bisect import bisect_right
from typing import Iterable, Tuple
from collections.abc import Iterable

GenomicPosition = Tuple[str, int]
GenomicPosition = tuple[str, int]


class Scale:
Expand Down
4 changes: 2 additions & 2 deletions src/higlass/_utils.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from __future__ import annotations

import uuid
from typing import Literal, TypeVar, Union
from typing import Literal, TypeVar

import higlass_schema as hgs
from pydantic import BaseModel

TrackType = Union[hgs.EnumTrackType, Literal["heatmap"]]
TrackType = hgs.EnumTrackType | Literal["heatmap"]
TrackPosition = Literal["center", "top", "left", "bottom", "center", "whole", "gallery"]

track_default_position: dict[str, TrackPosition] = {
Expand Down
19 changes: 9 additions & 10 deletions src/higlass/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
Generic,
Literal,
TypeVar,
Union,
cast,
overload,
)
Expand Down Expand Up @@ -158,13 +157,13 @@ class PluginTrack(hgs.BaseTrack, _OptionsMixin, _PropertiesMixin):
plugin_url: ClassVar[str]


Track = Union[
HeatmapTrack,
IndependentViewportProjectionTrack,
EnumTrack,
CombinedTrack,
PluginTrack,
]
Track = (
HeatmapTrack
| IndependentViewportProjectionTrack
| EnumTrack
| CombinedTrack
| PluginTrack
)

TrackT = TypeVar("TrackT", bound=Track)

Expand Down Expand Up @@ -588,7 +587,7 @@ def mapper(view):
getattr(a, lockattr).locksByViewUid.update(locks.locksByViewUid)
getattr(a, lockattr).locksDict.update(locks.locksDict)

return cast(Viewconf[Union[TrackTA, TrackTB]], a)
return cast(Viewconf[TrackTA | TrackTB], a)


hconcat = functools.partial(concat, "horizontal")
Expand Down Expand Up @@ -787,7 +786,7 @@ def combine(t1: Track, t2: Track, uid: str | None = None, **kwargs) -> CombinedT
)


T = TypeVar("T", bound=Union[EnumTrack, HeatmapTrack])
T = TypeVar("T", bound=EnumTrack | HeatmapTrack)


def divide(t1: T, t2: T, **kwargs) -> T:
Expand Down
Loading