Skip to content

Commit 060957e

Browse files
authored
Allow sphinx building of docs (#64)
* Allow sphinx building of docs The primary mechanism will be the `docs/` folder and associated tensorflow-like build system. However, for the interim we'll support building with sphinx since there's little overhead. In particular, sphinx will copy files from `docs/` to `dev_tools/docs/sphinx`. This PR also makes the following changes: - change copyright notice to bold from `<h6>`. `nbsphinx` was getting confused. - only install `recirq` in the notebook if it's not already installed. It's not nice to overwrite a user's environment! * Fix notebook dependency code * Intercept header at the source * conf.py imports to the top
1 parent dcdb97a commit 060957e

File tree

6 files changed

+49
-12
lines changed

6 files changed

+49
-12
lines changed

dev_tools/docs/sphinx/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
tutorials/
2+
_static/g3618.png
3+
_static/recirq_logo_notext.png

dev_tools/docs/sphinx/_static/custom.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,9 @@ div.body {
1111
div.document {
1212
width: 1220px;
1313
}
14+
15+
/* nbsphinx strips the HTML from these cells
16+
so they look bad */
17+
.tfo-notebook-buttons {
18+
display: none;
19+
}

dev_tools/docs/sphinx/conf.py

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
import os
15+
import re
1516
import shutil
17+
import subprocess
1618

1719
project = 'ReCirq'
1820
copyright = '2020, Google Quantum'
@@ -97,10 +99,11 @@ def env_before_read_docs(app, env, docnames):
9799
cirq-results/qaoa-p1-landscape/2020-03-tutorial
98100
99101
"""
102+
print("The following documents will be built:")
100103
print(docnames)
101104

102105
def _order(docname):
103-
if docname == 'Readout-Data-Collection':
106+
if docname == 'tutorials/data_collection':
104107
# must come before others
105108
return -1
106109

@@ -111,12 +114,14 @@ def _order(docname):
111114

112115
docnames.sort(key=_order)
113116

117+
print("Since there are dependencies between them, they will be built in this order:")
114118
print(docnames)
115119

116-
if ('Readout-Data-Collection' in docnames
117-
and 'Readout-Analysis' not in docnames):
118-
# Mark the analysis notebook as changed
119-
docnames.append('Readout-Analysis')
120+
if ('tutorials/data_collection' in docnames
121+
and 'tutorials/data_analysis' not in docnames):
122+
print("Since tutorials/data_collection has changed, "
123+
"also re-running tutorials/data_analysis")
124+
docnames.append('tutorials/data_analysis')
120125

121126
if 'qaoa/Tasks-Tutorial' in docnames:
122127
if 'qaoa/Precomputed-Analysis' not in docnames:
@@ -128,7 +133,9 @@ def _order(docname):
128133

129134
print(docnames)
130135

131-
if 'Readout-Data-Collection' in docnames:
136+
if 'tutorials/data_collection' in docnames:
137+
print("Since tutorials/data_collection has changed, "
138+
"deleting existing tutorial data.")
132139
from recirq.readout_scan import tasks as rs_tasks
133140
_rmtree_if_exists(f'{rs_tasks.DEFAULT_BASE_DIR}/2020-02-tutorial')
134141

@@ -147,5 +154,22 @@ def _order(docname):
147154
_rmtree_if_exists(f'{qaoa_p1_tasks.DEFAULT_BASE_DIR}/2020-03-tutorial')
148155

149156

157+
158+
REPO_DIR = subprocess.Popen(['git', 'rev-parse', '--show-toplevel'],
159+
stdout=subprocess.PIPE).communicate()[0].rstrip().decode('utf-8')
160+
161+
162+
def source_read(app, docname, source):
163+
source[0] = re.sub(r'"##### (Copyright 20\d\d Google)"', r'"**\1**"', source[0])
164+
165+
150166
def setup(app):
167+
FROM = f'{REPO_DIR}/docs'
168+
TO = f'{REPO_DIR}/dev_tools/docs/sphinx'
169+
from distutils.dir_util import copy_tree # allows overwriting
170+
copy_tree(f'{FROM}/tutorials', f'{TO}/tutorials')
171+
shutil.copy(f'{FROM}/images/g3618.png', f'{TO}/_static/')
172+
shutil.copy(f'{FROM}/images/recirq_logo_notext.png', f'{TO}/_static/')
173+
151174
app.connect('env-before-read-docs', env_before_read_docs)
175+
app.connect('source-read', source_read)

dev_tools/docs/sphinx/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ navigation.
2626
:hidden:
2727

2828
data_collection_idioms
29-
Readout-Data-Collection
30-
Readout-Analysis
29+
tutorials/data_collection
30+
tutorials/data_analysis
3131
best_practices
3232

3333
.. toctree::

docs/tutorials/data_analysis.ipynb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,10 @@
9999
},
100100
"outputs": [],
101101
"source": [
102-
"!pip install git+https://github.com/quantumlib/ReCirq"
102+
"try:\n",
103+
" import recirq\n",
104+
"except ImportError:\n",
105+
" !pip install git+https://github.com/quantumlib/ReCirq"
103106
]
104107
},
105108
{
@@ -453,7 +456,6 @@
453456
},
454457
"kernelspec": {
455458
"display_name": "Python 3",
456-
"language": "python",
457459
"name": "python3"
458460
}
459461
},

docs/tutorials/data_collection.ipynb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,10 @@
109109
},
110110
"outputs": [],
111111
"source": [
112-
"!pip install git+https://github.com/quantumlib/ReCirq"
112+
"try:\n",
113+
" import recirq\n",
114+
"except ImportError:\n",
115+
" !pip install git+https://github.com/quantumlib/ReCirq"
113116
]
114117
},
115118
{
@@ -437,7 +440,6 @@
437440
},
438441
"kernelspec": {
439442
"display_name": "Python 3",
440-
"language": "python",
441443
"name": "python3"
442444
}
443445
},

0 commit comments

Comments
 (0)