Skip to content

Commit 0788842

Browse files
Balandatfacebook-github-bot
authored andcommitted
Parse sphinx output for source code and move to website
Summary: Pull Request resolved: #135 Reviewed By: danielrjiang Differential Revision: D15155168 Pulled By: Balandat fbshipit-source-id: 75c1c452ff35c9cf9f6fc9ba8229ee40d7c4c78a
1 parent ba07fa4 commit 0788842

File tree

2 files changed

+28
-26
lines changed

2 files changed

+28
-26
lines changed

scripts/parse_sphinx.py

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,31 @@
2525

2626

2727
def parse_sphinx(input_dir, output_dir):
28-
for fname in os.listdir(input_dir):
29-
if fname.endswith(".html"):
30-
with open(input_dir + fname, "r") as f:
31-
soup = BeautifulSoup(f.read(), "html.parser")
32-
doc = soup.find("div", {"class": "document"})
33-
wrapped_doc = doc.wrap(soup.new_tag("div", **{"class": "sphinx"}))
34-
# add js
35-
if fname == "search.html":
36-
out = js_scripts + search_js_scripts + str(wrapped_doc)
37-
else:
38-
out = js_scripts + str(wrapped_doc)
39-
with open(output_dir + fname, "w") as fout:
40-
fout.write(out)
28+
for cur, _, files in os.walk(input_dir):
29+
for fname in files:
30+
if fname.endswith(".html"):
31+
with open(os.path.join(cur, fname), "r") as f:
32+
soup = BeautifulSoup(f.read(), "html.parser")
33+
doc = soup.find("div", {"class": "document"})
34+
wrapped_doc = doc.wrap(soup.new_tag("div", **{"class": "sphinx"}))
35+
# add js
36+
if fname == "search.html":
37+
out = js_scripts + search_js_scripts + str(wrapped_doc)
38+
else:
39+
out = js_scripts + str(wrapped_doc)
40+
output_path = os.path.join(output_dir, os.path.relpath(cur, input_dir))
41+
os.makedirs(output_path, exist_ok=True)
42+
with open(os.path.join(output_path, fname), "w") as fout:
43+
fout.write(out)
4144

42-
# update reference in JS file
43-
with open(input_dir + "_static/searchtools.js", "r") as js_file:
44-
js = js_file.read()
45-
js = js.replace(
46-
"DOCUMENTATION_OPTIONS.URL_ROOT + '_sources/'", "'_sphinx-sources/'"
47-
)
48-
with open(input_dir + "_static/searchtools.js", "w") as js_file:
49-
js_file.write(js)
45+
# update reference in JS file
46+
with open(os.path.join(input_dir, "_static/searchtools.js"), "r") as js_file:
47+
js = js_file.read()
48+
js = js.replace(
49+
"DOCUMENTATION_OPTIONS.URL_ROOT + '_sources/'", "'_sphinx-sources/'"
50+
)
51+
with open(os.path.join(input_dir, "_static/searchtools.js"), "w") as js_file:
52+
js_file.write(js)
5053

5154

5255
if __name__ == "__main__":

sphinx/source/conf.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@
8888
# Theme options are theme-specific and customize the look and feel of a theme
8989
# further. For a list of options available for each theme, see the
9090
# documentation.
91-
#
92-
# html_theme_options = {}
91+
html_theme_options = {}
9392

9493
# Add any paths that contain custom static files (such as style sheets) here,
9594
# relative to this directory. They are copied after the builtin static files,
@@ -141,7 +140,7 @@
141140
# (source start file, target name, title,
142141
# author, documentclass [howto, manual, or own class]).
143142
latex_documents = [
144-
(master_doc, "botorch.tex", "botorch Documentation", "Facebook, Inc.", "manual")
143+
(master_doc, "botorch.tex", "BoTorch Documentation", "Facebook, Inc.", "manual")
145144
]
146145

147146

@@ -161,9 +160,9 @@
161160
(
162161
master_doc,
163162
"botorch",
164-
"botorch Documentation",
163+
"BoTorch Documentation",
165164
author,
166-
"botorch",
165+
"BoTorch",
167166
"Bayesian Optimization in PyTorch.",
168167
"Miscellaneous",
169168
)

0 commit comments

Comments
 (0)