Skip to content

Commit e1bad52

Browse files
authored
Docs: Add syntax for registering backends in pyproject.toml (#8331)
Uses `sphinx-inline-tabs` for pretty and compact options. Also reword surrounding text a little for clarity, and make examples consistent with entry point class example
1 parent dbf8df2 commit e1bad52

File tree

3 files changed

+39
-21
lines changed

3 files changed

+39
-21
lines changed

ci/requirements/doc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ dependencies:
3434
- sphinx-book-theme >= 0.3.0
3535
- sphinx-copybutton
3636
- sphinx-design
37+
- sphinx-inline-tabs
3738
- sphinx>=5.0
3839
- zarr>=2.10
3940
- pip:

doc/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
"sphinx_copybutton",
8585
"sphinxext.rediraffe",
8686
"sphinx_design",
87+
"sphinx_inline_tabs",
8788
]
8889

8990

doc/internals/how-to-add-new-backend.rst

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ to integrate any code in Xarray; all you need to do is:
99
- Create a class that inherits from Xarray :py:class:`~xarray.backends.BackendEntrypoint`
1010
and implements the method ``open_dataset`` see :ref:`RST backend_entrypoint`
1111

12-
- Declare this class as an external plugin in your ``setup.py``, see :ref:`RST backend_registration`
12+
- Declare this class as an external plugin in your project configuration, see :ref:`RST
13+
backend_registration`
1314

1415
If you also want to support lazy loading and dask see :ref:`RST lazy_loading`.
1516

@@ -267,42 +268,57 @@ interface only the boolean keywords related to the supported decoders.
267268
How to register a backend
268269
+++++++++++++++++++++++++
269270

270-
Define a new entrypoint in your ``setup.py`` (or ``setup.cfg``) with:
271+
Define a new entrypoint in your ``pyproject.toml`` (or ``setup.cfg/setup.py`` for older
272+
configurations), with:
271273

272274
- group: ``xarray.backends``
273275
- name: the name to be passed to :py:meth:`~xarray.open_dataset` as ``engine``
274276
- object reference: the reference of the class that you have implemented.
275277

276-
You can declare the entrypoint in ``setup.py`` using the following syntax:
278+
You can declare the entrypoint in your project configuration like so:
277279

278-
.. code-block::
280+
.. tab:: pyproject.toml
279281

280-
setuptools.setup(
281-
entry_points={
282-
"xarray.backends": ["my_engine=my_package.my_module:MyBackendEntryClass"],
283-
},
284-
)
282+
.. code:: toml
283+
284+
[project.entry-points."xarray-backends"]
285+
my_engine = "my_package.my_module:MyBackendEntrypoint"
286+
287+
.. tab:: pyproject.toml [Poetry]
288+
289+
.. code-block:: toml
290+
291+
[tool.poetry.plugins."xarray.backends"]
292+
my_engine = "my_package.my_module:MyBackendEntrypoint"
285293
286-
in ``setup.cfg``:
294+
.. tab:: setup.cfg
287295

288-
.. code-block:: cfg
296+
.. code-block:: cfg
289297
290-
[options.entry_points]
291-
xarray.backends =
292-
my_engine = my_package.my_module:MyBackendEntryClass
298+
[options.entry_points]
299+
xarray.backends =
300+
my_engine = my_package.my_module:MyBackendEntrypoint
293301
302+
.. tab:: setup.py
294303

295-
See https://packaging.python.org/specifications/entry-points/#data-model
296-
for more information
304+
.. code-block::
297305
298-
If you are using `Poetry <https://python-poetry.org/>`_ for your build system, you can accomplish the same thing using "plugins". In this case you would need to add the following to your ``pyproject.toml`` file:
306+
setuptools.setup(
307+
entry_points={
308+
"xarray.backends": [
309+
"my_engine=my_package.my_module:MyBackendEntrypoint"
310+
],
311+
},
312+
)
299313
300-
.. code-block:: toml
301314
302-
[tool.poetry.plugins."xarray.backends"]
303-
"my_engine" = "my_package.my_module:MyBackendEntryClass"
315+
See the `Python Packaging User Guide
316+
<https://packaging.python.org/specifications/entry-points/#data-model>`_ for more
317+
information on entrypoints and details of the syntax.
304318

305-
See https://python-poetry.org/docs/pyproject/#plugins for more information on Poetry plugins.
319+
If you're using Poetry, note that table name in ``pyproject.toml`` is slightly different.
320+
See `the Poetry docs <https://python-poetry.org/docs/pyproject/#plugins>`_ for more
321+
information on plugins.
306322

307323
.. _RST lazy_loading:
308324

0 commit comments

Comments
 (0)