Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/sphinx/api/elasticsearch.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Elasticsearch
-------------

.. py:module:: elasticsearch.client
.. py:module:: elasticsearch

.. autoclass:: Elasticsearch
:members:
34 changes: 33 additions & 1 deletion docs/sphinx/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,42 @@

extensions = ["sphinx.ext.autodoc", "sphinx.ext.doctest", "sphinx.ext.intersphinx"]

autoclass_content = "both"
autoclass_content = "class"
autodoc_class_signature = "separated"

autodoc_typehints = "description"


def client_name(full_name):
# Get the class name, e.g. ['elasticsearch', 'client', 'TextStructureClient'] -> 'TextStructure'
class_name = full_name.split(".")[-1].removesuffix("Client")
# Convert to snake case, e.g. 'TextStructure' -> '_text_structure'
snake_case = "".join(["_" + c.lower() if c.isupper() else c for c in class_name])
# Remove the leading underscore
return snake_case.lstrip("_")


def add_client_usage_example(app, what, name, obj, options, lines):
if what == "class" and "Client" in name:
sub_client_name = client_name(name)
lines.append(
f"To use this client, access ``client.{sub_client_name}`` from an "
" :class:`~elasticsearch.Elasticsearch` client. For example::"
)
lines.append("")
lines.append(" from elasticsearch import Elasticsearch")
lines.append("")
lines.append(" # Create the client instance")
lines.append(" client = Elasticsearch(...)")
lines.append(f" # Use the {sub_client_name} client")
lines.append(f" client.{sub_client_name}.<method>(...)")
lines.append("")


def setup(app):
app.connect("autodoc-process-docstring", add_client_usage_example)


# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]

Expand Down
2 changes: 2 additions & 0 deletions elasticsearch/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
from ._utils import fixup_module_metadata

# This file exists for backwards compatibility.
# We can't remove it as we use it for the Sphinx docs which show the full page, and we'd
# rather show `elasticsearch.client.FooClient` than `elasticsearch._sync.client.FooClient`.
warnings.warn(
"Importing from the 'elasticsearch.client' module is deprecated. "
"Instead use 'elasticsearch' module for importing the client.",
Expand Down
Loading