Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: Add syntax for registering backends in pyproject.toml #8331

Merged
merged 1 commit into from
Oct 19, 2023
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
1 change: 1 addition & 0 deletions ci/requirements/doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ dependencies:
- sphinx-book-theme >= 0.3.0
- sphinx-copybutton
- sphinx-design
- sphinx-inline-tabs
- sphinx>=5.0
- zarr>=2.10
- pip:
Expand Down
1 change: 1 addition & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"sphinx_copybutton",
"sphinxext.rediraffe",
"sphinx_design",
"sphinx_inline_tabs",
]


Expand Down
58 changes: 37 additions & 21 deletions doc/internals/how-to-add-new-backend.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ to integrate any code in Xarray; all you need to do is:
- Create a class that inherits from Xarray :py:class:`~xarray.backends.BackendEntrypoint`
and implements the method ``open_dataset`` see :ref:`RST backend_entrypoint`

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

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

Expand Down Expand Up @@ -267,42 +268,57 @@ interface only the boolean keywords related to the supported decoders.
How to register a backend
+++++++++++++++++++++++++

Define a new entrypoint in your ``setup.py`` (or ``setup.cfg``) with:
Define a new entrypoint in your ``pyproject.toml`` (or ``setup.cfg/setup.py`` for older
configurations), with:

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

You can declare the entrypoint in ``setup.py`` using the following syntax:
You can declare the entrypoint in your project configuration like so:

.. code-block::
.. tab:: pyproject.toml

setuptools.setup(
entry_points={
"xarray.backends": ["my_engine=my_package.my_module:MyBackendEntryClass"],
},
)
.. code:: toml

[project.entry-points."xarray-backends"]
my_engine = "my_package.my_module:MyBackendEntrypoint"

.. tab:: pyproject.toml [Poetry]

.. code-block:: toml

[tool.poetry.plugins."xarray.backends"]
my_engine = "my_package.my_module:MyBackendEntrypoint"

in ``setup.cfg``:
.. tab:: setup.cfg

.. code-block:: cfg
.. code-block:: cfg

[options.entry_points]
xarray.backends =
my_engine = my_package.my_module:MyBackendEntryClass
[options.entry_points]
xarray.backends =
my_engine = my_package.my_module:MyBackendEntrypoint

.. tab:: setup.py

See https://packaging.python.org/specifications/entry-points/#data-model
for more information
.. code-block::

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:
setuptools.setup(
entry_points={
"xarray.backends": [
"my_engine=my_package.my_module:MyBackendEntrypoint"
],
},
)

.. code-block:: toml

[tool.poetry.plugins."xarray.backends"]
"my_engine" = "my_package.my_module:MyBackendEntryClass"
See the `Python Packaging User Guide
<https://packaging.python.org/specifications/entry-points/#data-model>`_ for more
information on entrypoints and details of the syntax.

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

.. _RST lazy_loading:

Expand Down