-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconf.py
134 lines (116 loc) · 4.45 KB
/
conf.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
122
123
124
125
126
127
128
129
130
131
132
133
134
# -*- coding: utf-8 -*-
import os
from os.path import join, dirname
import sys
import glob
import shutil
import urllib
import fnmatch
from datetime import datetime
from subprocess import call, Popen, PIPE
try:
import simplejson as json
except ImportError:
import json
class Context(dict):
def __init__(self, globs, locs):
super(Context, self).__init__()
self.globals = globs
self.locals = locs
def update(self, e=None, **f):
if e is None:
e = {}
super(Context, self).update(e, **f)
if 'subprojects' in e:
substitutions = \
'\n'.join('.. |%s| replace:: %s' % sp
for sp in e['subprojects'])
self.locals['rst_prolog'] = \
self.locals.get('rst_prolog', '') + '\n' + substitutions
def prepare(globs, locs):
# travis.sh sets the current working directory
# to <root>/docs/src/ before running sphinx-build.
cwd = os.getcwd()
root = os.path.abspath(join(cwd, '..', '..'))
builder = sys.argv[sys.argv.index('-b') + 1]
os.chdir(root)
git = Popen('which git 2> %s' % os.devnull, shell=True,
stdout=PIPE).stdout.read().strip()
doxygen = Popen('which doxygen 2> %s' % os.devnull, shell=True,
stdout=PIPE).stdout.read().strip()
# Retrieve several values from git
origin = Popen([git, 'config', '--local', 'remote.origin.url'],
stdout=PIPE).stdout.read().strip()
git_tag = Popen([git, 'describe', '--tags', '--exact', '--first-parent'],
stdout=PIPE).communicate()[0].strip()
git_hash = Popen([git, 'rev-parse', 'HEAD'],
stdout=PIPE).communicate()[0].strip()
git_default = Popen([git, 'symbolic-ref', '--short', 'refs/remotes/origin/HEAD'],
stdout=PIPE).communicate()[0].strip()
origin = origin.replace(':', '/').split('/')
vendor = origin[-2]
project = origin[-1]
default_branch = git_default.split('/', 1)[-1]
if project.endswith('.git'):
project = project[:-4]
os.environ['SPHINX_PROJECT'] = project
os.environ['SPHINX_PROJECT_SLUG'] = ("%s/%s" % (vendor, project)).lower()
os.environ['SPHINX_DEFAULT_BRANCH'] = default_branch
if git_tag:
os.environ['SPHINX_VERSION'] = git_tag
os.environ['SPHINX_RELEASE'] = git_tag
else:
commit = Popen([git, 'describe', '--always', '--first-parent'],
stdout=PIPE).communicate()[0].strip()
os.environ['SPHINX_VERSION'] = 'latest'
os.environ['SPHINX_RELEASE'] = 'latest-%s' % (commit, )
locs['tags'].add('devel')
if builder == 'html':
# Run doxygen
composer = json.load(open(join(root, 'composer.json'), 'r'))
call([doxygen, join(root, 'Doxyfile')], env={
'COMPONENT_NAME': os.environ['SPHINX_PROJECT'],
'COMPONENT_VERSION': os.environ['SPHINX_VERSION'],
'COMPONENT_BRIEF': composer.get('description', ''),
})
# Copy API doc to final place,
# overwriting files as necessary.
try:
shutil.rmtree(join(root, 'build'))
except OSError:
pass
os.mkdir(join(root, 'build'))
shutil.move(
join(root, 'docs', 'api', 'html'),
join(root, 'build', 'apidoc'),
)
try:
shutil.move(
join(root, '%s.tagfile.xml' %
os.environ['SPHINX_PROJECT']),
join(root, 'build', 'apidoc', '%s.tagfile.xml' %
os.environ['SPHINX_PROJECT'])
)
except OSError:
pass
# Load the real Sphinx configuration file.
os.chdir(cwd)
real_conf = join(root, 'docs', 'src', 'real_conf.py')
print "Including real configuration file (%s)..." % (real_conf, )
execfile(real_conf, globs, locs)
# Patch configuration afterwards.
# - Additional files (API doc)
locs.setdefault('html_extra_path', []).append(join(root, 'build'))
# - I18N
locs.setdefault('locale_dirs', []).insert(0, join(root, 'docs', 'i18n'))
# - misc.
locs['rst_prolog'] = locs.get('rst_prolog', '') + \
'\n .. _`this_commit`: https://github.com/%s/%s/commit/%s\n' % (
vendor,
project,
git_hash,
)
old_html_context = globals().get('html_context', {})
html_context = Context(globals(), locals())
html_context.update(old_html_context)
prepare(globals(), locals())