Skip to content

Commit efa45da

Browse files
radeksmDaniel P. Berrangé
authored andcommitted
docs: publish libvirt-python API docs via GitLab pages
Add jobs: - website_job - pages to build libvirt-python API docs using Sphinx. Created base on libvirt-php/libvirt-java/libvirt-ruby examples. Signed-off-by: Radoslaw Smigielski <rsmigiel@redhat.com>
1 parent 0e546ce commit efa45da

2 files changed

Lines changed: 80 additions & 1 deletion

File tree

.gitlab-ci.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ stages:
33
- containers
44
- builds
55
- sanity_checks
6+
- pages
67

78
.git_build_vars: &git_build_vars |
89
export MAKEFLAGS="-j$(getconf _NPROCESSORS_ONLN)"
@@ -57,6 +58,49 @@ stages:
5758

5859
include: '/ci/gitlab.yml'
5960

61+
# Build Sphinx HTML API docs.
62+
py_api_docs:
63+
extends:
64+
- .gitlab_native_build_job
65+
needs:
66+
- job: x86_64-fedora-44-container
67+
optional: true
68+
script:
69+
- export MAKEFLAGS="-j$(getconf _NPROCESSORS_ONLN)"
70+
- export CFLAGS="-Werror"
71+
- $PYTHON -m build -n -x
72+
- $PYTHON -m venv docs-venv --system-site-packages --symlinks
73+
- docs-venv/bin/python -m pip install dist/libvirt_python*.whl
74+
- docs-venv/bin/python -m pip install -r requirements-docs.txt
75+
- docs-venv/bin/sphinx-build -b html docs/ py_api_docs
76+
artifacts:
77+
expose_as: 'py_api_docs'
78+
name: 'py_api_docs'
79+
when: on_success
80+
expire_in: 30 days
81+
paths:
82+
- py_api_docs
83+
variables:
84+
NAME: fedora-44
85+
TARGET_BASE_IMAGE: registry.fedoraproject.org/fedora:44
86+
87+
# Publish "py_api_docs" output via GitLab Pages
88+
pages:
89+
stage: pages
90+
script:
91+
- mv py_api_docs public
92+
dependencies:
93+
- py_api_docs
94+
rules:
95+
- if: '$CI_PROJECT_NAMESPACE == $RUN_UPSTREAM_NAMESPACE && $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
96+
when: on_success
97+
- when: never
98+
artifacts:
99+
expose_as: 'pages'
100+
name: 'pages'
101+
paths:
102+
- public
103+
60104
api_coverage_job:
61105
extends:
62106
- .gitlab_native_build_job

docs/conf.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,41 @@
2828

2929
html_theme = 'alabaster'
3030
html_theme_options = {
31-
'description': 'Python bindings for the libvirt virtualization API',
31+
'description': 'Python bindings for the libvirt API',
3232
'github_button': False,
3333
}
34+
35+
36+
def _needs_literal_docstring(lines):
37+
"""Here comes a little bit of magic.
38+
This function returns True if docstring content is unsafe as reStructuredText,
39+
it will tell Sphinx to use the docstring as is, without any formatting.
40+
41+
Docs from C API descriptions are not always valid reStructuredText,
42+
these are valid for Python help() but are not docutils.
43+
"""
44+
in_field = False
45+
for line in lines:
46+
if line.startswith(':'):
47+
in_field = True
48+
continue
49+
if in_field:
50+
stripped = line.lstrip()
51+
if stripped.startswith(('-', '*')) and line[:1].isspace():
52+
return True
53+
if line and not line[0].isspace() and not line.startswith(':'):
54+
in_field = False
55+
if line.startswith((' ', '\t')):
56+
return True
57+
return False
58+
59+
60+
def process_docstring(app, what, name, obj, options, lines):
61+
if not lines or not _needs_literal_docstring(lines):
62+
return
63+
body = list(lines)
64+
lines[:] = ['::', ''] + [(' ' + line if line else '') for line in body]
65+
66+
67+
def setup(app):
68+
app.connect('autodoc-process-docstring', process_docstring)

0 commit comments

Comments
 (0)