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

L.S. Cook's avatar
L.S. Cook committed
3
.. ---------------------------------------------------------------------------
Robert Kimball's avatar
Robert Kimball committed
4
.. Copyright 2017-2019 Intel Corporation
L.S. Cook's avatar
L.S. Cook committed
5 6 7 8 9 10 11 12 13 14 15 16 17
.. 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.
.. ---------------------------------------------------------------------------

18 19
:orphan:

20 21
Contributing to documentation
=============================
L.S. Cook's avatar
L.S. Cook committed
22

Leona C's avatar
Leona C committed
23 24
.. note:: Tips for contributors who are new to the highly-dynamic 
   environment of documentation in AI software:
L.S. Cook's avatar
L.S. Cook committed
25

Leona C's avatar
Leona C committed
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
   * A good place to start is "document something you figured out how to 
     get working". Content changes and additions should be targeted at 
     something more specific than "developers". If you don't understand 
     how varied and wide the audience is, you'll inadvertently break or block 
     things.

   * There are experts who work on all parts of the stack; try asking how 
     documentation changes ought to be made in their respective sections.

   * Start with something small. It is okay to add a "patch" to fix a typo 
     or suggest a word change; larger changes to files or structure require 
     research and testing first, as well as some logic for why you think 
     something needs changed.

   * Most documentation should wrap at about ``80``. We do our best to help 
     authors source-link and maintain their own code and contributions; 
     overwriting something already documented doesn't always improve it.

   * Be careful editing files with links already present in them; deleting 
     links to papers, citations, or sources is discouraged.

   * Please do not submit Jupyter* notebook code to the nGraph Library
     or core repos; best practice is to maintain any project-specific 
     examples, tests, or walk-throughs in a separate repository and to link 
     back to the stable ``op`` or Ops that you use in your project.

For updates within the nGraph Library ``/doc`` repo, please submit a PR with 
L.S. Cook's avatar
L.S. Cook committed
53
any changes or ideas you'd like integrated. This helps us maintain trackability 
54
with respect to changes made, additions, deletions, and feature requests.
L.S. Cook's avatar
L.S. Cook committed
55 56

If you prefer to use a containerized application, like Jupyter\* notebooks, 
57 58 59 60
Google Docs\*, the GitHub* GUI, or MS Word\* to explain, write, or share 
documentation contributions, you can convert the ``doc/sphinx/source/*.rst`` 
files to another format with a tool like ``pypandoc`` and share a link   
to your efforts on our `wiki`_. 
L.S. Cook's avatar
L.S. Cook committed
61 62

Another option is to fork the `ngraph repo`_, essentially snapshotting it at 
Leona C's avatar
Leona C committed
63
that point in time, and to build a Jupyter\* notebook or other set of docs around 
64 65 66
it for a specific use case. Add a note on our wiki to show us what you 
did; new and novel applications may have their projects highlighted on an 
upcoming `ngraph.ai`_ release.   
L.S. Cook's avatar
L.S. Cook committed
67

68
.. note:: Please do not submit Jupyter* notebook code to the nGraph Library 
69
   or core repos; best practice is to maintain any project-specific examples, 
70
   tests, or walk-throughs in a separate repository.
L.S. Cook's avatar
L.S. Cook committed
71 72 73 74 75


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

Leona C's avatar
Leona C committed
76 77 78 79 80
When **verbosely** documenting functionality of specific sections of code -- 
whether they are entire code blocks within a file, or code strings that are 
**outside** the nGraph Library's `documentation repo`_, here is an example 
of best practice: 

L.S. Cook's avatar
L.S. Cook committed
81

82 83 84 85
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
86 87 88

::

89
  .. literalinclude:: ../../../examples/abc/abc.cpp
90 91
     :language: cpp
     :lines: 20-31
L.S. Cook's avatar
L.S. Cook committed
92 93 94

And the raw code will render as follows

95

96
.. literalinclude:: ../../../examples/abc/abc.cpp 
97 98
   :language: cpp
   :lines: 20-31
L.S. Cook's avatar
L.S. Cook committed
99 100

You can now verbosely explain the code block without worrying about breaking
101
the code. The trick here is to add the file you want to reference relative to 
102
the folder where the ``Makefile`` is that generates the documentation you're 
103 104 105
writing. 

See the **note** at the bottom of this page for more detail about how 
Leona C's avatar
Leona C committed
106
this works in the current |version| version of nGraph Library documentation.
L.S. Cook's avatar
L.S. Cook committed
107 108 109 110 111 112 113 114


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 
115
line numbers, and add a caption:
L.S. Cook's avatar
L.S. Cook committed
116 117 118

::

119
  .. literalinclude:: ../../../examples/abc/abc.cpp
120
     :language: cpp
121 122
     :lines: 48-56
     :caption: "caption for a block of code that initializes tensors"
L.S. Cook's avatar
L.S. Cook committed
123 124 125 126


and the generated output will show readers of your helpful documentation

127
.. literalinclude:: ../../../examples/abc/abc.cpp
128
   :language: cpp
129 130
   :lines: 48-56
   :caption: "caption for a block of code that initializes tensors"
L.S. Cook's avatar
L.S. Cook committed
131 132

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

136 137 138

.. build-docs:

139 140
How to build the documentation
-------------------------------
141 142


143 144 145 146
.. note:: Stuck on how to generate the html? Run these commands; they assume
   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
   documentation if you don't want; running ``$ make clean`` in the
147
   ``doc/sphinx`` folder removes any generated files.
148

149
Right now the minimal version of Sphinx needed to build the documentation is
150
Sphinx v. 1.7.5.  This can be installed with :command:`pip3`, either to a virtual 
151 152
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
153 154 155
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`_.   
156

L.S. Cook's avatar
L.S. Cook committed
157
To build documentation locally, run: 
158

L.S. Cook's avatar
L.S. Cook committed
159 160
   .. code-block:: console

Leona C's avatar
Leona C committed
161
      $ sudo apt-get install python3-sphinx
162 163
      $ pip3 install Sphinx==1.7.5
      $ pip3 install breathe numpy
164 165
      $ cd doc/sphinx/
      $ make html
166 167
      $ cd build/html
      $ python3 -m http.server 8000
L.S. Cook's avatar
L.S. Cook committed
168

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

171
To build documentation in a python3 virtualenv, try: 
172 173 174 175 176

   .. code-block:: console

      $ python3 -m venv py3doc
      $ . py3doc/bin/activate
177
      (py3doc)$ pip install Sphinx breathe numpy
178 179 180 181 182 183 184
      (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
185
.. note:: For docs built in a virtual env, Sphinx latest changes may break 
186
   documentation; try building with a specific version of Sphinx. 
L.S. Cook's avatar
L.S. Cook committed
187 188 189



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

L.S. Cook's avatar
L.S. Cook committed
193
.. _ngraph repo: https://github.com/NervanaSystems/ngraph/
194
.. _ngraph.ai: https://www.ngraph.ai
L.S. Cook's avatar
L.S. Cook committed
195
.. _documentation repo: https://github.com/NervanaSystems/ngraph/tree/master/doc
L.S. Cook's avatar
L.S. Cook committed
196 197
.. _sphinx: http://www.sphinx-doc.org/en/stable/rest.html
.. _wiki: https://github.com/NervanaSystems/ngraph/wiki/
198 199
.. _breathe: https://breathe.readthedocs.io/en/latest/
.. _doxygen: http://www.doxygen.org/index.html
200 201


Leona C's avatar
Leona C committed
202
.. 45555555555555555555555555555