Skip to content

World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.

[#4829] improvement(client-python): Sphinx Initialization (#4830)

noidname01f8e39b4f5125
diff --git a/build.gradle.kts b/build.gradle.kts
index 93feb52dea..da13580a32 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -508,7 +508,9 @@ tasks.rat {
"clients/client-python/apache_gravitino.egg-info/*",
"clients/client-python/gravitino/utils/http_client.py",
"clients/client-python/tests/unittests/htmlcov/*",
- "clients/client-python/tests/integration/htmlcov/*"
+ "clients/client-python/tests/integration/htmlcov/*",
+ "clients/client-python/docs/build",
+ "clients/client-python/docs/source/generated"
)
// Add .gitignore excludes to the Apache Rat exclusion list.
diff --git a/clients/client-python/.gitignore b/clients/client-python/.gitignore
index 20c0f8c5a1..18200b504a 100644
--- a/clients/client-python/.gitignore
+++ b/clients/client-python/.gitignore
@@ -28,7 +28,6 @@ dist
build
README.md
gravitino/version.ini
-docs
# Unit test / coverage reports
htmlcov/
@@ -44,3 +43,7 @@ coverage.xml
.hypothesis/
.pytest_cache/
cover/
+
+# Documentation Related
+docs/build
+docs/source/generated
\ No newline at end of file
diff --git a/clients/client-python/build.gradle.kts b/clients/client-python/build.gradle.kts
index 625e28c146..bebf536f6e 100644
--- a/clients/client-python/build.gradle.kts
+++ b/clients/client-python/build.gradle.kts
@@ -272,9 +272,10 @@ tasks {
}
}
- val pydoc by registering(VenvTask::class) {
- venvExec = "python"
- args = listOf("scripts/generate_doc.py")
+ val doc by registering(VenvTask::class) {
+ workingDir = projectDir.resolve("./docs")
+ venvExec = "make"
+ args = listOf("html")
}
val distribution by registering(VenvTask::class) {
@@ -318,7 +319,8 @@ tasks {
val clean by registering(Delete::class) {
delete("build")
delete("dist")
- delete("docs")
+ delete("docs/build")
+ delete("docs/source/generated")
delete("gravitino/version.ini")
delete("apache_gravitino.egg-info")
delete("tests/unittests/htmlcov")
diff --git a/clients/client-python/docs/Makefile b/clients/client-python/docs/Makefile
new file mode 100644
index 0000000000..5c5e2b9407
--- /dev/null
+++ b/clients/client-python/docs/Makefile
@@ -0,0 +1,37 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+
+# http://www.apache.org/licenses/LICENSE-2.0
+
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# 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/clients/client-python/docs/make.bat b/clients/client-python/docs/make.bat
new file mode 100644
index 0000000000..240af4fc78
--- /dev/null
+++ b/clients/client-python/docs/make.bat
@@ -0,0 +1,52 @@
+@REM Licensed to the Apache Software Foundation (ASF) under one
+@REM or more contributor license agreements. See the NOTICE file
+@REM distributed with this work for additional information
+@REM regarding copyright ownership. The ASF licenses this file
+@REM to you under the Apache License, Version 2.0 (the
+@REM "License"); you may not use this file except in compliance
+@REM with the License. You may obtain a copy of the License at
+
+@REM http://www.apache.org/licenses/LICENSE-2.0
+
+@REM Unless required by applicable law or agreed to in writing,
+@REM software distributed under the License is distributed on an
+@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+@REM KIND, either express or implied. See the License for the
+@REM specific language governing permissions and limitations
+@REM under the License.
+
+@ECHO OFF
+
+pushd %~dp0
+
+REM Command file for Sphinx documentation
+
+if "%SPHINXBUILD%" == "" (
+ set SPHINXBUILD=sphinx-build
+)
+set SOURCEDIR=source
+set BUILDDIR=build
+
+%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
+)
+
+if "%1" == "" goto help
+
+%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
+goto end
+
+:help
+%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
+
+:end
+popd
diff --git a/clients/client-python/docs/source/_templates/custom-class-template.rst b/clients/client-python/docs/source/_templates/custom-class-template.rst
new file mode 100644
index 0000000000..8fbff577e1
--- /dev/null
+++ b/clients/client-python/docs/source/_templates/custom-class-template.rst
@@ -0,0 +1,49 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+{{ fullname | escape | underline}}
+
+.. currentmodule:: {{ module }}
+
+.. autoclass:: {{ objname }}
+ :members:
+ :show-inheritance:
+ :inherited-members:
+
+ {% block methods %}
+ .. automethod:: __init__
+
+ {% if methods %}
+ .. rubric:: {{ _('Methods') }}
+
+ .. autosummary::
+ {% for item in methods %}
+ ~{{ name }}.{{ item }}
+ {%- endfor %}
+ {% endif %}
+ {% endblock %}
+
+ {% block attributes %}
+ {% if attributes %}
+ .. rubric:: {{ _('Attributes') }}
+
+ .. autosummary::
+ {% for item in attributes %}
+ ~{{ name }}.{{ item }}
+ {%- endfor %}
+ {% endif %}
+ {% endblock %}
\ No newline at end of file
diff --git a/clients/client-python/docs/source/_templates/custom-module-template.rst b/clients/client-python/docs/source/_templates/custom-module-template.rst
new file mode 100644
index 0000000000..fd8901bc46
--- /dev/null
+++ b/clients/client-python/docs/source/_templates/custom-module-template.rst
@@ -0,0 +1,83 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+{{ fullname | escape | underline}}
+
+.. automodule:: {{ fullname }}
+
+ {% block attributes %}
+ {% if attributes %}
+ .. rubric:: Module Attributes
+
+ .. autosummary::
+ :toctree:
+ {% for item in attributes %}
+ {{ item }}
+ {%- endfor %}
+ {% endif %}
+ {% endblock %}
+
+ {% block functions %}
+ {% if functions %}
+ .. rubric:: {{ _('Functions') }}
+
+ .. autosummary::
+ :toctree:
+ {% for item in functions %}
+ {{ item }}
+ {%- endfor %}
+ {% endif %}
+ {% endblock %}
+
+ {% block classes %}
+ {% if classes %}
+ .. rubric:: {{ _('Classes') }}
+
+ .. autosummary::
+ :toctree:
+ :template: custom-class-template.rst
+ {% for item in classes %}
+ {{ item }}
+ {%- endfor %}
+ {% endif %}
+ {% endblock %}
+
+ {% block exceptions %}
+ {% if exceptions %}
+ .. rubric:: {{ _('Exceptions') }}
+
+ .. autosummary::
+ :toctree:
+ {% for item in exceptions %}
+ {{ item }}
+ {%- endfor %}
+ {% endif %}
+ {% endblock %}
+
+{% block modules %}
+{% if modules %}
+.. rubric:: Modules
+
+.. autosummary::
+ :toctree:
+ :template: custom-module-template.rst
+ :recursive:
+{% for item in modules %}
+ {{ item }}
+{%- endfor %}
+{% endif %}
+{% endblock %}
\ No newline at end of file
diff --git a/clients/client-python/docs/source/conf.py b/clients/client-python/docs/source/conf.py
new file mode 100644
index 0000000000..3d9233cb4c
--- /dev/null
+++ b/clients/client-python/docs/source/conf.py
@@ -0,0 +1,76 @@
+"""
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+"""
+
+# Configuration file for the Sphinx documentation builder.
+#
+# For the full list of built-in configuration values, see the documentation:
+# https://www.sphinx-doc.org/en/master/usage/configuration.html
+
+# -- Project information -----------------------------------------------------
+# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
+import os
+import sys
+import re
+
+sys.path.insert(0, os.path.abspath('../..'))
+
+from gravitino.constants.version import SETUP_FILE
+from gravitino.exceptions.base import GravitinoRuntimeException
+
+VERSION_PATTERN = r"version\s*=\s*['\"]([^'\"]+)['\"]"
+AUTHOR_PATTERN = r"author\s*=\s*['\"]([^'\"]+)['\"]"
+
+
+with open(SETUP_FILE, "r", encoding="utf-8") as f:
+ setup_content = f.read()
+
+ version_group = re.search(VERSION_PATTERN, setup_content)
+ if version_group is not None:
+ project_version = version_group.group(1)
+ else:
+ raise GravitinoRuntimeException("Can't find valid author info in setup.py")
+
+ author_group = re.search(AUTHOR_PATTERN, setup_content)
+ if author_group is not None:
+ project_author = author_group.group(1)
+ else:
+ raise GravitinoRuntimeException("Can't find valid author info in setup.py")
+
+project = 'Apache Gravitino Python Client'
+copyright = '2024, Apache Software Foundation'
+author = project_author
+release = project_version
+
+# -- General configuration ---------------------------------------------------
+# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
+
+
+extensions = [
+ 'sphinx.ext.autodoc',
+ 'sphinx.ext.autosummary',
+]
+
+templates_path = ['_templates']
+exclude_patterns = []
+
+# -- Options for HTML output -------------------------------------------------
+# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
+
+html_theme = 'furo'
+html_static_path = ['_static']
diff --git a/clients/client-python/docs/source/index.rst b/clients/client-python/docs/source/index.rst
new file mode 100644
index 0000000000..c78aa3bf49
--- /dev/null
+++ b/clients/client-python/docs/source/index.rst
@@ -0,0 +1,33 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+.. Apache Gravitino Python Client documentation master file, created by
+ sphinx-quickstart on Fri Aug 30 14:16:27 2024.
+ You can adapt this file completely to your liking, but it should at least
+ contain the root `toctree` directive.
+
+Apache Gravitino Python Client documentation
+============================================
+
+Packages
+-----------
+.. autosummary::
+ :toctree: generated
+ :template: custom-module-template.rst
+ :recursive:
+
+ gravitino
diff --git a/clients/client-python/requirements-dev.txt b/clients/client-python/requirements-dev.txt
index 002e08964c..a268278321 100644
--- a/clients/client-python/requirements-dev.txt
+++ b/clients/client-python/requirements-dev.txt
@@ -30,3 +30,5 @@ readerwriterlock==1.0.9
docker==7.1.0
pyjwt[crypto]==2.8.0
jwcrypto==1.5.6
+sphinx==7.1.2
+furo==2024.8.6
diff --git a/clients/client-python/scripts/generate_doc.py b/clients/client-python/scripts/generate_doc.py
deleted file mode 100644
index 5bad954090..0000000000
--- a/clients/client-python/scripts/generate_doc.py
+++ /dev/null
@@ -1,42 +0,0 @@
-"""
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements. See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership. The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing,
-software distributed under the License is distributed on an
-"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-KIND, either express or implied. See the License for the
-specific language governing permissions and limitations
-under the License.
-"""
-
-import pydoc
-import os
-import shutil
-
-from gravitino.constants.doc import DOC_DIR
-from gravitino.constants.root import GRAVITINO_DIR, MODULE_NAME
-
-if __name__ == "__main__":
-
- if os.path.exists(DOC_DIR):
- # If doc folder exists, delete it
- shutil.rmtree(DOC_DIR)
-
- # Create a new doc folder
- os.makedirs(DOC_DIR)
- # Change work directory to doc folder
- os.chdir(DOC_DIR)
-
- # Write doc for top module
- pydoc.writedoc(MODULE_NAME)
-
- # Write doc for submodules
- pydoc.writedocs(GRAVITINO_DIR.as_posix(), MODULE_NAME + ".")