doc-contributor-README.rst 6.17 KB
Newer Older
1 2
.. doc-contributor-README:

L.S. Cook's avatar
L.S. Cook committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
.. ---------------------------------------------------------------------------
.. Copyright 2017 Intel Corporation
.. Licensed under the Apache License, Version 2.0 (the "License");
.. you may not use this file except in compliance with the License.
.. You may obtain a copy of the License at
..
..      http://www.apache.org/licenses/LICENSE-2.0
..
.. Unless required by applicable law or agreed to in writing, software
.. distributed under the License is distributed on an "AS IS" BASIS,
.. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
.. See the License for the specific language governing permissions and
.. limitations under the License.
.. ---------------------------------------------------------------------------

L.S. Cook's avatar
L.S. Cook committed
18 19
nGraph Library docs  
===================
L.S. Cook's avatar
L.S. Cook committed
20

21 22
Read this for changes affecting anything in ``ngraph/doc``
----------------------------------------------------------
L.S. Cook's avatar
L.S. Cook committed
23

L.S. Cook's avatar
L.S. Cook committed
24
For updates to the Intel® nGraph Library ``/doc`` repo, please submit a PR with 
L.S. Cook's avatar
L.S. Cook committed
25 26 27 28
any changes or ideas you'd like integrated. This helps us maintain trackability 
with respect to additions or feature requests.

If you prefer to use a containerized application, like Jupyter\* notebooks, 
29
Google Docs\*, or MS Word\* to explain, write, or share documentation contributions, 
L.S. Cook's avatar
L.S. Cook committed
30
you can convert the ``doc/sphinx/source/*.rst`` files to another format with a tool 
31
like ``pypandoc`` and share a link to your docs on our `wiki`_.
L.S. Cook's avatar
L.S. Cook committed
32 33 34

Another option is to fork the `ngraph repo`_, essentially snapshotting it at 
that point in time, and to build a Jupyter\* notebook or other set of docs around 
35
it for a specific use case; then share a link with the community on our wiki.   
L.S. Cook's avatar
L.S. Cook committed
36 37

.. note:: Please do not submit Jupyter* notebook code to the Intel nGraph library 
38
   or core repos; best practice is to maintain any project-specific examples, 
39
   tests, or walk-throughs separately. 
L.S. Cook's avatar
L.S. Cook committed
40 41 42 43 44 45


Documenting source code examples 
--------------------------------

When **verbosely** documenting functionality of specific sections of code -- whether 
46 47
they are entire code blocks within a file, or code strings that are **outside** 
the Intel nGraph `documentation repo`_, here is an example of best practice: 
L.S. Cook's avatar
L.S. Cook committed
48

49 50 51 52
Say a file has some interesting functionality that could benefit from more 
explanation about one or more of the pieces in context. To keep the "in context" 
navigable, write something like the following in your ``.rst`` documentation 
source file:
L.S. Cook's avatar
L.S. Cook committed
53 54 55

::

56
  .. literalinclude:: ../../../examples/abc/abc.cpp
57 58
     :language: cpp
     :lines: 20-31
L.S. Cook's avatar
L.S. Cook committed
59 60 61

And the raw code will render as follows

62

63
.. literalinclude:: ../../../examples/abc/abc.cpp 
64 65
   :language: cpp
   :lines: 20-31
L.S. Cook's avatar
L.S. Cook committed
66 67

You can now verbosely explain the code block without worrying about breaking
68
the code. The trick here is to add the file you want to reference relative to 
69
the folder where the ``Makefile`` is that generates the documentation you're 
70 71 72 73 74 75
writing. 


See the **note** at the bottom of this page for more detail about how 
this works in the current |version| version of Intel nGraph library 
documentation. 
L.S. Cook's avatar
L.S. Cook committed
76 77 78 79 80 81 82 83


Adding captions to code blocks 
------------------------------

One more trick to helping users understand exactly what you mean with a section
of code is to add a caption with content that describes your parsing logic. To 
build on the previous example, let's take a bigger chunk of code, add some 
84
line numbers, and add a caption:
L.S. Cook's avatar
L.S. Cook committed
85 86 87

::

88
  .. literalinclude:: ../../../examples/abc/abc.cpp
89
     :language: cpp
90 91
     :lines: 48-56
     :caption: "caption for a block of code that initializes tensors"
L.S. Cook's avatar
L.S. Cook committed
92 93 94 95


and the generated output will show readers of your helpful documentation

96
.. literalinclude:: ../../../examples/abc/abc.cpp
97
   :language: cpp
98 99
   :lines: 48-56
   :caption: "caption for a block of code that initializes tensors"
L.S. Cook's avatar
L.S. Cook committed
100 101

Our documentation practices are designed around "write once, reuse" that we can 
102 103
use to prevent code bloat.  See the :doc:`code-contributor-README` for our code 
style guide.       
L.S. Cook's avatar
L.S. Cook committed
104

105 106 107

.. build-docs:

108 109
Build the documentation
=======================
110 111


112
.. note:: Stuck on how to generate the html? Run these commands; they assume 
L.S. Cook's avatar
L.S. Cook committed
113 114
   you start at a command line running within a clone (or a cloned fork) of the 
   ``ngraph`` repo.  You do **not** need to run a virtual environment to create 
115 116
   documentation if you don't want; running ``$ make clean`` in the 
   ``doc/sphinx`` folder removes any generated files.
117 118

Right now the minimal version of Sphinx needed to build the documentation is 
119
Sphinx v. 1.7.5.  This can be installed with :command:`pip3`, either to a virtual 
120 121
environment, or to your base system if you plan to contribute much core code or
documentation. For C++ API docs that contain inheritance diagrams and collaboration
122 123 124
diagrams which are helpful for framework integratons, building bridge code, or 
creating a backend UI for your own custom framework, be sure you have a system 
capable of running `doxygen`_.   
125

L.S. Cook's avatar
L.S. Cook committed
126
To build documentation locally, run: 
127

L.S. Cook's avatar
L.S. Cook committed
128 129
   .. code-block:: console

130
      $ sudo apt-get install python3-sphinx
L.S. Cook's avatar
L.S. Cook committed
131
      $ pip3 install [-I] Sphinx==1.7.5 [--user] 
132
      $ pip3 install [-I] breathe numpy [--user]
133 134
      $ cd doc/sphinx/
      $ make html
135 136
      $ cd build/html
      $ python3 -m http.server 8000
L.S. Cook's avatar
L.S. Cook committed
137

138
Then point your browser at ``localhost:8000``.
L.S. Cook's avatar
L.S. Cook committed
139

140 141 142 143 144 145
To build documentation in a python3 virtualenv, run: 

   .. code-block:: console

      $ python3 -m venv py3doc
      $ . py3doc/bin/activate
146
      (py3doc)$ pip install python3-sphinx breathe numpy
147 148 149 150 151 152 153
      (py3doc)$ cd doc/sphinx
      (py3doc)$ make html
      (py3doc)$ cd build/html
      (py3doc)$ python -m http.server 8000

Then point your browser at ``localhost:8000``.

L.S. Cook's avatar
L.S. Cook committed
154 155 156 157 158
.. note:: For docs built in a virtual env, Sphinx latest changes may break 
   documentation; try building with a specific version of Sphinx.  



159 160
For tips on writing reStructuredText-formatted documentation, see the `sphinx`_ 
stable reST documentation.
L.S. Cook's avatar
L.S. Cook committed
161

L.S. Cook's avatar
L.S. Cook committed
162 163
.. _ngraph repo: https://github.com/NervanaSystems/ngraph/
.. _documentation repo: https://github.com/NervanaSystems/ngraph/tree/master/doc
L.S. Cook's avatar
L.S. Cook committed
164 165
.. _sphinx: http://www.sphinx-doc.org/en/stable/rest.html
.. _wiki: https://github.com/NervanaSystems/ngraph/wiki/
166 167
.. _breathe: https://breathe.readthedocs.io/en/latest/
.. _doxygen: http://www.doxygen.org/index.html