Skip to content

Commit d2757a1

Browse files
author
Sam Kleinman
committed
config: extracting site specific configuration from conf.py to support primer
1 parent 4238d8b commit d2757a1

File tree

3 files changed

+170
-41
lines changed

3 files changed

+170
-41
lines changed

conf.py

Lines changed: 48 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import os
1010
import datetime
1111

12+
from sphinx.errors import SphinxError
13+
1214
try:
1315
project_root = os.path.join(os.path.abspath(os.path.dirname(__file__)))
1416
except NameError:
@@ -21,14 +23,17 @@
2123
sys.path.append(os.path.join(project_root, buildsystem, 'sphinxext'))
2224
sys.path.append(os.path.join(project_root, buildsystem, 'bin'))
2325

24-
from utils import ingest_yaml, ingest_yaml_list
25-
from docs_meta import get_conf, get_versions, get_manual_path
26+
from utils.config import get_conf
27+
from utils.project import get_versions, get_manual_path
28+
from utils.serialization import ingest_yaml, ingest_yaml_list
29+
from utils.structures import BuildConfiguration
30+
from utils.strings import dot_concat
2631

2732
conf = get_conf()
2833

2934
conf.paths.projectroot = project_root
30-
pdfs = ingest_yaml_list(os.path.join(conf.paths.builddata, 'pdfs.yaml'))
3135
intersphinx_libs = ingest_yaml_list(os.path.join(conf.paths.builddata, 'intersphinx.yaml'))
36+
sconf = BuildConfiguration(os.path.join(conf.paths.builddata, 'sphinx-local.yaml'))
3237

3338
# -- General configuration ----------------------------------------------------
3439

@@ -50,9 +55,9 @@
5055

5156
source_suffix = '.txt'
5257

53-
master_doc = 'contents'
58+
master_doc = sconf.master_doc
5459
language = 'en'
55-
project = u'mongodb-manual'
60+
project = sconf.project
5661
copyright = u'2011-' + str(datetime.date.today().year) + ', MongoDB, Inc.'
5762
version = conf.version.branch
5863
release = conf.version.release
@@ -72,8 +77,8 @@
7277
'wiki': ('http://www.mongodb.org/display/DOCS/%s', ''),
7378
'api': ('http://api.mongodb.org/%s', ''),
7479
'source': ('https://github.com/mongodb/mongo/blob/master/%s', ''),
75-
'docsgithub' : ( 'http://github.com/mongodb/docs/blob/' + conf.git.branches.current + '/%s', ''),
76-
'hardlink' : ( 'http://docs.mongodb.org/' + conf.git.branches.current + '/%s', ''),
80+
'docsgithub' : ( 'http://github.com/mongodb/docs/blob/{0}/%s'.format(conf.git.branches.current), ''),
81+
'hardlink' : ( 'http://docs.mongodb.org/{0}/%s'.format(conf.git.branches.current), ''),
7782
'manual': ('http://docs.mongodb.org/manual%s', ''),
7883
'ecosystem': ('http://docs.mongodb.org/ecosystem%s', ''),
7984
'meta-driver': ('http://docs.mongodb.org/meta-driver/latest%s', ''),
@@ -84,7 +89,7 @@
8489

8590
## add `extlinks` for each published version.
8691
for i in conf.git.branches.published:
87-
extlinks[i] = ( conf.project.url + '/' + i + '%s', '')
92+
extlinks[i] = ( ''.join([ conf.project.url, '/', i, '%s' ]), '' )
8893

8994
intersphinx_mapping = {}
9095
for i in intersphinx_libs:
@@ -115,13 +120,13 @@
115120

116121
# -- Options for HTML output ---------------------------------------------------
117122

118-
html_theme = 'manual'
123+
html_theme = sconf.theme.name
119124
html_theme_path = [ os.path.join(buildsystem, 'themes') ]
120125
html_title = conf.project.title
121126
htmlhelp_basename = 'MongoDBdoc'
122127

123-
html_logo = ".static/logo-mongodb.png"
124-
html_static_path = ['source/.static']
128+
html_logo = sconf.logo
129+
html_static_path = sconf.paths.static
125130

126131
html_copy_source = False
127132
html_use_smartypants = True
@@ -132,31 +137,39 @@
132137
html_show_sphinx = True
133138
html_show_copyright = True
134139

135-
manual_edition_path = '{0}/{1}/MongoDB-manual'.format(conf.project.url, conf.git.branches.current)
140+
manual_edition_path = '{0}/{1}/{2}'.format(conf.project.url,
141+
conf.git.branches.current,
142+
sconf.theme.book_path_base)
136143

137144
html_theme_options = {
138145
'branch': conf.git.branches.current,
139-
'pdfpath': manual_edition_path + '.pdf',
140-
'epubpath': manual_edition_path + '.epub',
146+
'pdfpath': dot_concat(manual_edition_path, 'pdf'),
147+
'epubpath': dot_concat(manual_edition_path, 'epub'),
141148
'manual_path': get_manual_path(conf),
142149
'translations': languages,
143150
'language': language,
144-
'repo_name': 'docs',
145-
'jira_project': 'DOCS',
146-
'google_analytics': 'UA-7301842-8',
147-
'project': 'manual',
151+
'repo_name': sconf.theme.repo,
152+
'jira_project': sconf.theme.jira,
153+
'google_analytics': sconf.theme.google_analytics,
154+
'project': sconf.theme.project,
148155
'version': version,
149156
'version_selector': get_versions(conf),
150157
'stable': conf.version.stable,
151158
}
152159

153-
html_sidebars = {
154-
'**': ['pagenav.html'],
155-
}
156-
html_sidebars['**'].append('formats.html')
160+
html_sidebars = sconf.sidebars
157161

158162
# -- Options for LaTeX output --------------------------------------------------
159163

164+
if tags.has('latex'):
165+
pdf_conf_path = os.path.join(conf.paths.builddata, 'pdfs.yaml')
166+
if os.path.exists(pdf_conf_path):
167+
pdfs = ingest_yaml_list(pdf_conf_path)
168+
else:
169+
raise SphinxError('[WARNING]: skipping pdf builds because of missing {0} file'.format(pdf_conf_path))
170+
else:
171+
pdfs = []
172+
160173
latex_documents = []
161174
for pdf in pdfs:
162175
_latex_document = ( pdf['source'], pdf['output'], pdf['title'], pdf['author'], pdf['class'])
@@ -184,24 +197,18 @@
184197

185198
# -- Options for manual page output --------------------------------------------
186199

187-
man_pages = [
188-
# (source start file, name, description, authors, manual section).
189-
('reference/program/bsondump', 'bsondump', u'MongoDB BSON utility', [u'MongoDB Documentation Project'], 1),
190-
('reference/program/mongo', 'mongo', u'MongoDB Shell', [u'MongoDB Documentation Project'], 1),
191-
('reference/program/mongod', 'mongod', u'MongoDB Server', [u'MongoDB Documentation Project'], 1),
192-
('reference/program/mongos', 'mongos', u'MongoDB Shard Utility', [u'MongoDB Documentation Project'], 1),
193-
('reference/program/mongodump', 'mongodump', u'MongoDB', [u'MongoDB Documentation Project'], 1),
194-
('reference/program/mongoexport', 'mongoexport', u'MongoDB', [u'MongoDB Documentation Project'], 1),
195-
('reference/program/mongofiles', 'mongofiles', u'MongoDB', [u'MongoDB Documentation Project'], 1),
196-
('reference/program/mongoimport', 'mongoimport', u'MongoDB', [u'MongoDB Documentation Project'], 1),
197-
('reference/program/mongooplog', 'mongooplog', u'MongoDB', [u'MongoDB Documentation Project'], 1),
198-
('reference/program/mongorestore', 'mongorestore', u'MongoDB', [u'MongoDB Documentation Project'], 1),
199-
('reference/program/mongostat', 'mongostat', u'MongoDB', [u'MongoDB Documentation Project'], 1),
200-
('reference/program/mongosniff', 'mongosniff', u'MongoDB', [u'MongoDB Documentation Project'], 1),
201-
('reference/program/mongotop', 'mongotop', u'MongoDB', [u'MongoDB Documentation Project'], 1),
202-
('reference/program/mongoperf', 'mongoperf', u'MongoDB', [u'MongoDB Documentation Project'], 1),
203-
('reference/parameters', 'mongodb-parameters', u'MongoDB Parameters', [u'MongoDB Documentation Project'], 5),
204-
]
200+
if tags.has('man'):
201+
man_page_conf_path = os.path.join(conf.paths.builddata, 'manpages.yaml')
202+
if os.path.exists(man_page_conf_path):
203+
man_page_definitions = ingest_yaml_list(man_page_conf_path)
204+
else:
205+
raise SphinxError('[WARNING]: skipping man builds because of missing {0} file'.format(man_page_conf_path))
206+
else:
207+
man_page_definitions = []
208+
209+
man_pages = []
210+
for mp in man_page_definitions:
211+
man_pages.append((mp['file'], mp['name'], mp['title'], mp['authors'], mp['section']))
205212

206213
# -- Options for Epub output ---------------------------------------------------
207214

@@ -215,7 +222,7 @@
215222
epub_tocdepth = 3
216223
epub_language = language
217224
epub_scheme = 'url'
218-
epub_identifier = conf.project.url + '/' + conf.git.branches.current
225+
epub_identifier = ''.join([conf.project.url, '/', conf.git.branches.current])
219226
epub_exclude_files = []
220227

221228
epub_pre_files = []

config/manpages.yaml

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
file: reference/program/bsondump
2+
name: bsondump
3+
title: MongoDB BSON Utility
4+
authors:
5+
- MongoDB Documentation Project
6+
section: 1
7+
---
8+
file: reference/program/mongo
9+
name: mongo
10+
title: MongoDB Shell
11+
authors:
12+
- MongoDB Documentation Project
13+
section: 1
14+
---
15+
file: reference/program/mongod
16+
name: mongod
17+
title: MongoDB Server
18+
authors:
19+
- MongoDB Documentation Project
20+
section: 1
21+
---
22+
file: reference/program/mongos
23+
name: mongos
24+
title: MongoDB Sharded Cluster Query Router
25+
authors:
26+
- MongoDB Documentation Project
27+
section: 1
28+
---
29+
file: reference/program/mongodump
30+
name: mongodump
31+
title: MongoDB Data Dump Utility
32+
authors:
33+
- MongoDB Documentation Project
34+
section: 1
35+
---
36+
file: reference/program/mongoexport
37+
name: mongoexport
38+
title: MongoDB Export Utility
39+
authors:
40+
- MongoDB Documentation Project
41+
section: 1
42+
---
43+
file: reference/program/mongofiles
44+
name: mongofiles
45+
title: MongoDB GridFS Utility
46+
authors:
47+
- MongoDB Documentation Project
48+
section: 1
49+
---
50+
file: reference/program/mongoimport
51+
name: mongoimport
52+
title: MongoDB Import Utility
53+
authors:
54+
- MongoDB Documentation Project
55+
section: 1
56+
---
57+
file: reference/program/mongooplog
58+
name: mongooplog
59+
title: MongoDB Oplog Utility
60+
authors:
61+
- MongoDB Documentation Project
62+
section: 1
63+
---
64+
file: reference/program/mongorestore
65+
name: mongorestore
66+
title: MongoDB Data Restoration Tool
67+
authors:
68+
- MongoDB Documentation Project
69+
section: 1
70+
---
71+
file: reference/program/mongostat
72+
name: mongostat
73+
title: MongoDB Use Statistics
74+
authors:
75+
- MongoDB Documentation Project
76+
section: 1
77+
---
78+
file: reference/program/mongosniff
79+
name: mongosniff
80+
title: MongoDB Protocol Introspection Utility
81+
authors:
82+
- MongoDB Documentation Project
83+
section: 1
84+
---
85+
file: reference/program/mongotop
86+
name: mongotop
87+
title: MongoDB Activity Monitor
88+
authors:
89+
- MongoDB Documentation Project
90+
section: 1
91+
---
92+
file: reference/program/mongoperf
93+
name: mongoperf
94+
title: MongoDB Performance Utility
95+
authors:
96+
- MongoDB Documentation Project
97+
section: 1
98+
---
99+
file: reference/parameters
100+
name: mongodb-parameters
101+
title: MongoDB setParameter Options
102+
authors:
103+
- MongoDB Documentation Project
104+
section: 5
105+
...

config/sphinx-local.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
project: 'mongodb-manual'
2+
master_doc: 'contents'
3+
logo: ".static/logo-mongodb.png"
4+
paths:
5+
static: ['source/.static']
6+
theme:
7+
name: 'manual'
8+
project: 'manual'
9+
google_analytics: 'UA-7301842-8'
10+
book_path_base: 'MongoDB-manual'
11+
repo: 'docs'
12+
jira: 'DOCS'
13+
sidebars:
14+
'**':
15+
- 'pagenav.html'
16+
- 'formats.html'
17+
...

0 commit comments

Comments
 (0)