This repository has been archived by the owner on Jun 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathgenerate_docs.py
121 lines (85 loc) · 3.51 KB
/
generate_docs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import inspect
from databricks_api import DatabricksAPI
import databricks_cli
db = DatabricksAPI(host="localhost", token="token")
intro = """databricks-api
==============
**Please switch to the official Databricks SDK for Python (https://github.com/databricks/databricks-sdk-py) by running the following command:**
.. code-block:: bash
pip install databricks-sdk
|pypi| |pyversions|
.. |pypi| image:: https://img.shields.io/pypi/v/databricks-api.svg
:target: https://pypi.python.org/pypi/databricks-api
.. |pyversions| image:: https://img.shields.io/pypi/pyversions/databricks-api.svg
:target: https://pypi.python.org/pypi/databricks-api
*[This documentation is auto-generated]*
This package provides a simplified interface for the Databricks REST API.
The interface is autogenerated on instantiation using the underlying client
library used in the official ``databricks-cli`` python package.
Install using
.. code-block:: bash
pip install databricks-api
The docs here describe the interface for version **{version}** of
the ``databricks-cli`` package for API version **{api_version}**.
The ``databricks-api`` package contains a ``DatabricksAPI`` class which provides
instance attributes for the ``databricks-cli`` ``ApiClient``, as well as each of
the available service instances. The attributes of a ``DatabricksAPI`` instance are:
""".format(
version=databricks_cli.version.version, api_version=databricks_cli.sdk.version.API_VERSION
)
attrs = []
for k, v in db.__dict__.items():
attrs.append("* DatabricksAPI." + k + " *<" + v.__class__.__module__ + "." + v.__class__.__name__ + ">*\n")
signature = str(inspect.signature(databricks_cli.sdk.ApiClient))
signature = "(\n " + ",\n ".join(signature[1:-1].split(", ")) + "\n )"
middle = """
To instantiate the client, provide the databricks host and either a token or
user and password. Also shown is the full signature of the
underlying ``ApiClient.__init__``
.. code-block:: python
from databricks_api import DatabricksAPI
# Provide a host and token
db = DatabricksAPI(
host="example.cloud.databricks.com",
token="dpapi123..."
)
# OR a host and user and password
db = DatabricksAPI(
host="example.cloud.databricks.com",
user="[email protected]",
password="password"
)
# Full __init__ signature
{instantiate}
Refer to the `official documentation <https://docs.databricks.com/api/index.html>`_
on the functionality and required arguments of each method below.
Each of the service instance attributes provides the following public methods:
""".format(
instantiate="db = DatabricksAPI" + signature
)
services = []
for k, v in db.__dict__.items():
if k == "client":
continue
print(k, v)
h = "DatabricksAPI." + k
services.append(h + "\n")
services.append("-" * len(h) + "\n\n")
services.append(".. code-block:: python\n\n")
methods = inspect.getmembers(v, predicate=inspect.ismethod)
print(methods)
for method in methods:
print(method)
if not method[0].startswith("_"):
signature = str(inspect.signature(method[1]))
if "," in signature:
signature = "(\n " + ",\n ".join(signature[1:-1].split(", ")) + ",\n )"
services.append(" db." + k + "." + method[0] + signature + "\n\n")
services.append("\n")
with open("README.rst", "w") as f:
f.write(intro)
for a in attrs:
f.write(a)
f.write(middle)
for s in services:
f.write(s)