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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ poetry.lock
venv*/
docs/api/
docs/examples/music*.svg
pyabc2/sheet/test.*
pyabc2/abcjs/headless/test.*

# node
node_modules
Expand Down
4 changes: 2 additions & 2 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ python:
extra_requirements:
- doc
- sources
- widget
- sheet
- abcjs-widget
- abcjs-headless

sphinx:
configuration: docs/conf.py
26 changes: 21 additions & 5 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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/
Expand All @@ -164,13 +169,24 @@ Widget


Headless rendering
==================
------------------

.. automodule:: pyabc2.sheet
.. automodule:: pyabc2.abcjs.headless

.. autosummary::
:toctree: api/

svg
svg_to
build

HTML page generation
--------------------

.. automodule:: pyabc2.abcjs.htmlgen

.. autosummary::
:toctree: api/

html
open_html
13 changes: 7 additions & 6 deletions docs/examples/widget.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
},
{
Expand All @@ -28,7 +28,8 @@
"source": [
"## The display widget\n",
"\n",
"Used to {ref}`display <tune_type>` {class}`~pyabc2.Tune`s in the notebook environment."
"Used to {ref}`display <tune_type>` {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)."
]
},
{
Expand Down Expand Up @@ -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`."
]
},
{
Expand All @@ -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"
]
},
{
Expand All @@ -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."
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()])
Expand Down Expand Up @@ -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

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion pyabc2/html.py → pyabc2/abcjs/htmlgen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 5 additions & 2 deletions pyabc2/widget/__init__.py → pyabc2/abcjs/widget/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@
class ABCJSWidget(anywidget.AnyWidget):
"""Display SVG sheet music rendered from ABC notation by abcjs.

Many of the `render options <https://docs.abcjs.net/visual/render-abc-options.html>`__
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"
Expand Down
File renamed without changes.
File renamed without changes.
8 changes: 3 additions & 5 deletions pyabc2/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)):
Expand All @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ sources = [
"pandas ==2.*",
"requests ==2.*",
]
widget = [
abcjs-widget = [
"anywidget",
"ipywidgets",
"traitlets",
]
sheet = [
abcjs-headless = [
"cairosvg",
"nodejs-wheel-binaries",
]
Expand Down
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_html.py
Original file line number Diff line number Diff line change
@@ -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()

Expand Down