Skip to content

Commit ab7cac6

Browse files
authored
Generate docs using sphinx (#820)
* Use sphinx to generate docs * Remove generated docs * Ignore some files in git * Switch them, remove version * Cleanup conf * Fix CI and nav * Add cache, fix version pattern * Tweak readme
1 parent 81d3bd6 commit ab7cac6

File tree

1,107 files changed

+130
-41125
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,107 files changed

+130
-41125
lines changed

.github/workflows/docs.yml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,22 @@ jobs:
2929
- name: Install tox
3030
run: pip install tox
3131

32+
- name: Cache sphinx
33+
uses: actions/cache@v2
34+
with:
35+
path: site
36+
key: sphinx
37+
3238
- name: Build documentation
33-
run: tox -e docs build
39+
run: tox -e docs
40+
41+
- name: Compress site
42+
run: tar czf site.tar.gz site
3443

3544
- uses: actions/upload-artifact@v2
3645
with:
3746
name: documentation
38-
path: site
47+
path: site.tar.gz
3948

4049
publish:
4150
runs-on: ubuntu-latest
@@ -48,7 +57,10 @@ jobs:
4857
- uses: actions/download-artifact@v2
4958
with:
5059
name: documentation
51-
path: site
60+
path: site.tar.gz
61+
62+
- name: Uncompress site
63+
run: tar xzf site.tar.gz
5264

5365
- uses: peaceiris/actions-gh-pages@v3
5466
with:

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
.env
2-
examples/
32
src/datadog_api_client/version.py
43
.generator/lib
4+
docs/datadog_api_client*.rst
5+
examples/generated
6+
site
57

68
# VSCode
79
.vscode

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ repos:
1212
stages: [manual]
1313
language: node
1414
language_version: 14.12.0
15-
entry: prettier --write --list-different --ignore-unknown docs
15+
entry: prettier --write --list-different --ignore-unknown README.md
1616
"types": [text]
17-
files: '^docs/'
17+
files: 'README.md'
1818
pass_filenames: false
1919
additional_dependencies:
2020
# When updating the version of prettier, make sure to check the pre-commit file

Makefile

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
.PHONY: all
22
all: .generator .env
33
@pre-commit run --all-files --hook-stage=manual openapi-generator || true
4-
@mkdir -p docs/v1 docs/v2
54
@cp -r v1/datadog_api_client ./src/
65
@cp -r v2/datadog_api_client ./src/
7-
@cp -r v1/docs/* ./docs/v1/
8-
@cp -r v2/docs/* ./docs/v2/
9-
@cp v1/README.md ./docs/v1/
10-
@cp v2/README.md ./docs/v2/
6+
@ls v1/docs/*Api.md | xargs -n1 ./extract-code-blocks.awk -v output="examples/generated/v1"
7+
@ls v2/docs/*Api.md | xargs -n1 ./extract-code-blocks.awk -v output="examples/generated/v2"
118
@rm -rf v1 v2
129
@pre-commit run --all-files --hook-stage=manual docs || echo "modified files"
1310
@pre-commit run --all-files --hook-stage=manual autoflake || echo "modified files"

README.md

Lines changed: 18 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -21,54 +21,25 @@ pip install datadog-api-client
2121
Please follow the [installation](#installation) instruction and execute the following Python code:
2222

2323
```python
24-
import os
25-
from dateutil.parser import parse as dateutil_parser
26-
import datadog_api_client.v1
27-
from datadog_api_client.v1.api import aws_integration_api
28-
from datadog_api_client.v1.models import *
29-
from pprint import pprint
30-
31-
# Defining the host is optional and defaults to https://api.datadoghq.com
32-
# See configuration.py for a list of all supported configuration parameters.
33-
configuration = datadog_api_client.v1.Configuration(
34-
host = "https://api.datadoghq.com"
24+
from datadog_api_client.v1 import ApiClient, Configuration
25+
from datadog_api_client.v1.api.monitors_api import MonitorsApi
26+
from datadog_api_client.v1.model.monitor import Monitor
27+
from datadog_api_client.v1.model.monitor_type import MonitorType
28+
29+
body = Monitor(
30+
name="example",
31+
type=MonitorType("log alert"),
32+
query='logs("service:foo AND type:error").index("main").rollup("count").by("source").last("5m") > 2',
33+
message="some message Notify: @hipchat-channel",
34+
tags=["test:example", "env:ci"],
35+
priority=3,
3536
)
3637

37-
# The client must configure the authentication and authorization parameters
38-
# in accordance with the API server security policy.
39-
# Examples for each auth method are provided below, use the example that
40-
# satisfies your auth use case.
41-
42-
# Configure API key authorization: apiKeyAuth
43-
configuration.api_key['apiKeyAuth'] = os.getenv('DD_CLIENT_API_KEY')
44-
45-
# Configure API key authorization: appKeyAuth
46-
configuration.api_key['appKeyAuth'] = os.getenv('DD_CLIENT_APP_KEY')
47-
48-
# Enter a context with an instance of the API client
49-
with datadog_api_client.v1.ApiClient(configuration) as api_client:
50-
# Create an instance of the API class
51-
api_instance = aws_integration_api.AWSIntegrationApi(api_client)
52-
body = AWSAccount(
53-
access_key_id="access_key_id_example",
54-
account_id="1234567",
55-
account_specific_namespace_rules={
56-
"key": True,
57-
},
58-
excluded_regions=["us-east-1","us-west-2"],
59-
filter_tags=["<KEY>:<VALUE>"],
60-
host_tags=["<KEY>:<VALUE>"],
61-
role_name="DatadogAWSIntegrationRole",
62-
secret_access_key="secret_access_key_example",
63-
) # AWSAccount | AWS Request Object
64-
65-
# example passing only required values which don't have defaults set
66-
try:
67-
# Create an AWS integration
68-
api_response = api_instance.create_aws_account(body)
69-
pprint(api_response)
70-
except datadog_api_client.v1.ApiException as e:
71-
print("Exception when calling AWSIntegrationApi->create_aws_account: %s\n" % e)
38+
configuration = Configuration()
39+
with ApiClient(configuration) as api_client:
40+
api_instance = MonitorsApi(api_client)
41+
response = api_instance.create_monitor(body=body)
42+
print(response)
7243
```
7344

7445
### Unstable Endpoints
@@ -113,7 +84,6 @@ the API methods will then return coroutines that you can wait for.
11384

11485
To make async support available, you need to install the extra `async` qualifiers during installation: `pip install datadog-api-client[async]`.
11586

116-
11787
```python
11888
import asyncio
11989

@@ -132,9 +102,7 @@ asyncio.run(main())
132102

133103
## Documentation for API Endpoints and Models
134104

135-
Documentation for API endpoints and models can be found under the docs subdirectories, in [v1](/docs/v1#documentation-for-api-endpoints) and [v2](/docs/v2#documentation-for-api-endpoints).
136-
137-
It's also available on [readthedocs](https://datadog-api-client.readthedocs.io/).
105+
Documentation for API endpoints and models are available on [readthedocs](https://datadog-api-client.readthedocs.io/).
138106

139107
## Documentation for Authorization
140108

@@ -148,4 +116,3 @@ configuration.api_key["appKeyAuth"] = "YOUR_APPLICATION_KEY"
148116
## Author
149117

150118
151-

docs/README.md

Lines changed: 0 additions & 149 deletions
This file was deleted.

docs/conf.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# -- Path setup --------------------------------------------------------------
2+
3+
# If extensions (or modules to document with autodoc) are in another directory,
4+
# add these directories to sys.path here. If the directory is relative to the
5+
# documentation root, use os.path.abspath to make it absolute, like shown here.
6+
#
7+
import os
8+
import sys
9+
10+
sys.path.insert(0, os.path.abspath("../src"))
11+
12+
13+
# -- Project information -----------------------------------------------------
14+
15+
project = "Datadog API Client for Python"
16+
copyright = "2022, Datadog"
17+
author = "Datadog"
18+
19+
# -- General configuration ---------------------------------------------------
20+
21+
# Add any Sphinx extension module names here, as strings. They can be
22+
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
23+
# ones.
24+
extensions = ["m2r2", "sphinx.ext.autodoc"]
25+
26+
# Add any paths that contain templates here, relative to this directory.
27+
templates_path = ["_templates"]
28+
29+
# List of patterns, relative to source directory, that match files and
30+
# directories to ignore when looking for source files.
31+
# This pattern also affects html_static_path and html_extra_path.
32+
exclude_patterns = []
33+
34+
35+
# -- Options for HTML output -------------------------------------------------
36+
37+
# The theme to use for HTML and HTML Help pages. See the documentation for
38+
# a list of builtin themes.
39+
#
40+
html_theme = "sphinx_material"
41+
42+
html_logo = "assets/images/logo.svg"
43+
html_favicon = "assets/images/favicon.ico"
44+
45+
# Add any paths that contain custom static files (such as style sheets) here,
46+
# relative to this directory. They are copied after the builtin static files,
47+
# so a file named "default.css" will overwrite the builtin "default.css".
48+
html_static_path = ["assets"]
49+
50+
html_sidebars = {
51+
"**": ["globaltoc.html", "localtoc.html", "searchbox.html"]
52+
}
53+
54+
html_theme_options = {
55+
# Set the name of the project to appear in the navigation.
56+
"nav_title": "Datadog API Client for Python",
57+
# Set the color and the accent color
58+
"color_primary": "deep-purple",
59+
"color_accent": "deep-purple",
60+
# Set the repo location to get a badge with stats
61+
"repo_url": "https://github.com/DataDog/datadog-api-client-python/",
62+
"repo_name": "datadog-api-client-python",
63+
# Visible levels of the global TOC; -1 means unlimited
64+
"globaltoc_depth": 3,
65+
# If False, expand all TOC entries
66+
"globaltoc_collapse": False,
67+
# If True, show hidden TOC entries
68+
"globaltoc_includehidden": False,
69+
}

0 commit comments

Comments
 (0)