|
61 | 61 | "together with the signature, into a web page.\n",
|
62 | 62 | "\n",
|
63 | 63 | "The most popular is [Doxygen](http://www.doxygen.nl/).\n",
|
64 |
| - "[Have a look at an example of some Doxygen output](\n", |
65 |
| - "http://www.bempp.org/cppref/2.0/group__abstract__boundary__operators.html).\n", |
66 | 64 | "\n",
|
67 |
| - "[Sphinx](http://sphinx-doc.org/) is nice for Python, and works with C++ as well.\n", |
68 |
| - "Here's some [Sphinx-generated output](http://www.bempp.org/pythonref/2.0/bempp_visualization.html)\n", |
69 |
| - "and the [corresponding source code](https://bitbucket.org/bemppsolutions/bempp/src/8f10af0b0b4a94bc36c6236eb9ddb2a34cde1756/python/bempp/visualization.py?at=v2.0.2&fileviewer=file-view-default).\n", |
70 |
| - "[Breathe](https://breathe.readthedocs.io/en/latest/) can be used to make Sphinx and Doxygen work together.\n", |
| 65 | + "Here are some other documentation tools used in different languages, have a look at the generated and source examples:\n", |
71 | 66 | "\n",
|
72 |
| - "[Roxygen](https://cran.r-project.org/web/packages/roxygen2/vignettes/roxygen2.html) is good for R.\n" |
| 67 | + "\n", |
| 68 | + "| Language | Name | Output example | source |\n", |
| 69 | + "| --- | --- | --- | --- |\n", |
| 70 | + "| Multiple | [Doxygen](http://www.doxygen.nl/) | [`Array` docs](https://eigen.tuxfamily.org/dox/classEigen_1_1Array.html) | [`Array` docstring source](https://gitlab.com/libeigen/eigen/-/blob/55e3ae02ac1f13fbcc7a83f5e37a39fd2b142db1/Eigen/src/Core/Array.h#L26-L45) |\n", |
| 71 | + "| Python | [Sphinx](http://sphinx-doc.org/) | [`numpy.ones` docs](https://numpy.org/doc/1.21/reference/generated/numpy.ones.html) | [`numpy.ones` docstring source](https://github.com/numpy/numpy/blob/v1.21.0/numpy/core/numeric.py#L149-L206) |\n", |
| 72 | + "| R | [pkgdown](https://pkgdown.r-lib.org/) | [`stringr`'s `str_unique`](https://stringr.tidyverse.org/reference/str_unique.html) | [`stringr`'s `str_unique` docstring source](https://github.com/tidyverse/stringr/blob/main/R/unique.R) |\n", |
| 73 | + "| Julia | [Documnenter.jl](https://juliadocs.github.io/Documenter.jl/stable/) | [`ones` docs](https://docs.julialang.org/en/v1/base/arrays/#Base.ones) | [`ones` docstring source](https://github.com/JuliaLang/julia/blob/ae8452a9e0b973991c30f27beb2201db1b0ea0d3/base/array.jl#L475-L493) |\n", |
| 74 | + "| Fortan | [FORD](https://github.com/Fortran-FOSS-Programmers/ford) | [`arange` docs](https://stdlib.fortran-lang.org/interface/arange.html) | [`arange` docstring source](https://github.com/fortran-lang/stdlib/blob/d14fca8e7cc36ed5f6f84d2bf576c91c2e54eb07/src/stdlib_math.fypp#L276-L290) |\n", |
| 75 | + "| Rust | [rustdoc](https://doc.rust-lang.org/rustdoc/what-is-rustdoc.html) | [`Matrix` docs](https://docs.rs/nalgebra/0.18.0/nalgebra/base/struct.Matrix.html) | [`Matrix` docstring source](https://github.com/dimforge/nalgebra/blob/8ea8ac70d5ad4bae865e6246a48455bf0b3fa3d2/src/base/matrix.rs#L59-L157) |\n", |
| 76 | + "\n", |
| 77 | + "[Breathe](https://breathe.readthedocs.io/en/latest/) can be used to make Sphinx and Doxygen work together (good to keep documentation, for example, of a C++ project that includes Python bindings). [roxygen2](https://cran.r-project.org/web/packages/roxygen2/vignettes/roxygen2.html) is another good option for R packages.\n", |
| 78 | + "\n", |
| 79 | + "\n" |
73 | 80 | ]
|
74 | 81 | },
|
75 | 82 | {
|
|
95 | 102 | "There are various conventions for how to write docstrings, but the native Sphinx one doesn't look nice when used with\n",
|
96 | 103 | "the built in `help` system.\n",
|
97 | 104 | "\n",
|
98 |
| - "In writing Greeter, we used the docstring conventions from NumPy.\n", |
99 |
| - "So we use the [numpydoc](https://numpydoc.readthedocs.io/en/latest/) sphinx extension to \n", |
| 105 | + "In writing Greeter, we used the [docstring conventions from NumPy](https://numpy.org/doc/stable/docs/howto_document.html).\n", |
| 106 | + "So we use the [`numpydoc`](https://numpydoc.readthedocs.io/en/latest/) sphinx extension to\n", |
100 | 107 | "support these (Note: you will need to install this extension for the later examples to work)."
|
101 | 108 | ]
|
102 | 109 | },
|
|
176 | 183 | "metadata": {},
|
177 | 184 | "source": [
|
178 | 185 | "```\n",
|
179 |
| - "Welcome to the Sphinx 3.3.0 quickstart utility.\n", |
| 186 | + "Welcome to the Sphinx 4.2.0 quickstart utility.\n", |
180 | 187 | "\n",
|
181 | 188 | "Please enter values for the following settings (just press Enter to\n",
|
182 | 189 | "accept a default value, if one is given in brackets).\n",
|
|
187 | 194 | "Either, you use a directory \"_build\" within the root path, or you separate\n",
|
188 | 195 | "\"source\" and \"build\" directories within the root path.\n",
|
189 | 196 | "> Separate source and build directories (y/n) [n]:\n",
|
| 197 | + "\n", |
| 198 | + "The project name will occur in several places in the built documentation.\n", |
| 199 | + "> Project name: Greetings\n", |
| 200 | + "> Author name(s): James Hetherington\n", |
| 201 | + "> Project release []: 0.1\n", |
| 202 | + "\n", |
| 203 | + "If the documents are to be written in a language other than English,\n", |
| 204 | + "you can select a language here by its language code. Sphinx will then\n", |
| 205 | + "translate text that it generates into that language.\n", |
| 206 | + "\n", |
| 207 | + "For a list of supported codes, see\n", |
| 208 | + "https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language.\n", |
| 209 | + "> Project language [en]:\n", |
| 210 | + "\n", |
| 211 | + "Creating file ./conf.py.\n", |
| 212 | + "Creating file ./index.rst.\n", |
| 213 | + "Creating file ./Makefile.\n", |
| 214 | + "Creating file ./make.bat.\n", |
| 215 | + "\n", |
| 216 | + "Finished: An initial directory structure has been created.\n", |
| 217 | + "\n", |
| 218 | + "You should now populate your master file /tmp/index.rst and create other documentation\n", |
| 219 | + "source files. Use the Makefile to build the docs, like so:\n", |
| 220 | + " make builder\n", |
| 221 | + "where \"builder\" is one of the supported builders, e.g. html, latex or linkcheck.\n", |
190 | 222 | "```"
|
191 | 223 | ]
|
192 | 224 | },
|
193 | 225 | {
|
194 | 226 | "cell_type": "markdown",
|
195 | 227 | "metadata": {},
|
196 | 228 | "source": [
|
197 |
| - "and then look at and adapt the generated config, a file called\n", |
198 |
| - "conf.py in the root of the project. This contains the project's Sphinx configuration, as Python variables:" |
| 229 | + "and then look at and adapt the generated config - a file called\n", |
| 230 | + "`conf.py` in the root of the project - with, for example, the extensions we want to use.\n", |
| 231 | + "This config file contains the project's Sphinx configuration, as Python variables:" |
199 | 232 | ]
|
200 | 233 | },
|
201 | 234 | {
|
|
247 | 280 | "import sys\n",
|
248 | 281 | "import os\n",
|
249 | 282 | "\n",
|
| 283 | + "# We need to tell Sphinx where to look for modules\n", |
| 284 | + "sys.path.insert(0, os.path.abspath('.'))\n", |
| 285 | + "\n", |
250 | 286 | "extensions = [\n",
|
251 | 287 | " 'sphinx.ext.autodoc', # Support automatic documentation\n",
|
252 | 288 | " 'sphinx.ext.coverage', # Automatically check if functions are documented\n",
|
|
257 | 293 | "templates_path = ['_templates']\n",
|
258 | 294 | "source_suffix = '.rst'\n",
|
259 | 295 | "master_doc = 'index'\n",
|
260 |
| - "project = u'Greetings'\n", |
261 |
| - "copyright = u'2014, James Hetherington'\n", |
| 296 | + "project = 'Greetings'\n", |
| 297 | + "copyright = '2014, James Hetherington'\n", |
262 | 298 | "version = '0.1'\n",
|
263 | 299 | "release = '0.1'\n",
|
264 |
| - "exclude_patterns = ['_build']\n", |
| 300 | + "exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']\n", |
| 301 | + "html_theme = 'alabaster'\n", |
265 | 302 | "pygments_style = 'sphinx'\n",
|
266 | 303 | "htmlhelp_basename = 'Greetingsdoc'\n",
|
267 | 304 | "latex_elements = {\n",
|
268 | 305 | "}\n",
|
269 | 306 | "\n",
|
270 | 307 | "latex_documents = [\n",
|
271 |
| - " ('index', 'Greetings.tex', u'Greetings Documentation',\n", |
272 |
| - " u'James Hetherington', 'manual'),\n", |
| 308 | + " ('index', 'Greetings.tex', 'Greetings Documentation',\n", |
| 309 | + " 'James Hetherington', 'manual'),\n", |
273 | 310 | "]\n",
|
274 | 311 | "\n",
|
275 | 312 | "man_pages = [\n",
|
276 |
| - " ('index', 'greetings', u'Greetings Documentation',\n", |
277 |
| - " [u'James Hetherington'], 1)\n", |
| 313 | + " ('index', 'greetings', 'Greetings Documentation',\n", |
| 314 | + " ['James Hetherington'], 1)\n", |
278 | 315 | "]\n",
|
279 | 316 | "\n",
|
280 | 317 | "texinfo_documents = [\n",
|
281 | 318 | " ('index', 'Greetings', u'Greetings Documentation',\n",
|
282 |
| - " u'James Hetherington', 'Greetings', 'One line description of project.',\n", |
| 319 | + " 'James Hetherington', 'Greetings', 'One line description of project.',\n", |
283 | 320 | " 'Miscellaneous'),\n",
|
284 | 321 | "]"
|
285 | 322 | ]
|
|
296 | 333 | "metadata": {},
|
297 | 334 | "source": [
|
298 | 335 | "\n",
|
299 |
| - "Sphinx uses [RestructuredText](http://docutils.sourceforge.net/rst.html) another wiki markup format similar to Markdown.\n", |
| 336 | + "Sphinx uses [RestructuredText](https://docutils.sourceforge.io/rst.html) another wiki markup format similar to Markdown.\n", |
300 | 337 | "\n",
|
301 | 338 | "You define an \"index.rst\" file to contain any preamble text you want. The rest is autogenerated by `sphinx-quickstart`\n",
|
302 | 339 | "\n",
|
|
363 | 400 | "name": "stdout",
|
364 | 401 | "output_type": "stream",
|
365 | 402 | "text": [
|
366 |
| - "Running Sphinx v1.8.0\n" |
| 403 | + "Running Sphinx v4.2.0\n" |
367 | 404 | ]
|
368 | 405 | },
|
369 | 406 | {
|
|
389 | 426 | "cell_type": "markdown",
|
390 | 427 | "metadata": {},
|
391 | 428 | "source": [
|
392 |
| - "Sphinx's output is [html](http://github-pages.ucl.ac.uk/rsd-engineeringcourse/ch04packaging/greetings/doc/index.html). We just created a simple single function's documentation, but Sphinx will create\n", |
| 429 | + "Sphinx's output is [html](./greetings/doc/index.html). We just created a simple single function's documentation, but Sphinx will create\n", |
393 | 430 | "multiple nested pages of documentation automatically for many functions.\n",
|
394 | 431 | "\n",
|
395 | 432 | "\n",
|
|
409 | 446 | "source": [
|
410 | 447 | "`doctest` is a module included in the standard library. It runs all the code within the docstrings and checks whether the output is what it's claimed on the documentation.\n",
|
411 | 448 | "\n",
|
412 |
| - "Let's add an example to our greeting function and check it with `doctest`. We are leaving the output with a small typo to see what's the type of output we get from `doctest`." |
| 449 | + "Let's add an example to our greeting function and check it with `doctest`. We are leaving the output with a small typo (missing the closing quote `'`) to see what's the type of output we get from `doctest`." |
413 | 450 | ]
|
414 | 451 | },
|
415 | 452 | {
|
|
0 commit comments