Welcome to XFEL ReadTheDocs’s documentation!

Contents:

Introduction

Documentation for software-related projects should be written such that it can be hosted on this XFEL internal Read The Docs server. Specifically, this implies that:

Projects with Special Dependencies

In case your project has special (external) dependencies it is likely that the build will fail, as the RTD server does not know of this dependencies. You can however add a requirements.txt file to make RTD aware of these dependencies and run the documentation build in a virtual environment with these dependencies. In your documentation root (where the conf.py file is located) place a readthedocs.requirements.txt file. It should have the same format as any pip requirements file:

slumber>=1.0
matplotlib

This would for instance assure that slumber with a version higher 1.0 and a version of matplotlib is installed.

Adding a New Project from GitLab

Adding a new project from GitLab is simple. Before you start, you need to assure that a few prerequisites are met:

  • your project has a sphinx compatible conf.py somewhere in its directory structure and a sphinx build with this files succeeds. See Non-Karabo-Related Documentation for information on how to create such a file.
  • you do not have any special theme or style set in your conf.py. If you do please remove them.
  • your project is hosted on our GitLab server. If it is publically available you can skip on to Adding Your Project to RTD, if not read on at Adding an Access Token.

Adding an Access Token

For private GitLab projects RTD needs some way to access these. As we cannot provide ssh keys for every project, and project’s may have different members the acccess token offers a solution to this. To generate a personal access token navigate to your profile settings on GitLab and then on to “Access Tokens”.

_images/profile_settings.png

In the access token dialog give it a meaninful name, e.g. readthedocs, and select api as “scope”. Clicking on “Create Personal Access Tokens” will create a token - be sure to save this somewhere, as it will not be retrievable after you leave the page.

_images/accesstoken.png

Copy this token for later usage.

Adding Your Project to RTD

To add your project to RTD navigate to the RTD website and make sure you are logged in. You can log-in with your LDAP credentials. Given you are a member of the right group you will have the rights to create projects.

_images/RTD_Start.png

On the next page you can add a new project. For use with XFEL’s internal GitLab server select Import Manually.

_images/RTD_Manual_Project.png

You will then be asked to give a project name (please choose something appropriate for your project), as well as the Gitlab location.

_images/Public_Project.png

The location can be copied from GitLab on the project main page. Make sure you select the https address, not ssh:

_images/GIT_Link.png

In case your repository is private you will now need to insert the access token into this address. It should have the form: https://YOUR_LOGIN:YOUR_TOKEN@git.xfel.eu/…

Where “YOUR_LOGIN” is your gitlab user name. Upon confirmation this page may not directly redirect. This depends on how much there is to clone. You can however go back to the main page and then click on your projects:

_images/RTD_Project_List.png

In the Builds menu you can check the status of the documentation build for your project.

_images/RTD_Build_Status.png

Enabling GitLab Webhooks

Note that RTD complains that you do not yet have a webhook set-up for this project. This means that new documentation builds will not be trigger upon commits to your project’s git. We can remedy this in GitLab. Click on your project menu and select the Webhooks entry:

_images/GIT_Webhook_Menu.png

In the following dialog add the URL to XFEL’s RTD server in the appropriate field: https://in.xfel.eu/readthedocs/gitlab. Select for which events on GitLab a new documentation build should be triggered. For Projects it is recommended to select Push events, for devices it is recommended to select Tag events.

_images/GIT_Webhooks.png

After clicking Add Webhook the new webhook will appear in the bottom list. You can test it from there (will trigger a documentation build of your project).

Referencing across Projects

Assuming you have a conf.py configured to download the intersphinx bindings from XFEL’s read-the-docs server (Non-Karabo-Related Documentation) use the following syntax to link across hosted projects: :ref:`Karabo<karabo:introduction>`. This will create a link to the Karabo project’s introduction, referenced by its label introduction: Karabo. The project identifier, karabo in this case, corresponds to the URI-slug of the respective projects, with all dashes - replaced. You can deduce it from the url of the project. For

Karabo this is exflkarabo.desy.de/karabo/en/latest/, the slug is the part right after the server address, hence karabo.

Including in-code docs

Rendition of Karabo framework doc strings already works, this section describes how this can be achieved for doc strings in Karabo devices.

Steps required

An example Karabo devices including doc strings rendition is karaboDevices/puffin, viewing puffin files and performing the steps outlined below should get doc strings visible for your device project.

  • ensure that your conf.py includes the sphinx.ext.autodoc extension.
  • ensure that your sources are in the system path, e.g. by adding sys.path.append(‘../../src/’) to conf.py.
  • include in your index.rst’s toctree the name of the file, for puffin this is puffin_code.rst, defining which source files should be searched for doc strings to render. Puffin currently renders only strings from Puffin.py, which makes puffin_code very short and avoids any complication. If you need complication, then do it and update this documentation to share your knowledge. The directives in puffin_code are sufficient to render class and class method doc strings.
  • searching for doc strings in your project’s source requires importing Karabo framework files and these have to be made available to the virtual environment used by RTD. The Framework.git directive, see puffin’s requirements.rst below, must be inserted as-is into your project’s requirements.rst to make framework files available. Note that the robotDevice.git directive is required by puffin as Puffin.py inherits from karaboDevices/RobotDevice, this file must also be made available and your project may have similar dependencies.
sphinx==1.4.5
pint
git+https://git.xfel.eu/gitlab/Karabo/rtd-conf-py.git
slumber
breathe
numpy
matplotlib
git+https://github.com/enthought/traits.git
git+https://xfel.redmine:K9Sss5CmWtQ_nbx3gyt2@git.xfel.eu/gitlab/Karabo/Framework.git@master#egg=karabo&subdirectory=src/pythonKarabo
git+https://xfel.redmine:K9Sss5CmWtQ_nbx3gyt2@git.xfel.eu/gitlab/karaboDevices/robotDevice.git
lxml

It is not recommended to select the “Use system packages” option in (Admin > Advanced Settings), if a different version for one of the (internal) dependencies is required. e.g. sphinx 1.4.5 or sphinx-rtd-theme 0.4.3.

_images/use_system_packages.png

How To Document

Note

Always start a file with reference to itself. E.g the first lines of this file look like this:

.. _project/howto_document:

***************
How To Document
***************

In order to allow proper cross-referencing later, use one of the following pre-fixes:

  • framework/ - For all framework related documenation
  • devices/ - For all device related documenation
  • projects/ - For documentation about karabo projects or setups

Headers

Only use one top header (section header) per file.

Top headers use stars (“*”) as surrounding. Sub-headers are underlined by “=”, “+”, “_” and “^” in this order.

Sub-Header

Sub-Sub Header
Sub-Sub-Sub Header
Headers
=======

Sub-Header
----------

Sub-Sub Header
++++++++++++++

Sub-Sub-Sub Header

Paragraphs

This text reflects a regular paragraph. Use the same indentation and separate text by adding one or more blank lines.

Do not use more than 80 characters per line.

Inline Markup

Inline markup should go like this: emphasis, strong emaphasis, code related. Escaping is sometimes needed, use a backslash if you want to show e.g. *, \, `.

Always use double backticks if you want to refer to a class or function, like: void foo()

Inline markup should go like this: *emphasis*, **strong emaphasis**,
``code related``. Escaping is sometimes needed, use a backslash if you want
to show e.g. \*, \\, \`.

Always use double backticks if you want to refer to a class or function, like:
``void foo()``

Lists

  • Bulleted item
  • Bulleted item
    • Nested bulleted item (watch the blank line)
    • Nested bulleted item
  • Bulleted item
  1. Numbered item
  2. Numbered item
    1. Nested numbered item (watch the blank line)
    2. Nested numbered item
  3. Numbered item 3
  1. Explicit item
  2. Explicit item
    1. Nested explicit item
    2. Nested explicit item
  3. Explicit item
* Bulleted item
* Bulleted item

  * Nested bulleted item (watch the blank line)
  * Nested bulleted item

* Bulleted item


#. Numbered item
#. Numbered item

   #. Nested numbered item (watch the blank line)
   #. Nested numbered item

#. Numbered item 3


1. Explicit item
2. Explicit item

   a. Nested explicit item
   b. Nested explicit item

3. Explicit item

Special Directives

Topic title

This is a topic. Something that highlights in a box.

See also

This is a seealso.

Note

This is a note.

Warning

This is a warning.

.. topic:: Topic title

   This is a topic. Something that highlights in a box.

.. seealso::

   This is a seealso.

.. note::

   This is a note.

.. warning::

   This is a warning.

.. todo::

   This is a todo note.

.. ifconfig:: includeDevInfo is True

   This is information that is very detailed and can be switched off during
   rendering.

Tables

  • Simple tables are formatted like so:
A B A and B
False False False
True False False
False True False
True True True
=====  =====  =======
  A      B    A and B
=====  =====  =======
False  False  False
True   False  False
False  True   False
True   True   True
=====  =====  =======
  • Complex tables are formatted like so:
Title 1 Title 2
Some entry Single row
Some other entry Split row
Split row
+------------------+-------------------------------------------------------+
|**Title 1**       |**Title 2**                                            |
+------------------+-------------------------------------------------------+
|Some entry        |Single row                                             |
+------------------+-------------------------------------------------------+
|Some other entry  |Split row                                              |
|                  +-------------------------------------------------------+
|                  |Split row                                              |
+------------------+-------------------------------------------------------+
  • Tables from csv format can be imported like so:
.. csv-table:: Table Title
   :file: myfile.csv

Code

Code blocks are initiated by

@Slot
def foo(self):
    """Does nothing"""
    pass
KARABO_REGISTER_SLOT(foo);
void foo() {
    // Does nothing
}
 .. code-block:: Python

@Slot
def foo(self):
    """Does nothing"""
    pass
KARABO_REGISTER_SLOT(foo);
void foo() {
    // Does nothing
}

Images and Figures

To add an image use:

_images/darthvader.jpg
alternate text

Figures are like images but with a caption

.. image:: _images/darthvader.jpg

.. figure:: _images/xfel.jpg
    :align: center
    :height: 100px
    :alt: alternate text
    :figclass: align-center

    Figures are like images but with a caption

Graphs

Drawing of graphs is also supported:

Examples

digraph {
   "From" -> "To";
}
.. graphviz::

   digraph {
      "From" -> "To";
   }
digraph example {
"device1" [shape=circle, style=filled, fillcolor=green]
"device2" [shape=circle, style=filled, fillcolor=orange]
"broker"  [shape=box, height=2, style=filled, fillcolor=gray]

"device1" -> "broker"
"device2" -> "broker"
}
.. digraph:: example

   "device1" [shape=circle, style=filled, fillcolor=green]
   "device2" [shape=circle, style=filled, fillcolor=orange]
   "broker"  [shape=box, height=2, style=filled, fillcolor=gray]

   "device1" -> "broker"
   "device2" -> "broker"

Math

\[n_{\mathrm{offset}} = \sum_{k=0}^{N-1} s_k n_k\]
.. math::

    n_{\mathrm{offset}} = \sum_{k=0}^{N-1} s_k n_k

Footnotes

Some text that requires a footnote [1] .

Footnotes

[1]Text of the first footnote.
Some text that requires a footnote [#f1]_ .

.. rubric:: Footnotes

.. [#f1] Text of the first footnote.

Indices and tables