Skip to content

Commit

Permalink
Add an example for pyproject.toml and move costly import
Browse files Browse the repository at this point in the history
  • Loading branch information
Xarthisius committed Jan 8, 2023
1 parent 4894cfa commit 0ac661e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
14 changes: 10 additions & 4 deletions doc/source/developing/extensions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,22 @@ Frontend as an extension

Starting with version 4.2 of yt, any externally installed package that exports
:class:`~yt.data_objects.static_output.Dataset` subclass as an entrypoint in
``yt.frontends`` namespace:
``yt.frontends`` namespace in ``setup.py``:

.. code-block:: python
setup(
entry_points={
"yt.frontends": ["myFrontend = my_frontend.api.MyFrontendDataset"]
}
# ...,
entry_points={"yt.frontends": ["myFrontend = my_frontend.api.MyFrontendDataset"]}
)
or ``pyproject.toml``:

.. code-block:: toml
[project.entry-points."yt.frontends"]
myFrontend = "my_frontend.api.MyFrontendDataset"
will be automatically loaded and immediately available in
:func:`~yt.loaders.load`.

Expand Down
4 changes: 3 additions & 1 deletion yt/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from multiprocessing import Pipe, Process
from multiprocessing.connection import Connection
from pathlib import Path
from pkg_resources import iter_entry_points
from typing import Dict, List, Optional, Tuple, Union
from urllib.parse import urlsplit

Expand Down Expand Up @@ -98,6 +97,9 @@ def load(
if not fn.startswith("http"):
fn = str(lookup_on_disk_data(fn))

# import it here cause it's costly
from pkg_resources import iter_entry_points

# Ensure that external frontends are loaded
for entrypoint in iter_entry_points("yt.frontends"):
entrypoint.load()
Expand Down
2 changes: 1 addition & 1 deletion yt/tests/test_external_frontends.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import mock
from unittest import mock

from yt.data_objects.static_output import Dataset
from yt.geometry.grid_geometry_handler import GridIndex
Expand Down

0 comments on commit 0ac661e

Please sign in to comment.