| 1 |
# Copyright 2014 OpenStack Foundation |
| 2 |
# |
| 3 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 |
# not use this file except in compliance with the License. You may obtain |
| 5 |
# a copy of the License at |
| 6 |
# |
| 7 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
# |
| 9 |
# Unless required by applicable law or agreed to in writing, software |
| 10 |
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 |
# License for the specific language governing permissions and limitations |
| 13 |
# under the License. |
| 14 |
|
| 15 |
import os.path as path |
| 16 |
|
| 17 |
from sphinx import apidoc |
| 18 |
|
| 19 |
|
| 20 |
# NOTE(blk-u): pbr will run Sphinx multiple times when it generates |
| 21 |
# documentation. Once for each builder. To run this extension we use the |
| 22 |
# 'builder-inited' hook that fires at the beginning of a Sphinx build. |
| 23 |
# We use ``run_already`` to make sure apidocs are only generated once |
| 24 |
# even if Sphinx is run multiple times. |
| 25 |
run_already = False |
| 26 |
|
| 27 |
|
| 28 |
def run_apidoc(app): |
| 29 |
global run_already |
| 30 |
if run_already: |
| 31 |
return |
| 32 |
run_already = True |
| 33 |
|
| 34 |
package_dir = path.abspath(path.join(app.srcdir, '..', '..', 'osc_lib')) |
| 35 |
source_dir = path.join(app.srcdir, 'api') |
| 36 |
apidoc.main( |
| 37 |
[ |
| 38 |
'apidoc', |
| 39 |
package_dir, |
| 40 |
'-f', |
| 41 |
'-H', |
| 42 |
'osc-lib Modules', |
| 43 |
'-o', |
| 44 |
source_dir, |
| 45 |
] |
| 46 |
) |
| 47 |
|
| 48 |
|
| 49 |
def setup(app): |
| 50 |
app.connect('builder-inited', run_apidoc) |