Skip to content

Commit

Permalink
👌 IMPROVE: Support old entry points interface (#321)
Browse files Browse the repository at this point in the history
Despite pinning to `importlib-metdata>=3.6` in #319,
python/importlib_metadata#308
could still cause Conda installs to fail using the newer interface.
So now the pinning is removed, and the new interface is only used if available.
  • Loading branch information
chrisjsewell authored Apr 26, 2021
1 parent ceb30a6 commit a4c21b1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[![Coverage Status][codecov-badge]][codecov-link]
[![Documentation Status][rtd-badge]][rtd-link]
[![PyPI][pypi-badge]][pypi-link]
[![Conda Version][conda-badge]][conda-link]

A collection of tools for working with Jupyter Notebooks in Sphinx.

Expand All @@ -26,3 +27,5 @@ See the [Contributing Guide](https://myst-nb.readthedocs.io/en/latest/develop/co
[codecov-link]: https://codecov.io/gh/executablebooks/MyST-NB
[pypi-badge]: https://img.shields.io/pypi/v/myst-nb.svg
[pypi-link]: https://pypi.org/project/myst-nb
[conda-badge]: https://img.shields.io/conda/vn/conda-forge/myst-nb.svg
[conda-link]: https://anaconda.org/conda-forge/myst-nb
13 changes: 10 additions & 3 deletions myst_nb/render_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,19 @@ class MystNbEntryPointError(SphinxError):
category = "MyST NB Renderer Load"


def load_renderer(name) -> "CellOutputRendererBase":
def load_renderer(name: str) -> "CellOutputRendererBase":
"""Load a renderer,
given a name within the ``myst_nb.mime_render`` entry point group
"""
eps = entry_points(group="myst_nb.mime_render", name=name)
if name in eps.names:
all_eps = entry_points()
if hasattr(all_eps, "select"):
# importlib_metadata >= 3.6 or importlib.metadata in python >=3.10
eps = all_eps.select(group="myst_nb.mime_render", name=name)
found = name in eps.names
else:
eps = {ep.name: ep for ep in all_eps.get("myst_nb.mime_render", [])}
found = name in eps
if found:
klass = eps[name].load()
if not issubclass(klass, CellOutputRendererBase):
raise MystNbEntryPointError(
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ project_urls =
packages = find:
install_requires =
docutils>=0.15
importlib_metadata>=3.6
importlib_metadata
ipython
ipywidgets>=7.0.0,<8
jupyter-cache~=0.4.1
Expand Down

0 comments on commit a4c21b1

Please sign in to comment.