Slide 1

Slide 1 text

Eric Holscher eric@ericholscher.com Introduction to Sphinx & Read the Docs

Slide 2

Slide 2 text

Who am I • Co-Founder of Read the Docs • Co-Founder of Write the Docs

Slide 3

Slide 3 text

What we will talk about today • Why Write Docs • reStructuredText • Sphinx • Read the Docs

Slide 4

Slide 4 text

Why Write Docs

Slide 5

Slide 5 text

You will be using your code in 6 months

Slide 6

Slide 6 text

You want people to use your code

Slide 7

Slide 7 text

It makes your code better

Slide 8

Slide 8 text

You want to be a better writer

Slide 9

Slide 9 text

+----------------------------------------------------------+ | | | Read the Docs | | +----------------------------------------------+ | | | | | | | Sphinx | | | | +-----------------------------------+ | | | | | | | | | | | Docutils | | | | | | +--------------------+ | | | | | | | | | | | | | | | reStructuredText | | | | | | | | | | | | | | | +--------------------+ | | | | | | | | | | | | | | | | | | | | | | | +-----------------------------------+ | | | | | | | | | | | | | | | +----------------------------------------------+ | | | | | +----------------------------------------------------------+ Tech Overview

Slide 10

Slide 10 text

reStructuredText

Slide 11

Slide 11 text

Lightweight Markup Language

Slide 12

Slide 12 text

Lightweight Markup Language • Base format to generate other formats from • Readable as plain text • Works well with programmer tools

Slide 13

Slide 13 text

Semantic Meaning • The power of HTML, and reStructredText • Semantics mean you are saying what something is, not how to display it • Once you know what it is, you can display it properly • “Separation of Concerns”

Slide 14

Slide 14 text

# HTML (Bad) issue 72 # HTML (Good) issue 72 # CSS .issue { text-format: bold; } Classic HTML Example

Slide 15

Slide 15 text

# Bad Warning: Don’t do this! # Good Don’t do this! # Best .. warning:: Don’t do this Classic RST Example

Slide 16

Slide 16 text

# Markdown Check out [PEP 8](https:// www.python.org/dev/peps/pep-0008/) # RST Check out :pep:`8` Markdown vs. RST

Slide 17

Slide 17 text

Semantic Markup • Shows the intent of your words • Works across output formats • You can style warnings differently in HTML, PDF, ePub, etc.

Slide 18

Slide 18 text

Markdown vs. reST • Markdown is JUST for HTML, not semantic • reStructuredText does more, thus is more complex • reStructuredText is ugly, not only because of the complexity

Slide 19

Slide 19 text

If you care about your words, you should write in a way that preserves semantic meaning!

Slide 20

Slide 20 text

RST • Whitespace Sensitive (Like Python) • Extensible • Powerful, but slightly awkward

Slide 21

Slide 21 text

Example • http://localhost:5000/? n=84c9a8d71ad9d4e6dd94504a 3c65f6 &theme=nature

Slide 22

Slide 22 text

Understanding reStructuredText Extensibility

Slide 23

Slide 23 text

Page Level Markup • A line that starts with “.. “, 2 periods and whitespace • Ends at the next un-indented line

Slide 24

Slide 24 text

Directives • .. directive-name:: • Main source of extendability • A lot of Sphinx’s power comes through Directives

Slide 25

Slide 25 text

.. code-block:: python :linenos: from datetime import datetime time = datetime.now() print time Directive Example

Slide 26

Slide 26 text

Directive Example

Slide 27

Slide 27 text

Inline Markup • Anything that is included in the page content itself • Used for embedding things into the rendered output

Slide 28

Slide 28 text

Inline Markup • Look like :role:`target` • :pep:`8` will create a link to PEP 8

Slide 29

Slide 29 text

.. _my-reference-label: Section to cross-reference -------------------------- This is the text of the section. It refers to itself, see :ref:`my-reference-label`. Inline Markup Example

Slide 30

Slide 30 text

Inline Markup Example

Slide 31

Slide 31 text

Code Docs Module Level Page Level Markup Class Level Inline Markup

Slide 32

Slide 32 text

Extension Point Review • Directives for page level markup • Interpreted Text Roles for inside paragraphs

Slide 33

Slide 33 text

RST Review • Gives you semantic meaning • Amazingly extensible • Play with it at http://rst.ninjs.org

Slide 34

Slide 34 text

Sphinx

Slide 35

Slide 35 text

Understanding Sphinx

Slide 36

Slide 36 text

project/ docs/ conf.py Makefile index.rst tutorial.rst … Basic Sphinx Layout

Slide 37

Slide 37 text

Build your Docs • Put RST into your docs directory • Run `make html`

Slide 38

Slide 38 text

Sphinx • Best documentation tool I know of • Great community and lots of prior art • So good, that I built an entire website around it :)

Slide 39

Slide 39 text

Sphinx Additions

Slide 40

Slide 40 text

TOC Tree • Table of Contents Tree • Allows hierarchal notion of documents • Gives you a nice index page of all your content • .. toctree:: Sweet Contents

Slide 41

Slide 41 text

Cross-referencing • Allows you to reference content in other documents • Intersphinx extension lets you reference content in other projects • :ref:`python:keywords` • :doc:`tutorial`

Slide 42

Slide 42 text

Tons of code-specific Markup • Environmental Variables, RFC’s, Tokens, Keywords, Classes, Filenames, Man pages, etc. • :rfc:`1984` • :pep:`8`

Slide 43

Slide 43 text

Syntax Highlighting • Uses Pygments Library • Highlights basically everything • .. source-code:: ruby

Slide 44

Slide 44 text

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.

Slide 45

Slide 45 text

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 • .. autoclass:: ap.models.Poll

Slide 46

Slide 46 text

Sphinx Review • Documentation Generator • Takes reST files and turns it into HTML/PDF/etc • Adds lots of nice markup specific to writing tech documentation

Slide 47

Slide 47 text

Read the Docs

Slide 48

Slide 48 text

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

Slide 49

Slide 49 text

Story of Read the Docs

Slide 50

Slide 50 text

2010 Django Dash

Slide 51

Slide 51 text

Charles Leifer Bobby Grace (Design) Me

Slide 52

Slide 52 text

Doc Hosting Sucks • packages.python.org • GitHub Pages • Cron Jobs

Slide 53

Slide 53 text

No content

Slide 54

Slide 54 text

Had a workable site in 48 Hours

Slide 55

Slide 55 text

Open Source • https://github.com/rtfd/ readthedocs.org

Slide 56

Slide 56 text

Fast Forward to Today

Slide 57

Slide 57 text

RTD Stats • 5,822 commits • 1622 issues • 3.3M builds • 320 million pageviews, 15M a month • https://blog.readthedocs.com/read-the- docs-2014-stats/

Slide 58

Slide 58 text

No content

Slide 59

Slide 59 text

Read the Docs Features

Slide 60

Slide 60 text

Beautiful Theme • Designed by Dave Snider (a real designer!) • Looks great on mobile • Beautiful fonts and colors

Slide 61

Slide 61 text

Beautiful Theme

Slide 62

Slide 62 text

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

Slide 63

Slide 63 text

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

Slide 64

Slide 64 text

Markdown Support • Newly added • Can write in CommonMark or RST in a project

Slide 65

Slide 65 text

Translations • Host multiple languages of your docs • Host one version of your docs, not in English :)

Slide 66

Slide 66 text

Localization • The main readthedocs.org site is localized • We now have 8 languages that are suported

Slide 67

Slide 67 text

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

Slide 68

Slide 68 text

CNAMEs • Host your docs on your own domain • http://docs.fabfile.org

Slide 69

Slide 69 text

Multiple Formats • HTML • PDF • Zipped HTML • ePub

Slide 70

Slide 70 text

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

Slide 71

Slide 71 text

Lots of small things • Build failure emails • Have multiple people manage a project • Python 3 • Virtualenv & requirements.txt support

Slide 72

Slide 72 text

Using Read the Docs

Slide 73

Slide 73 text

Using RTD • Register for an account • Import your project with Sphinx documentation • There is no step 3

Slide 74

Slide 74 text

Recap • Why Write Documentation • Why reST and Sphinx exist and how they work • Why Read the Docs is awesome :)

Slide 75

Slide 75 text

Support • Come help develop RTD if you are interested in this • Help us triage Github Issues • Get your company to Sponsor the project • Use readthedocs.com for your private docs

Slide 76

Slide 76 text

“I can’t say I’m self taught. I’ve been taught by the people who wrote the documentation” - @soulshake

Slide 77

Slide 77 text

Thanks • @ericholscher • eric@ericholscher.com • Come talk to me around the conference