Testing the autorun Sphinx extension

In this page, I am testing an « experimental » feature of Sphinx, the autorun extension, which provides a .. runblock:: directive, to execute arbitrary code when generating a Sphinx-powered web-page.

Voir aussi

For a list of possibly useful Sphinx extensions, this page gives a good overview.

Examples

pycon

The first directive is ..runblock:: pycon. It uses the Python language, but accepts the syntax of an interactive interpreter session.

For instance, this snippet of code:

.. runblock:: pycon

    >>> for i in range(5):
    …  print(i)

will produce this output (raw included in the HTML web-page):


  File "<stdin>", line 2
    rint(i)
       ^
IndentationError: expected an indented block

We can also check which version of Python used by the extension:


3.6.8 (default, Aug 20 2019, 17:12:48) 
[GCC 8.3.0]

This .. runblock:: pycon directive is interesting to give example or short demonstration, when writing tutorials or documentation for instance.

But this runcode extension allows to do way more!


A few more interesting examples

.. runblock:: console

This directive accepts the syntax of a shell or Bash session, where the code starts with a *$ * symbol.

For instance, the current date and directory:

$ echo "Date: $(date). Directory: $(pwd)."
Date: dimanche 22 septembre 2019, 12:59:09 (UTC+0200). Directory: /home/lilian/web-sphinx.

We can also ask for a list of the reStructuredText files .rst (the source code of each of these web-pages) in the current directory:

$ ls -larth ./{,.}*.rst
-rw-r--r-- 1 lilian lilian  727 juil.  8  2016 ./.special.rst
-rw-r--r-- 1 lilian lilian  650 janv. 30  2017 ./.javascript.fr.rst
-rw-r--r-- 1 lilian lilian  578 janv. 30  2017 ./.javascript.en.rst
-rw-r--r-- 1 lilian lilian  15K nov.  27  2018 ./demo.rst
-rw-r--r-- 1 lilian lilian 4,5K nov.  27  2018 ./iteri.fr.rst
-rw-r--r-- 1 lilian lilian 4,8K nov.  27  2018 ./iteri.en.rst
-rw-r--r-- 1 lilian lilian  23K nov.  27  2018 ./slides.rst
-rw-r--r-- 1 lilian lilian  912 nov.  27  2018 ./self-quantified.fr.rst
-rw-r--r-- 1 lilian lilian  15K nov.  27  2018 ./self-quantified.en.rst
lrwxrwxrwx 1 lilian lilian   21 nov.  27  2018 ./TODO.rst -> /home/lilian/TODO.rst
lrwxrwxrwx 1 lilian lilian   22 nov.  27  2018 ./admin.rst -> /home/lilian/admin.rst
lrwxrwxrwx 1 lilian lilian   14 nov.  27  2018 ./affaires-voyage.en.rst -> packing.en.rst
lrwxrwxrwx 1 lilian lilian   19 nov.  27  2018 ./apprendre-python.en.rst -> learn-python.en.rst
lrwxrwxrwx 1 lilian lilian   19 nov.  27  2018 ./autostop.en.rst -> hitch-hiking.en.rst
lrwxrwxrwx 1 lilian lilian   30 nov.  27  2018 ./ce-que-je-regarde-sur-youtube.en.rst -> what-i-watch-on-youtube.en.rst
lrwxrwxrwx 1 lilian lilian   15 nov.  27  2018 ./enseignement.en.rst -> teaching.en.rst
lrwxrwxrwx 1 lilian lilian   15 nov.  27  2018 ./hitch-hiking.fr.rst -> autostop.fr.rst
lrwxrwxrwx 1 lilian lilian   23 nov.  27  2018 ./learn-python.fr.rst -> apprendre-python.fr.rst
lrwxrwxrwx 1 lilian lilian   15 nov.  27  2018 ./recherche.en.rst -> research.en.rst
lrwxrwxrwx 1 lilian lilian   22 nov.  27  2018 ./packing.fr.rst -> affaires-voyage.fr.rst
lrwxrwxrwx 1 lilian lilian   16 nov.  27  2018 ./research.fr.rst -> recherche.fr.rst
lrwxrwxrwx 1 lilian lilian   19 nov.  27  2018 ./teaching.fr.rst -> enseignement.fr.rst
lrwxrwxrwx 1 lilian lilian   36 nov.  27  2018 ./what-i-watch-on-youtube.fr.rst -> ce-que-je-regarde-sur-youtube.fr.rst
-rw-r--r-- 1 lilian lilian 2,4K janv.  6  2019 ./403.rst
-rw-r--r-- 1 lilian lilian 2,4K janv.  6  2019 ./404.rst
-rw-r--r-- 1 lilian lilian 8,8K janv.  6  2019 ./A953.rst
-rw-r--r-- 1 lilian lilian 2,5K janv.  6  2019 ./ace2.rst
-rw-r--r-- 1 lilian lilian 1,8K janv.  6  2019 ./ace.rst
-rw-r--r-- 1 lilian lilian 8,7K janv.  6  2019 ./affaires-voyage.fr.rst
-rw-r--r-- 1 lilian lilian 3,6K janv.  6  2019 ./alaskabombeh.en.rst
-rw-r--r-- 1 lilian lilian 3,3K janv.  6  2019 ./alaskabombeh.fr.rst
-rw-r--r-- 1 lilian lilian  20K janv.  6  2019 ./apk.en.rst
-rw-r--r-- 1 lilian lilian  23K janv.  6  2019 ./apk.fr.rst
-rw-r--r-- 1 lilian lilian 8,0K janv.  6  2019 ./avoir.rst
-rw-r--r-- 1 lilian lilian  11K janv.  6  2019 ./beacon.en.rst
-rw-r--r-- 1 lilian lilian  11K janv.  6  2019 ./beacon.fr.rst
-rw-r--r-- 1 lilian lilian  15K janv.  6  2019 ./bin.en.rst
-rw-r--r-- 1 lilian lilian  15K janv.  6  2019 ./bin.fr.rst
-rw-r--r-- 1 lilian lilian 3,7K janv.  6  2019 ./bitbucket-features.en.rst
-rw-r--r-- 1 lilian lilian 3,8K janv.  6  2019 ./bitbucket-features.fr.rst
-rw-r--r-- 1 lilian lilian  17K janv.  6  2019 ./blog-roll.en.rst
-rw-r--r-- 1 lilian lilian  17K janv.  6  2019 ./blog-roll.fr.rst
-rw-r--r-- 1 lilian lilian 7,5K janv.  6  2019 ./callme.en.rst
-rw-r--r-- 1 lilian lilian 7,4K janv.  6  2019 ./callme.fr.rst
-rw-r--r-- 1 lilian lilian  17K janv.  6  2019 ./ce-que-je-regarde-sur-youtube.fr.rst
-rw-r--r-- 1 lilian lilian 3,0K janv.  6  2019 ./cookies.en.rst
-rw-r--r-- 1 lilian lilian 4,3K janv.  6  2019 ./cookies.fr.rst
-rw-r--r-- 1 lilian lilian 3,5K janv.  6  2019 ./data-analysis-of-2-years-of-sms-2016-2017.en.rst
-rw-r--r-- 1 lilian lilian 3,9K janv.  6  2019 ./data-analysis-of-2-years-of-sms-2016-2017.fr.rst
-rw-r--r-- 1 lilian lilian  984 janv.  6  2019 ./dyndns.rst
-rw-r--r-- 1 lilian lilian  16K janv.  6  2019 ./firefox-extensions.en.rst
-rw-r--r-- 1 lilian lilian  18K janv.  6  2019 ./firefox-extensions.fr.rst
-rw-r--r-- 1 lilian lilian 2,1K janv.  6  2019 ./folders.rst
-rw-r--r-- 1 lilian lilian 3,6K janv.  6  2019 ./freedns.rst
-rw-r--r-- 1 lilian lilian 3,8K janv.  6  2019 ./ga.en.rst
-rw-r--r-- 1 lilian lilian 3,8K janv.  6  2019 ./ga.fr.rst
-rw-r--r-- 1 lilian lilian 7,2K janv.  6  2019 ./gnuplot_embed.rst
-rw-r--r-- 1 lilian lilian  11K janv.  6  2019 ./gnuplot.rst
-rw-r--r-- 1 lilian lilian 8,5K janv.  6  2019 ./graph.en.rst
-rw-r--r-- 1 lilian lilian 8,7K janv.  6  2019 ./graph.fr.rst
-rw-r--r-- 1 lilian lilian 4,6K janv.  6  2019 ./js.en.rst
-rw-r--r-- 1 lilian lilian 5,0K janv.  6  2019 ./js.fr.rst
-rw-r--r-- 1 lilian lilian 3,0K janv.  6  2019 ./latexonwindows.en.rst
-rw-r--r-- 1 lilian lilian 3,0K janv.  6  2019 ./latexonwindows.fr.rst
-rw-r--r-- 1 lilian lilian 6,1K janv.  6  2019 ./math.rst
-rw-r--r-- 1 lilian lilian 3,1K janv.  6  2019 ./mount.en.rst
-rw-r--r-- 1 lilian lilian 3,6K janv.  6  2019 ./mount.fr.rst
-rw-r--r-- 1 lilian lilian  16K janv.  6  2019 ./NanoSyntax.rst
-rw-r--r-- 1 lilian lilian 5,7K janv.  6  2019 ./ocaml_ace.rst
-rw-r--r-- 1 lilian lilian 3,1K janv.  6  2019 ./ocaml.en.rst
-rw-r--r-- 1 lilian lilian 3,1K janv.  6  2019 ./ocaml.fr.rst
-rw-r--r-- 1 lilian lilian 2,8K janv.  6  2019 ./online-gnu-octave.en.rst
-rw-r--r-- 1 lilian lilian 3,1K janv.  6  2019 ./online-gnu-octave.fr.rst
-rw-r--r-- 1 lilian lilian 7,6K janv.  6  2019 ./opendns.en.rst
-rw-r--r-- 1 lilian lilian 8,2K janv.  6  2019 ./opendns.fr.rst
-rw-r--r-- 1 lilian lilian 4,4K janv.  6  2019 ./packing.en.rst
-rw-r--r-- 1 lilian lilian 4,7K janv.  6  2019 ./pgp.en.rst
-rw-r--r-- 1 lilian lilian 7,6K janv.  6  2019 ./pgp.fr.rst
-rw-r--r-- 1 lilian lilian 1,2K janv.  6  2019 ./plume-air-paris.en.rst
-rw-r--r-- 1 lilian lilian 1,3K janv.  6  2019 ./plume-air-paris.fr.rst
-rw-r--r-- 1 lilian lilian  18K janv.  6  2019 ./publis.en.rst
-rw-r--r-- 1 lilian lilian  19K janv.  6  2019 ./publis.fr.rst
-rw-r--r-- 1 lilian lilian 7,0K janv.  6  2019 ./python.rst
-rw-r--r-- 1 lilian lilian 8,1K janv.  6  2019 ./README.rst
-rw-r--r-- 1 lilian lilian 1,3K janv.  6  2019 ./rss.rst
-rw-r--r-- 1 lilian lilian 6,9K janv.  6  2019 ./runblock.en.rst
-rw-r--r-- 1 lilian lilian 7,1K janv.  6  2019 ./runblock.fr.rst
-rw-r--r-- 1 lilian lilian  512 janv.  6  2019 ./sitemap.en.rst
-rw-r--r-- 1 lilian lilian  562 janv.  6  2019 ./sitemap.fr.rst
-rw-r--r-- 1 lilian lilian  11K janv.  6  2019 ./skulpt.rst
-rw-r--r-- 1 lilian lilian 5,5K janv.  6  2019 ./sparkline.rst
-rw-r--r-- 1 lilian lilian 3,3K janv.  6  2019 ./sphinxtabs.en.rst
-rw-r--r-- 1 lilian lilian 3,5K janv.  6  2019 ./sphinxtabs.fr.rst
-rw-r--r-- 1 lilian lilian 8,3K janv.  6  2019 ./stats-google-analytics.en.rst
-rw-r--r-- 1 lilian lilian 7,9K janv.  6  2019 ./stats-google-analytics.fr.rst
-rw-r--r-- 1 lilian lilian  29K janv.  6  2019 ./sublimetext.en.rst
-rw-r--r-- 1 lilian lilian  32K janv.  6  2019 ./sublimetext.fr.rst
-rw-r--r-- 1 lilian lilian 2,7K janv.  6  2019 ./time.rst
-rw-r--r-- 1 lilian lilian 1,5K janv.  6  2019 ./todo.rst
-rw-r--r-- 1 lilian lilian  17K janv.  6  2019 ./top10.en.rst
-rw-r--r-- 1 lilian lilian  18K janv.  6  2019 ./top10.fr.rst
-rw-r--r-- 1 lilian lilian 9,7K janv.  6  2019 ./trademarks.rst
-rw-r--r-- 1 lilian lilian 8,0K janv.  6  2019 ./transifex.en.rst
-rw-r--r-- 1 lilian lilian 9,3K janv.  6  2019 ./transifex.fr.rst
-rw-r--r-- 1 lilian lilian 4,9K janv.  6  2019 ./try-ocaml.en.rst
-rw-r--r-- 1 lilian lilian 4,8K janv.  6  2019 ./try-ocaml.fr.rst
-rw-r--r-- 1 lilian lilian  24K janv.  6  2019 ./tutogit.en.rst
-rw-r--r-- 1 lilian lilian  26K janv.  6  2019 ./tutogit.fr.rst
-rw-r--r-- 1 lilian lilian  17K janv.  6  2019 ./visualstudiocode.en.rst
-rw-r--r-- 1 lilian lilian  19K janv.  6  2019 ./visualstudiocode.fr.rst
-rw-r--r-- 1 lilian lilian 7,8K janv.  6  2019 ./vpn.fr.rst
-rw-r--r-- 1 lilian lilian  16K janv.  6  2019 ./what-i-watch-on-youtube.en.rst
-rw-r--r-- 1 lilian lilian 3,7K janv.  6  2019 ./whatsnew.en.rst
-rw-r--r-- 1 lilian lilian 3,8K janv.  6  2019 ./whatsnew.fr.rst
-rw-r--r-- 1 lilian lilian 8,9K janv.  6  2019 ./wolfram.en.rst
-rw-r--r-- 1 lilian lilian 8,9K janv.  6  2019 ./wolfram.fr.rst
-rw-r--r-- 1 lilian lilian 2,6K janv.  6  2019 ./zotero.en.rst
-rw-r--r-- 1 lilian lilian 2,7K janv.  6  2019 ./zotero.fr.rst
-rw-r--r-- 1 lilian lilian  11K janv. 10  2019 ./resume-de-mon-annee-2017.rst
-rw-r--r-- 1 lilian lilian 9,5K févr.  6  2019 ./vieprivee.rst
-rw-r--r-- 1 lilian lilian  19K mars   5  2019 ./wakatime.fr.rst
-rw-r--r-- 1 lilian lilian  18K mars   5  2019 ./wakatime.en.rst
-rw-r--r-- 1 lilian lilian  26K avril 19 10:14 ./cv.fr.rst
-rw-r--r-- 1 lilian lilian  23K avril 19 10:14 ./cv.en.rst
-rw-r--r-- 1 lilian lilian  12K juil.  2 17:57 ./research.en.rst
-rw-r--r-- 1 lilian lilian  13K juil.  2 17:57 ./recherche.fr.rst
-rw-r--r-- 1 lilian lilian  16K août   7 10:23 ./resume-de-mon-annee-2018.rst
-rw-r--r-- 1 lilian lilian 8,5K août  26 10:14 ./hitch-hiking.en.rst
-rw-r--r-- 1 lilian lilian 9,6K août  26 10:15 ./autostop.fr.rst
-rw-r--r-- 1 lilian lilian  14K août  27 00:33 ./projects.en.rst
-rw-r--r-- 1 lilian lilian 8,2K août  27 00:33 ./index.en.rst
-rw-r--r-- 1 lilian lilian  32K août  27 00:33 ./projects.fr.rst
-rw-r--r-- 1 lilian lilian 8,7K août  27 00:43 ./index.fr.rst
-rw-r--r-- 1 lilian lilian  16K août  27 00:45 ./teaching.en.rst
-rw-r--r-- 1 lilian lilian  16K août  27 00:48 ./enseignement.fr.rst
-rw-r--r-- 1 lilian lilian 5,7K sept. 10 09:38 ./learn-python.en.rst
-rw-r--r-- 1 lilian lilian 6,1K sept. 10 09:38 ./apprendre-python.fr.rst
-rw-r--r-- 1 lilian lilian 8,8K sept. 10 09:41 ./resume-de-mon-annee-2019.rst
-rw-r--r-- 1 lilian lilian 4,6K sept. 10 09:53 ./matlab-clones.en.rst
-rw-r--r-- 1 lilian lilian 5,1K sept. 10 09:53 ./matlab-clones.fr.rst
-rw-r--r-- 1 lilian lilian  13K sept. 22 12:58 ./a-faire-avant-30-ans.rst

We can look for the 10 longest filenames of the reStructuredText files in the current directory:

$ for i in $(find -iname '*'.rst | sort); do echo "${#i} : $i" | sed s/'^\([0-9]\) '/'0\1 '/; done | sort | tail | awk '{ print $3 }'
./resume-de-mon-annee-2018.rst
./resume-de-mon-annee-2019.rst
./stats-google-analytics.en.rst
./stats-google-analytics.fr.rst
./what-i-watch-on-youtube.en.rst
./what-i-watch-on-youtube.fr.rst
./ce-que-je-regarde-sur-youtube.en.rst
./ce-que-je-regarde-sur-youtube.fr.rst
./data-analysis-of-2-years-of-sms-2016-2017.en.rst
./data-analysis-of-2-years-of-sms-2016-2017.fr.rst

We can also ask GPG to produce (on the fly) a signature of the current file (for more information about GPG, see pgp.html):

$ gpg --quiet -o - --armor --detach-sign runblock.en.rst
-----BEGIN PGP SIGNATURE-----

iQIzBAABCgAdFiEEvxBajcdUkbnW7axdAarNucEI+KAFAl2HU/0ACgkQAarNucEI
+KA9Kw/+IOL5q8CTGkMNR76KQ/Bo26mVwQ+XX+r1TErh0Y+XQV77seOcUQe2t5+7
VP1GTnJr17WJTeBxKaRadL9/Npf79FsvGo77kdPDEPaxH3QOBHhCXrrnIYJEVPVb
FGv8nVwX1xVBepH6bCtvoWlKZDgv5kxLI/Sw8YjFA6KISDy3ROE+G1EcBhbdQd3F
uorW6ZBRmASEF4YKfq58ml7Gkf8gNjCxijtVBVi9YGCIA731wNxW9UPzlZYz/u0C
wPFPq1YS3M8Hfg0EpVBsd57Kx3tTb3b6hmRTBUGG1r17iM6xYCRPK2nBQjO7UuaW
zXYp0OjMcMTxgRpMdatkLjVkzB+7PPNQYcQPOh94kfYU9GnxgvWWcrSKQEhHrwfn
7SbjIgu5TJx/WxwKlemqqe7ZyGjdlZYMgU4MnwsO45QSGV5v8Rg7KY8xLuCNlRZ8
OdVK5JYtPfInNVZhQeTd4eOaNGliUwG422srZV1jb6qU+EvJBCuiRPSLZQrI+oQv
CPf9oHm779J6VUckB2NgV4/1+rOu2tP4f+AXM2A7AjO7TbbzCauRKf1YBmUEMe+f
lSIziIBnrw8Z2PuiCWUgr1c8HJQ+1RPXYzU7JoXsWdJJjiMeWZ0hpjeZV5JRhbEp
RVNWcxEvL6TSg0I3JLRo0WDjuW+xqKLWp5ykrDY1IMVyVE8DCI8=
=fs8i
-----END PGP SIGNATURE-----

Other examples

figlet can print text in a nice « ASCII art » form:

$ figlet "Isn't  it  pretty  ?"
 ___           _ _      _ _                     _   _            ___ 
|_ _|___ _ __ ( ) |_   (_) |_    _ __  _ __ ___| |_| |_ _   _   |__ \
 | |/ __| '_ \|/| __|  | | __|  | '_ \| '__/ _ \ __| __| | | |    / /
 | |\__ \ | | | | |_   | | |_   | |_) | | |  __/ |_| |_| |_| |   |_| 
|___|___/_| |_|  \__|  |_|\__|  | .__/|_|  \___|\__|\__|\__, |   (_) 
                                |_|                     |___/        

My script bin/series.sh was conceived to automatically play the next episode for your current TV show, and it uses a ~/current file to know which folder to use. We can use it to display the TV show I am currently watching:

$ echo -e "These days, I am watching the TV show : $(basename "$(cat /home/lilian/current | tr _ ' ')") :)"
These days, I am watching the TV show : The Big Bang Theory :)

Current state of the git repository (shows which files are new (N), modified (M) or deleted (D)) :

$ git status --porcelain
?? todo_01-01-2020.sh

A stupid example with an elk:

$ cowthink -W 160 -f /usr/share/cowsay/cows/moose.cow "And you think this is funny?"
 ______________________________
( And you think this is funny? )
 ------------------------------
  o
   o   \_\_    _/_/
    o      \__/
           (oo)\_______
           (__)\       )\/\
               ||----w |
               ||     ||

We can go crazy, and try to display a picture in ASCII text :

$ convert ~/.link.ico jpg:- | jp2a -b - --size=31x20
+-------------------------------+
|MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM|
|MMMMMMMMMMWNNNNNNNNWMMMMMMMMMMM|
|MMMMMMMMMNk'.......ONNWMMMMMMMM|
|MMMMMMMWNc.;::;cxl;'..xWMMMMMMM|
|MMMMMWKl',;;lkkxc,'oxd;'dXXNMMM|
|MMMMNd.'::;.'::;.c0Ox:.   .lWMM|
|MMMN;.:cc..dl. .xOko; ....xNMMM|
|MMMWd,;:c..kkc. ;;'. .okkKWMMMM|
|MMMMMXc,;..x00, .l0.'Oc..'XMMMM|
|MMMMMMW0: .dO0,.k00,,kkkc'KMMMM|
|MMMMMMMMW: ,ck'.xkkxo;;;dNWMMMM|
|MMMMMMMMW; ..;. ,;;;' lMMMMMMMM|
|MMMMMMW0d,.:, .,,. .. lMMMMMMMM|
|MMMMMMWl 'cc, l0Kc :: lMMMMMMMM|
|MMMMMMMo .,,. ;oo, ll lMMMMMMMM|
|MMMMMMWO:. ',,,,,. .. lMMMMMMMM|
|MMMMMMNko. ;ccccc'    ;ONMMMMMM|
|MMMMMMNdcllodddxxxkOO0KKNMMMMMM|
|MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM|
|MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM|
+-------------------------------+

The same, even bigger (fyi, this image is the favicon of this website):

$ convert ~/.link.ico jpg:- | jp2a -b - --size=62x30
+--------------------------------------------------------------+
|MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM|
|MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM|
|MMMMMMMMMMMMMMMMMMMMMWXKKKKKKKKKKKKKKKNMMMMMMMMMMMMMMMMMMMMMMM|
|MMMMMMMMMMMMMMMMMMMWNO,...............xMMMMMMMMMMMMMMMMMMMMMMM|
|MMMMMMMMMMMMMMMMMMKoc:'........';;,'.'cdddddOWMMMMMMMMMMMMMMMM|
|MMMMMMMMMMMMMMN0Ox:...;cclooooodxkxc,;,'...':xO0XWMMMMMMMMMMMM|
|MMMMMMMMMMMMWNl.  .;cccclx00000klc;.  c0000Ko.  :KWWMWWMMMMMMM|
|MMMMMMMMMMWOc,'''';:c:'.'cdddddc'.':lok00kdd:   .:ccc:c0MMMMMM|
|MMMMMMMMWKx;..,ccc:;;,...,;;;;;'..,xK00OOo;;'        ..dWMMMMM|
|MMMMMMMNd..';;:ccc,. .okx;     ,dkO000xll,.         :0XNMMMMMM|
|MMMMMMMXc. 'cccccc'  .dKOc''.  .ldo:;,'...  ;xkkkkkkKWMMMMMMMM|
|MMMMMMMMWOc;,,:ccc'  .dK0xdo,  ..,,,,'.  .';lddddxOXWMMMMMMMMM|
|MMMMMMMMMMW0:.'ccc'  .dK0000c     .dKO;  ;O0d.    .:KMMMMMMMMM|
|MMMMMMMMMMMMNkc;,..  .dK0000c  .cloOKO;  ;O0koll:. 'OMMMMMMMMM|
|MMMMMMMMMMMMMMNKk;.  .oOkO00c  ,kK000Oc..:xkkkxkd;.,OMMMMMMMMM|
|MMMMMMMMMMMMMMMMWNd. .;c:dO0:  'x0OOO0kkkoc:;...,xXXWMMMMMMMMM|
|MMMMMMMMMMMMMMMMMWd.  ...;ol,  .:ooooooll;..,x000NMMMMMMMMMMMM|
|MMMMMMMMMMMMMMMMMNo.  ...',,.  .',,,,,,,,.  '0MMMMMMMMMMMMMMMM|
|MMMMMMMMMMMMMMWWWNo. .,c:.                  '0MMMMMMMMMMMMMMMM|
|MMMMMMMMMMMMMWx,,,'',;:c:.  'oooddl.  .,,.  '0MMMMMMMMMMMMMMMM|
|MMMMMMMMMMMMMWl   .;cccc:.  ;O0K0Kx'  ;xx;  'OMMMMMMMMMMMMMMMM|
|MMMMMMMMMMMMMMo.  .,::::;.  ;kOOOOd.  cOO:  'OMMMMMMMMMMMMMMMM|
|MMMMMMMMMMMMMMo    ......   .......   ,ol,  .OMMMMMMMMMMMMMMMM|
|MMMMMMMMMMMMMWk;;;.   .'''''''''',.   .,,.  'OWWMMMMMMMMMMMMMM|
|MMMMMMMMMMMMWNK00Oc. .cxxddddddddxl.        .xXNWMMMMMMMMMMMMM|
|MMMMMMMMMMMMNO;....   ........'''''..',,,;;:cldkKWMMMMMMMMMMMM|
|MMMMMMMMMMMMMNkoddxxkkkO000000KKKKXXXNNNNWWWMMMMMMMMMMMMMMMMMM|
|MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM|
|MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM|
|MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM|
+--------------------------------------------------------------+

A few statistics about this git repository:

$ echo "Number of commits per author (on this git repository) :"
$ git --no-pager shortlog -sn --all
Number of commits per author (on this git repository) :
  1750	Lilian Besson
     5	Lilian Besson (Naereen)
     1	Jill-Jênn Vie

A small calendar, showing in ASCII the active days in this git repository (with this other script, note that this web-page is a nice looking version of this ASCII « calendar »):

$ git-cal --ascii
    Sep   Oct     Nov     Dec       Jan     Feb     Mar       Apr     May     Jun       Jul     Aug       Sep 
              .       .             .       .                         .                                       . 
    M           .   .       .               . .   . .                         .                       .         
                .       .     o     O             . .   .                       .     .         .     .   .     
    W   .         .                   .     .                               .                   .   .           
            .     . .               .                                       .                                   
    F             o .                                           .                                               
                      .                             .     .                   .                   .             

                                                                                          Less   . o O 0  More
  60: Total commits
   4: Days ( Nov  7 2018 - Nov 12 2018 ) - Longest streak excluding weekends       
   3: Days ( Nov  7 2018 - Nov  9 2018 ) - Longest streak including weekends       
   1: Days ( Sep 22 2019 - Sep 22 2019 ) - Current streak                          

Adding support for another language: OCaml?

In the Sphinx configuration file, conf.py, we can easily add shortcuts to use this runblock extension with other languages.

First, we have to create an empty dictionary called autorun_languages:

autorun_languages = {}

Then, add a value truc (which has to be a valid command-line program, like gnuplot or ocaml) and truc_prefix_chars (size of the prefix) to enable a new directive .. code-block:: truc in all your reStructuredText document (in this project only):

# Add these two lines in your 'conf.py' file
autorun_languages['ocaml'] = u'ocaml -stdin'
autorun_languages['ocaml_prefix_chars'] = 2
autorun_languages['ocaml_input_language'] = 'utf_8'
autorun_languages['ocaml_output_language'] = 'utf_8'

.. runblock:: ocaml now works

With this trick, we can now include example of code snippet in OCaml:

# let rec f = function 0 -> 1 | n -> n *(f (n-1)) in
# print_int (f 11);;
# Printf.printf "\n        OCaml version %s\n" Sys.ocaml_version;;
39916800
        OCaml version 4.04.2

Pour plus de détails, cf. le code source de l’extension autorun.py.


A weird bug of pygments

This runblock extension uses the great pygments Python library to color the code.

Sometimes, I have seen the pygments or pygmentize command-line tool break completely, and the only bugfix I found was to manually delete the « experimental » support of pkg_resources in the pygments file plugin.py, by manually forcing pkg_resources = None (at line 41). It’s durty, but it fixes my bug…