Daniel Dunbar | eaa88c8 | 2012-04-06 23:47:34 +0000 | [diff] [blame] | 1 | .. _sphinx_intro: |
| 2 | |
| 3 | Sphinx Introduction for LLVM Developers |
| 4 | ======================================= |
| 5 | |
| 6 | This document is intended as a short and simple introduction to the Sphinx |
| 7 | documentation generation system for LLVM developers. |
| 8 | |
| 9 | Quickstart |
| 10 | ---------- |
| 11 | |
| 12 | To get started writing documentation, you will need to: |
| 13 | |
| 14 | 1. Have the Sphinx tools :ref:`installed <installing_sphinx>`. |
| 15 | |
| 16 | 2. Understand how to :ref:`build the documentation |
| 17 | <building_the_documentation>`. |
| 18 | |
| 19 | 3. Start :ref:`writing documentation <writing_documentation>`! |
| 20 | |
| 21 | .. _installing_sphinx: |
| 22 | |
| 23 | Installing Sphinx |
| 24 | ~~~~~~~~~~~~~~~~~ |
| 25 | |
| 26 | You should be able to install Sphinx using the standard Python package |
| 27 | installation tool ``easy_install``, as follows:: |
| 28 | |
| 29 | $ sudo easy_install sphinx |
| 30 | Searching for sphinx |
| 31 | Reading http://pypi.python.org/simple/sphinx/ |
| 32 | Reading http://sphinx.pocoo.org/ |
| 33 | Best match: Sphinx 1.1.3 |
| 34 | ... more lines here .. |
| 35 | |
| 36 | If you do not have root access (or otherwise want to avoid installing Sphinx in |
| 37 | system directories) see the section on :ref:`installing_sphinx_in_a_venv` . |
| 38 | |
| 39 | If you do not have the ``easy_install`` tool on your system, you should be able |
| 40 | to install it using: |
| 41 | |
| 42 | Linux |
Alex Rosenberg | b65e888 | 2013-02-03 07:05:26 +0000 | [diff] [blame] | 43 | Use your distribution's standard package management tool to install it, |
| 44 | i.e., ``apt-get install easy_install`` or ``yum install easy_install``. |
Daniel Dunbar | eaa88c8 | 2012-04-06 23:47:34 +0000 | [diff] [blame] | 45 | |
| 46 | Mac OS X |
| 47 | All modern Mac OS X systems come with ``easy_install`` as part of the base |
| 48 | system. |
| 49 | |
| 50 | Windows |
| 51 | See the `setuptools <http://pypi.python.org/pypi/setuptools>`_ package web |
| 52 | page for instructions. |
| 53 | |
| 54 | |
| 55 | .. _building_the_documentation: |
| 56 | |
| 57 | Building the documentation |
| 58 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 59 | |
| 60 | In order to build the documentation, all you should need to do is change to the |
| 61 | ``docs`` directory and invoke make as follows:: |
| 62 | |
| 63 | $ cd path/to/project/docs |
| 64 | $ make html |
| 65 | |
Daniel Dunbar | e84f5ca | 2012-04-06 23:55:50 +0000 | [diff] [blame] | 66 | Note that on Windows there is a ``make.bat`` command in the docs directory which |
| 67 | supplies the same interface as the ``Makefile``. |
| 68 | |
| 69 | That command will invoke ``sphinx-build`` with the appropriate options for the |
| 70 | project, and generate the HTML documentation in a ``_build`` subdirectory. You |
| 71 | can browse it starting from the index page by visiting |
| 72 | ``_build/html/index.html``. |
Daniel Dunbar | eaa88c8 | 2012-04-06 23:47:34 +0000 | [diff] [blame] | 73 | |
| 74 | Sphinx supports a wide variety of generation formats (including LaTeX, man |
| 75 | pages, and plain text). The ``Makefile`` includes a number of convenience |
| 76 | targets for invoking ``sphinx-build`` appropriately, the common ones are: |
| 77 | |
| 78 | make html |
| 79 | Generate the HTML output. |
| 80 | |
Daniel Dunbar | e84f5ca | 2012-04-06 23:55:50 +0000 | [diff] [blame] | 81 | make latexpdf |
Daniel Dunbar | eaa88c8 | 2012-04-06 23:47:34 +0000 | [diff] [blame] | 82 | Generate LaTeX documentation and convert to a PDF. |
| 83 | |
Daniel Dunbar | e84f5ca | 2012-04-06 23:55:50 +0000 | [diff] [blame] | 84 | make man |
Daniel Dunbar | eaa88c8 | 2012-04-06 23:47:34 +0000 | [diff] [blame] | 85 | Generate man pages. |
| 86 | |
| 87 | |
| 88 | .. _writing_documentation: |
| 89 | |
| 90 | Writing documentation |
| 91 | ~~~~~~~~~~~~~~~~~~~~~ |
| 92 | |
| 93 | The documentation itself is written in the reStructuredText (ReST) format, and Sphinx |
| 94 | defines additional tags to support features like cross-referencing. |
| 95 | |
| 96 | The ReST format itself is organized around documents mostly being readable |
| 97 | plaintext documents. You should generally be able to write new documentation |
| 98 | easily just by following the style of the existing documentation. |
| 99 | |
| 100 | If you want to understand the formatting of the documents more, the best place |
| 101 | to start is Sphinx's own `ReST Primer <http://sphinx.pocoo.org/rest.html>`_. |
| 102 | |
| 103 | |
| 104 | Learning More |
| 105 | ------------- |
| 106 | |
| 107 | If you want to learn more about the Sphinx system, the best place to start is |
| 108 | the Sphinx documentation itself, available `here |
| 109 | <http://sphinx.pocoo.org/contents.html>`_. |
| 110 | |
| 111 | |
| 112 | .. _installing_sphinx_in_a_venv: |
| 113 | |
| 114 | Installing Sphinx in a Virtual Environment |
| 115 | ------------------------------------------ |
| 116 | |
| 117 | Most Python developers prefer to work with tools inside a *virtualenv* (virtual |
| 118 | environment) instance, which functions as an application sandbox. This avoids |
| 119 | polluting your system installation with different packages used by various |
| 120 | projects (and ensures that dependencies for different packages don't conflict |
| 121 | with one another). Of course, you need to first have the virtualenv software |
| 122 | itself which generally would be installed at the system level:: |
| 123 | |
| 124 | $ sudo easy_install virtualenv |
| 125 | |
| 126 | but after that you no longer need to install additional packages in the system |
| 127 | directories. |
| 128 | |
| 129 | Once you have the *virtualenv* tool itself installed, you can create a |
| 130 | virtualenv for Sphinx using:: |
| 131 | |
| 132 | $ virtualenv ~/my-sphinx-install |
| 133 | New python executable in /Users/dummy/my-sphinx-install/bin/python |
| 134 | Installing setuptools............done. |
| 135 | Installing pip...............done. |
| 136 | |
| 137 | $ ~/my-sphinx-install/bin/easy_install sphinx |
| 138 | ... install messages here ... |
| 139 | |
| 140 | and from now on you can "activate" the *virtualenv* using:: |
| 141 | |
| 142 | $ source ~/my-sphinx-install/bin/activate |
| 143 | |
| 144 | which will change your PATH to ensure the sphinx-build tool from inside the |
| 145 | virtual environment will be used. See the `virtualenv website |
| 146 | <http://www.virtualenv.org/en/latest/index.html>`_ for more information on using |
| 147 | virtual environments. |