From 19be5802ea8adeac77567d6fed60d06b164afa72 Mon Sep 17 00:00:00 2001 From: PhilipMay Date: Wed, 19 Jan 2022 21:44:52 +0100 Subject: [PATCH] add sphinx Signed-off-by: Philip May --- .github/workflows/build_deploy_doc.yml | 33 ++++++++ DEVELOPER_GUIDE.md | 13 +++ docs/Makefile | 20 +++++ docs/make.bat | 35 ++++++++ docs/source/README.md | 1 + docs/source/_static/css/custom.css | 20 +++++ docs/source/_templates/.gitkeep | 0 docs/source/api-ref.md | 11 +++ docs/source/api-ref/client.md | 5 ++ docs/source/api-ref/connection.md | 13 +++ docs/source/api-ref/connection_pool.md | 13 +++ docs/source/api-ref/exceptions.md | 57 +++++++++++++ docs/source/api-ref/serializer.md | 5 ++ docs/source/api-ref/transport.md | 5 ++ docs/source/conf.py | 111 +++++++++++++++++++++++++ docs/source/genindex.md | 1 + docs/source/imgs/OpenSearch.svg | 1 + docs/source/index.md | 19 +++++ setup.py | 2 +- 19 files changed, 364 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/build_deploy_doc.yml create mode 100644 docs/Makefile create mode 100644 docs/make.bat create mode 120000 docs/source/README.md create mode 100644 docs/source/_static/css/custom.css create mode 100644 docs/source/_templates/.gitkeep create mode 100644 docs/source/api-ref.md create mode 100644 docs/source/api-ref/client.md create mode 100644 docs/source/api-ref/connection.md create mode 100644 docs/source/api-ref/connection_pool.md create mode 100644 docs/source/api-ref/exceptions.md create mode 100644 docs/source/api-ref/serializer.md create mode 100644 docs/source/api-ref/transport.md create mode 100644 docs/source/conf.py create mode 100644 docs/source/genindex.md create mode 120000 docs/source/imgs/OpenSearch.svg create mode 100644 docs/source/index.md diff --git a/.github/workflows/build_deploy_doc.yml b/.github/workflows/build_deploy_doc.yml new file mode 100644 index 00000000..b264079b --- /dev/null +++ b/.github/workflows/build_deploy_doc.yml @@ -0,0 +1,33 @@ +name: Build & Deploy Doc +on: + push: + branches: [ main ] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +jobs: + build-and-deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + with: + python-version: 3.7 + + - name: Install + run: | + python -m pip install -U pip + pip install --progress-bar off -U .[doc,optional] + + - name: Make + run: | + cd docs + make html + cd .. + + - name: Deploy + uses: peaceiris/actions-gh-pages@v3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./docs/build/html diff --git a/DEVELOPER_GUIDE.md b/DEVELOPER_GUIDE.md index 827ddd08..10dbb2e7 100644 --- a/DEVELOPER_GUIDE.md +++ b/DEVELOPER_GUIDE.md @@ -1,3 +1,6 @@ +# Developer Guide + +## Linter and Test Suite Run the linter and test suite to ensure your changes do not break existing code: ``` @@ -11,6 +14,7 @@ $ nox -rs format $ nox -rs test ``` +## Integration Tests To run the integration tests locally, run: ``` @@ -20,3 +24,12 @@ To run the integration tests locally, run: The first argument, `opensearch` tells the server type to run integration test against. Valid values are `opensearch` and `opendistro`. The second argument tells whether to run server with security plugin enabled or not. Note that integration tests require docker to be installed and running, and downloads quite a bit of data from over the internet and hence take few minutes to complete. + +## Build the Documentation with Sphinx +This are the steps to build the documentation with [Sphinx](https://www.sphinx-doc.org/): + +1. change into the `opensearch-py` directory where `setup.py` is located +2. install opensearch-py - we recommend [editable mode](https://pip.pypa.io/en/stable/cli/pip_install/#cmdoption-e): `pip install -e .[docs]` +3. change into the `docs` directory +4. execute `make html` +5. use your favorite web browser to open the file called `opensearch-py/docs/build/html/index.html` diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 00000000..d0c3cbf1 --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,20 @@ +# Minimal makefile for Sphinx documentation +# + +# You can set these variables from the command line, and also +# from the environment for the first two. +SPHINXOPTS ?= +SPHINXBUILD ?= sphinx-build +SOURCEDIR = source +BUILDDIR = build + +# Put it first so that "make" without argument is like "make help". +help: + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + +.PHONY: help Makefile + +# Catch-all target: route all unknown targets to Sphinx using the new +# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). +%: Makefile + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/docs/make.bat b/docs/make.bat new file mode 100644 index 00000000..061f32f9 --- /dev/null +++ b/docs/make.bat @@ -0,0 +1,35 @@ +@ECHO OFF + +pushd %~dp0 + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set SOURCEDIR=source +set BUILDDIR=build + +if "%1" == "" goto help + +%SPHINXBUILD% >NUL 2>NUL +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.https://www.sphinx-doc.org/ + exit /b 1 +) + +%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% +goto end + +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% + +:end +popd diff --git a/docs/source/README.md b/docs/source/README.md new file mode 120000 index 00000000..fe840054 --- /dev/null +++ b/docs/source/README.md @@ -0,0 +1 @@ +../../README.md \ No newline at end of file diff --git a/docs/source/_static/css/custom.css b/docs/source/_static/css/custom.css new file mode 100644 index 00000000..c9c217c2 --- /dev/null +++ b/docs/source/_static/css/custom.css @@ -0,0 +1,20 @@ +/* +.wy-nav-top: top box in mobile view +.wy-side-nav-search: top left box in nav bar +.wy-side-nav-search > a:hover: no hover highlight +*/ +.wy-nav-top, +.wy-side-nav-search, +.wy-side-nav-search > a:hover { + background-color: #2980b9; +} + +/* broader content area */ +.wy-nav-content { + max-width: 1000px; +} + +/* top left project name -> bigger */ +.wy-side-nav-search > a.icon.icon-home { + font-size: 160%; +} diff --git a/docs/source/_templates/.gitkeep b/docs/source/_templates/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/docs/source/api-ref.md b/docs/source/api-ref.md new file mode 100644 index 00000000..5d92e038 --- /dev/null +++ b/docs/source/api-ref.md @@ -0,0 +1,11 @@ +# API Reference + +```{toctree} +--- +glob: +titlesonly: +maxdepth: 2 +--- + +api-ref/* +``` diff --git a/docs/source/api-ref/client.md b/docs/source/api-ref/client.md new file mode 100644 index 00000000..2ef2d671 --- /dev/null +++ b/docs/source/api-ref/client.md @@ -0,0 +1,5 @@ +# client + +```{eval-rst} +.. autoclass:: opensearchpy.OpenSearch +``` diff --git a/docs/source/api-ref/connection.md b/docs/source/api-ref/connection.md new file mode 100644 index 00000000..c5bca91d --- /dev/null +++ b/docs/source/api-ref/connection.md @@ -0,0 +1,13 @@ +# connection + +```{eval-rst} +.. autoclass:: opensearchpy.Connection +``` + +```{eval-rst} +.. autoclass:: opensearchpy.RequestsHttpConnection +``` + +```{eval-rst} +.. autoclass:: opensearchpy.Urllib3HttpConnection +``` diff --git a/docs/source/api-ref/connection_pool.md b/docs/source/api-ref/connection_pool.md new file mode 100644 index 00000000..6e5b9261 --- /dev/null +++ b/docs/source/api-ref/connection_pool.md @@ -0,0 +1,13 @@ +# connection_pool + +```{eval-rst} +.. autoclass:: opensearchpy.ConnectionPool +``` + +```{eval-rst} +.. autoclass:: opensearchpy.ConnectionSelector +``` + +```{eval-rst} +.. autoclass:: opensearchpy.RoundRobinSelector +``` diff --git a/docs/source/api-ref/exceptions.md b/docs/source/api-ref/exceptions.md new file mode 100644 index 00000000..90e05166 --- /dev/null +++ b/docs/source/api-ref/exceptions.md @@ -0,0 +1,57 @@ +# exceptions + +```{eval-rst} +.. autoclass:: opensearchpy.AuthenticationException +``` + +```{eval-rst} +.. autoclass:: opensearchpy.AuthorizationException +``` + +```{eval-rst} +.. autoclass:: opensearchpy.ConflictError +``` + +```{eval-rst} +.. autoclass:: opensearchpy.ConnectionError +``` + +```{eval-rst} +.. autoclass:: opensearchpy.ConnectionTimeout +``` + +```{eval-rst} +.. autoclass:: opensearchpy.ImproperlyConfigured +``` + +```{eval-rst} +.. autoclass:: opensearchpy.NotFoundError +``` + +```{eval-rst} +.. autoclass:: opensearchpy.OpenSearchDeprecationWarning +``` + +```{eval-rst} +.. autoclass:: opensearchpy.OpenSearchException +``` + +```{eval-rst} +.. autoclass:: opensearchpy.OpenSearchWarning +``` + +```{eval-rst} +.. autoclass:: opensearchpy.RequestError +``` + +```{eval-rst} +.. autoclass:: opensearchpy.SerializationError +``` + +```{eval-rst} +.. autoclass:: opensearchpy.SSLError +``` + +```{eval-rst} +.. autoclass:: opensearchpy.TransportError +``` diff --git a/docs/source/api-ref/serializer.md b/docs/source/api-ref/serializer.md new file mode 100644 index 00000000..b96a4b51 --- /dev/null +++ b/docs/source/api-ref/serializer.md @@ -0,0 +1,5 @@ +# serializer + +```{eval-rst} +.. autoclass:: opensearchpy.JSONSerializer +``` diff --git a/docs/source/api-ref/transport.md b/docs/source/api-ref/transport.md new file mode 100644 index 00000000..d1dce175 --- /dev/null +++ b/docs/source/api-ref/transport.md @@ -0,0 +1,5 @@ +# transport + +```{eval-rst} +.. autoclass:: opensearchpy.Transport +``` diff --git a/docs/source/conf.py b/docs/source/conf.py new file mode 100644 index 00000000..2db76b9f --- /dev/null +++ b/docs/source/conf.py @@ -0,0 +1,111 @@ +# Configuration file for the Sphinx documentation builder. +# +# This file only contains a selection of the most common options. For a full +# list see the documentation: +# https://www.sphinx-doc.org/en/master/usage/configuration.html + +# -- Path setup -------------------------------------------------------------- + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +# +# import os +# import sys +# sys.path.insert(0, os.path.abspath('.')) + + +# -- Project information ----------------------------------------------------- + +project = 'OpenSearch Python Client' +copyright = 'OpenSearch Project Contributors' +author = 'OpenSearch Project Contributors' + + +# -- General configuration --------------------------------------------------- + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [ + "sphinx.ext.autodoc", + "sphinx_rtd_theme", + "sphinx.ext.viewcode", + "myst_parser", # https://myst-parser.readthedocs.io/ + "sphinx.ext.intersphinx", + "sphinx_copybutton", # https://github.com/executablebooks/sphinx-copybutton + "sphinx.ext.todo", # https://www.sphinx-doc.org/en/master/usage/extensions/todo.html +] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This pattern also affects html_static_path and html_extra_path. +exclude_patterns = [] + + +# -- Options for HTML output ------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +# +html_theme = 'sphinx_rtd_theme' + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] + +# -- additional settings ------------------------------------------------- +intersphinx_mapping = { + "python": ("https://docs.python.org/3", None), +} + +html_logo = "imgs/OpenSearch.svg" + +# These paths are either relative to html_static_path +# or fully qualified paths (eg. https://...) +html_css_files = [ + "css/custom.css", +] + +# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. +html_show_sphinx = False + +# add github link +html_context = { + "display_github": True, + "github_user": "opensearch-project", + "github_repo": "opensearch-py", + "github_version": "main/docs/source/", +} + +# -- autodoc config ------------------------------------------------- +# This value controls how to represent typehints. +# https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#confval-autodoc_typehints +autodoc_typehints = "description" + +# This value selects what content will be inserted into the main body of an autoclass directive. +# https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#confval-autoclass_content +autoclass_content = "both" + +# https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-add_module_names +# add_module_names = False + +# The default options for autodoc directives. +# https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#confval-autodoc_default_options +autodoc_default_options = { + # If set, autodoc will generate document for the members of the target module, class or exception. # noqa: E501 + # https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#directive-option-automodule-members + "members": True, + "show-inheritance": True, + # If set, autodoc will also generate document for the special members (that is, those named like __special__). # noqa: E501 + # https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#directive-option-automodule-special-members + "special-members": None, + # If set, autodoc will also generate document for the private members (that is, those named like _private or __private). # noqa: E501 + # https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#directive-option-automodule-private-members + "private-members": None, + "exclude-members": "__weakref__, __init__", +} diff --git a/docs/source/genindex.md b/docs/source/genindex.md new file mode 100644 index 00000000..8b013d6a --- /dev/null +++ b/docs/source/genindex.md @@ -0,0 +1 @@ +# Index diff --git a/docs/source/imgs/OpenSearch.svg b/docs/source/imgs/OpenSearch.svg new file mode 120000 index 00000000..361d002d --- /dev/null +++ b/docs/source/imgs/OpenSearch.svg @@ -0,0 +1 @@ +../../../OpenSearch.svg \ No newline at end of file diff --git a/docs/source/index.md b/docs/source/index.md new file mode 100644 index 00000000..8d228acf --- /dev/null +++ b/docs/source/index.md @@ -0,0 +1,19 @@ +# OpenSearch Python Client Documentation + +## Table of Contents +```{toctree} +--- +maxdepth: 1 +--- + +api-ref +genindex +License +Contributing +Code of Conduct +Developer Guide +GitHub Repository +``` + +```{include} README.md +``` diff --git a/setup.py b/setup.py index de7240b7..41a4b2cd 100644 --- a/setup.py +++ b/setup.py @@ -62,7 +62,7 @@ tests_require = [ ] async_require = ["aiohttp>=3,<4"] -docs_require = [] +docs_require = ["sphinx", "sphinx_rtd_theme", "myst_parser", "sphinx_copybutton"] generate_require = ["black", "jinja2"] setup(