Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction to Sphinx & Read the Docs

Introduction to Sphinx & Read the Docs

ericholscher

March 15, 2014
Tweet

More Decks by ericholscher

Other Decks in Technology

Transcript

  1. What we will talk about today • Why Write Docs

    • reStructuredText • Sphinx • Read the Docs
  2. Who am I • Maintainer of Read the Docs •

    Co-Organizer of Write the Docs
  3. What you should do • Stop me if anything is

    unclear • Stop me if I’m talking too fast • Ask questions • Learn something :)
  4. ! ! ! ! +----------------------------------------------------------+ | | | Read the

    Docs | | +----------------------------------------------+ | | | | | | | Sphinx | | | | +-----------------------------------+ | | | | | | | | | | | Docutils | | | | | | +--------------------+ | | | | | | | | | | | | | | | reStructuredText | | | | | | | | | | | | | | | +--------------------+ | | | | | | | | | | | | | | | | | | | | | | | +-----------------------------------+ | | | | | | | | | | | | | | | +----------------------------------------------+ | | | | | +----------------------------------------------------------+ Tech Overview
  5. Lightweight Markup Language • Base format to generate other formats

    from • Readable as plain text • Works well with programmer tools
  6. Semantic Meaning • The power of HTML, and LWML •

    Semantics mean you are saying what something is, not how to display it • Once you know what it is, you can display it properly
  7. # HTML (Bad) <b>issue 72</b> ! # HTML (Good) <span

    class=“issue”>issue 72</span> # CSS .issue { text-format: bold; } Classic HTML Example
  8. # Bad <font color=“red”>Warning: Don’t do this!</font> ! # Good

    <span class=“warning”>Don’t do this!</span> ! # Best .. warning:: Don’t do this Classic LWML Example
  9. Semantic Markup • Shows the intent of your words •

    Works across output formats • You can style warnings differently in HTML, PDF, epub, man pages, etc.
  10. Markdown vs. reST • Markdown is JUST for HTML •

    reStructuredText does more, thus is more complex • reStructuredText is ugly, not only because of the complexity
  11. If you care about your words, you should write in

    a way that preserves semantic meaning!
  12. Page Level Markup • A line that starts with “..

    “, 2 periods and whitespace • Ends at the next un-indented line
  13. Directives • .. directive-name:: • Main source of extendability •

    A lot of Sphinx’s power comes through Directives
  14. .. code-block:: python :linenos: ! from datetime import datetime time

    = datetime.now() print time Directive Example
  15. Inline Markup • Anything that is included in the page

    content itself • Used for embedding things into the rendered output
  16. Interpreted Text Roles • Good example of Inline Markup •

    Look like :role:`target` • :pep:`8` will create a link to PEP 8
  17. .. _my-reference-label: ! Section to cross-reference -------------------------- ! This is

    the text of the section. ! It refers to itself, see :ref:`my-reference-label`. Interpreted Text Role Example
  18. Extension Point Review • Directives for page level markup •

    Interpreted Text Roles for inside paragraphs
  19. reStructuredText Review • The best LWML that I know of

    • Gives you the most semantic meaning • Most extensible • Sphinx adds documentation semantics to reStructuredText • Play with it at http://rst.ninjs.org
  20. Sphinx • Best documentation tool I know of • Great

    community and lots of prior art • So good, that I built an entire website around it :)
  21. TOC Tree • Table of Contents Tree • Allows hierarchal

    notion of documents • Gives you a nice index page of all your content • .. toctree:: Table of Contents
  22. Cross-referencing • Allows you to reference content in other documents

    • Intersphinx extension lets you reference content in other projects • :ref:`python:keywords` • :doc:`tutorial`
  23. Extensions • Ships with lots of useful extensions • Has

    an API for defining your own • Ships with doctest runner, coverage stats, graphviz support, todo lists, viewing source code, etc.
  24. Autodoc • Pulls docstrings from your classes and methods •

    Runs dynamically so it’s always up to date with your source code • A bit hard to work with, because it’s made to be manually edited • .. class:: django.core.views.View
  25. Sphinx Review • Documentation Generator • Takes reST files and

    turns it into HTML/PDF/etc • Adds lots of nice markup specific to writing tech documentation
  26. Read the Docs • Builds and hosts Sphinx documentation •

    Defacto hosting provider for Python documentation • Created in 48 hours in 2010 Django Dash • Provides a lot of value on top of Sphinx
  27. RTD Stats • 118 people have contributed code • 3,801

    commits • 844 issues • 1,475,000 builds • 150 million pageviews, 9M a month • http://ericholscher.com/blog/2013/dec/ 23/read-the-docs-2013-stats/
  28. Beautiful Theme • Designed by Dave Snider (a real designer!)

    • Looks great on mobile • Beautiful fonts and colors
  29. Versions • Based on your VCS • Every tag and

    branch convert into a version • Build and host old versions of your docs, for users who still use them
  30. Post Commit Hooks • We support GitHub and BitBucket •

    Your docs build automatically when you push a new commit • Your docs are always up to date
  31. Translations • Host multiple languages of your docs • Host

    one version of your docs, not in English :)
  32. Search • We index everything into Elastic Search • Provide

    full-text search of your documentation • Much better than the built-in Sphinx search, since we can use a server
  33. Highly Available • We host everything with redundant app servers

    straight from nginx, without touching a database • Never had significant (multi-hour) downtime of documentation serving
  34. Lots of small things • Serve multiple projects on one

    CNAME • Have multiple people manage a project • Python 3 • Virtualenv & requirements.txt support
  35. Using RTD • Register for an account • Import your

    project with Sphinx documentation • There is no step 3
  36. Recap • Why Write Documentation • Why reST and Sphinx

    exist and how they work • Why Read the Docs is awesome :)