Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into version-handling
Browse files Browse the repository at this point in the history
* upstream/main:
  Docs: Add syntax for registering backends in `pyproject.toml` (pydata#8331)
  Request to adjust pyright config (pydata#8329)
  • Loading branch information
dcherian committed Oct 19, 2023
2 parents bc588ea + e1bad52 commit ed24e18
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 22 deletions.
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
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@ defineConstant = {DEBUG = true}
# stubPath = "src/stubs"
# venv = "env367"

reportMissingImports = true
# Enabling this means that developers who have disabled the warning locally —
# because not all dependencies are installable — are overridden
# reportMissingImports = true
reportMissingTypeStubs = false

# pythonVersion = "3.6"
Expand Down

0 comments on commit ed24e18

Please sign in to comment.