diff --git a/.gitignore b/.gitignore index e677cc6..d6d2e73 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,7 @@ poetry.lock venv*/ docs/api/ docs/examples/music*.svg -pyabc2/sheet/test.* +pyabc2/abcjs/headless/test.* # node node_modules diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 8b387a5..fb7a639 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -12,8 +12,8 @@ python: extra_requirements: - doc - sources - - widget - - sheet + - abcjs-widget + - abcjs-headless sphinx: configuration: docs/conf.py diff --git a/docs/api.rst b/docs/api.rst index e88c43e..c40945c 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -87,7 +87,7 @@ These methods/properties result from tune body parsing and repeat/ending expansi Tune sources ============ -.. currentmodule:: pyabc2.sources +.. module:: pyabc2.sources The :mod:`pyabc2.sources` namespace contains a few general tools. @@ -151,10 +151,15 @@ Functions: eskin.abctools_url_to_abc eskin.abc_to_abctools_url +abcjs tools +=========== + +.. module:: pyabc2.abcjs + Widget -====== +------ -.. automodule:: pyabc2.widget +.. automodule:: pyabc2.abcjs.widget .. autosummary:: :toctree: api/ @@ -164,9 +169,9 @@ Widget Headless rendering -================== +------------------ -.. automodule:: pyabc2.sheet +.. automodule:: pyabc2.abcjs.headless .. autosummary:: :toctree: api/ @@ -174,3 +179,14 @@ Headless rendering svg svg_to build + +HTML page generation +-------------------- + +.. automodule:: pyabc2.abcjs.htmlgen + +.. autosummary:: + :toctree: api/ + + html + open_html diff --git a/docs/examples/widget.ipynb b/docs/examples/widget.ipynb index ecb771a..46dc2a0 100644 --- a/docs/examples/widget.ipynb +++ b/docs/examples/widget.ipynb @@ -18,7 +18,7 @@ "import ipywidgets as ipw\n", "from IPython.display import SVG\n", "\n", - "from pyabc2.widget import ABCJSWidget, interactive" + "from pyabc2.abcjs.widget import ABCJSWidget, interactive" ] }, { @@ -28,7 +28,8 @@ "source": [ "## The display widget\n", "\n", - "Used to {ref}`display ` {class}`~pyabc2.Tune`s in the notebook environment." + "Used to {ref}`display ` {class}`~pyabc2.Tune`s in the notebook environment.\n", + "{class}`~pyabc2.abcjs.widget.ABCJSWidget` supports many of the [abcjs render options](https://docs.abcjs.net/visual/render-abc-options.html)." ] }, { @@ -274,7 +275,7 @@ "source": [ "## Headless\n", "\n", - "We can also use abcjs in the background via Node.js using {mod}`pyabc2.sheet`." + "We can also use abcjs in the background via Node.js using {mod}`pyabc2.abcjs.headless`." ] }, { @@ -286,7 +287,7 @@ "source": [ "from IPython.display import SVG, Image\n", "\n", - "from pyabc2.sheet import svg, svg_to" + "from pyabc2.abcjs.headless import svg, svg_to" ] }, { @@ -306,8 +307,8 @@ "id": "26", "metadata": {}, "source": [ - "{func}`~pyabc2.sheet.build` is automatically called if needed.\n", - "But the next time we call {func}`~pyabc2.sheet.svg`, it will be ready to go:" + "{func}`~pyabc2.abcjs.headless.build` is automatically called if needed.\n", + "The next time we call {func}`~pyabc2.abcjs.headless.svg`, it should be faster." ] }, { diff --git a/pyabc2/sheet/__init__.py b/pyabc2/abcjs/headless/__init__.py similarity index 97% rename from pyabc2/sheet/__init__.py rename to pyabc2/abcjs/headless/__init__.py index e01e475..121c169 100644 --- a/pyabc2/sheet/__init__.py +++ b/pyabc2/abcjs/headless/__init__.py @@ -24,7 +24,7 @@ def build(): raise RuntimeError( "The 'nodejs-wheel-binaries' package is required " "to render sheet music in the background with abcjs via Node.js. " - "It is included with the pyabc2 'sheet' extra." + "It is included with the pyabc2 'abcjs-headless' extra." ) from e rc = npm(["install", "--prefix", HERE.as_posix()]) @@ -64,7 +64,7 @@ def svg( **kwargs Additional abcjs options that haven't been explicitly defined here in the signature. - https://paulrosen.github.io/abcjs/visual/render-abc-options.html + https://docs.abcjs.net/visual/render-abc-options.html """ from nodejs_wheel import node diff --git a/pyabc2/sheet/cli.cjs b/pyabc2/abcjs/headless/cli.cjs similarity index 100% rename from pyabc2/sheet/cli.cjs rename to pyabc2/abcjs/headless/cli.cjs diff --git a/pyabc2/sheet/package.json b/pyabc2/abcjs/headless/package.json similarity index 100% rename from pyabc2/sheet/package.json rename to pyabc2/abcjs/headless/package.json diff --git a/pyabc2/sheet/render.js b/pyabc2/abcjs/headless/render.js similarity index 100% rename from pyabc2/sheet/render.js rename to pyabc2/abcjs/headless/render.js diff --git a/pyabc2/html.py b/pyabc2/abcjs/htmlgen/__init__.py similarity index 97% rename from pyabc2/html.py rename to pyabc2/abcjs/htmlgen/__init__.py index 0576d9f..6f2aa94 100644 --- a/pyabc2/html.py +++ b/pyabc2/abcjs/htmlgen/__init__.py @@ -52,7 +52,7 @@ def html( **kwargs Additional abcjs options that haven't been explicitly defined here in the signature. - https://paulrosen.github.io/abcjs/visual/render-abc-options.html + https://docs.abcjs.net/visual/render-abc-options.html """ params = { **kwargs, diff --git a/pyabc2/widget/__init__.py b/pyabc2/abcjs/widget/__init__.py similarity index 95% rename from pyabc2/widget/__init__.py rename to pyabc2/abcjs/widget/__init__.py index a953e11..9ddb999 100644 --- a/pyabc2/widget/__init__.py +++ b/pyabc2/abcjs/widget/__init__.py @@ -19,10 +19,13 @@ class ABCJSWidget(anywidget.AnyWidget): """Display SVG sheet music rendered from ABC notation by abcjs. + Many of the `render options `__ + are supported, though some names have been modified to fit the Python style. + Examples -------- - >>> from pyabc2.widget import ABCJSWidget - >>> w = ABCJSWidget(abc="ABCD", staff_width=250) + >>> from pyabc2.abcjs.widget import ABCJSWidget + >>> w = ABCJSWidget(abc='ABCD', staff_width=250) """ _esm = HERE / "index.js" diff --git a/pyabc2/widget/index.css b/pyabc2/abcjs/widget/index.css similarity index 100% rename from pyabc2/widget/index.css rename to pyabc2/abcjs/widget/index.css diff --git a/pyabc2/widget/index.js b/pyabc2/abcjs/widget/index.js similarity index 100% rename from pyabc2/widget/index.js rename to pyabc2/abcjs/widget/index.js diff --git a/pyabc2/parse.py b/pyabc2/parse.py index 9105410..2f06f32 100644 --- a/pyabc2/parse.py +++ b/pyabc2/parse.py @@ -336,9 +336,7 @@ def _extract_measures(self, tune_lines: list[str]) -> None: self.measures = measures def __repr__(self): - return ( - f"{self.__class__.__name__}(title={self.title!r}, key={self.key}, type={self.type!r})" - ) + return f"{type(self).__name__}(title={self.title!r}, key={self.key}, type={self.type!r})" def __eq__(self, other): if not isinstance(other, type(self)): @@ -354,10 +352,10 @@ def _repr_html_(self): # pragma: no cover try: from IPython.display import display - from .widget import ABCJSWidget + from .abcjs.widget import ABCJSWidget except ImportError: warnings.warn( - "The 'widget' extra is required for HTML representation of tunes via abcjs." + "The 'abcjs-widget' extra is required for HTML representation of tunes via abcjs." ) else: display(ABCJSWidget(abc=self.abc)) diff --git a/pyproject.toml b/pyproject.toml index 2e0e648..3fc9cf3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,12 +23,12 @@ sources = [ "pandas ==2.*", "requests ==2.*", ] -widget = [ +abcjs-widget = [ "anywidget", "ipywidgets", "traitlets", ] -sheet = [ +abcjs-headless = [ "cairosvg", "nodejs-wheel-binaries", ] diff --git a/tests/test_abcjs_nodejs.py b/tests/test_abcjs_headless.py similarity index 96% rename from tests/test_abcjs_nodejs.py rename to tests/test_abcjs_headless.py index a789994..4ec45ce 100644 --- a/tests/test_abcjs_nodejs.py +++ b/tests/test_abcjs_headless.py @@ -1,6 +1,6 @@ import pytest -from pyabc2.sheet import svg, svg_to +from pyabc2.abcjs.headless import svg, svg_to HAVE_CAIROSVG = True try: diff --git a/tests/test_html.py b/tests/test_html.py index 1395f8a..a087759 100644 --- a/tests/test_html.py +++ b/tests/test_html.py @@ -1,7 +1,7 @@ from pathlib import Path from tempfile import gettempdir -from pyabc2.html import html, open_html +from pyabc2.abcjs.htmlgen import html, open_html TMP = gettempdir()