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:


2.7.18 (default, Mar  8 2021, 13:02:45) 
[GCC 9.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: mer. 25 août 2021 12:53:11 CEST. 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  650 janv. 30  2017 ./.javascript.fr.rst
-rw-r--r-- 1 lilian lilian  578 janv. 30  2017 ./.javascript.en.rst
lrwxrwxrwx 1 lilian lilian   22 juin  16  2020 ./admin.rst -> /home/lilian/admin.rst
-rw-r--r-- 1 lilian lilian  739 févr.  8  2021 ./.special.rst
-rw-r--r-- 1 lilian lilian  12K mars  14 12:25 ./.blagues.rst
-rw-r--r-- 1 lilian lilian 2,4K avril 12 01:04 ./404.rst
-rw-r--r-- 1 lilian lilian 2,4K avril 12 01:04 ./403.rst
-rw-r--r-- 1 lilian lilian 8,7K avril 12 01:04 ./affaires-voyage.fr.rst
-rw-r--r-- 1 lilian lilian 1,8K avril 12 01:04 ./ace.rst
-rw-r--r-- 1 lilian lilian 2,5K avril 12 01:04 ./ace2.rst
-rw-r--r-- 1 lilian lilian 8,8K avril 12 01:04 ./A953.rst
-rw-r--r-- 1 lilian lilian  12K avril 12 01:04 ./beacon.en.rst
-rw-r--r-- 1 lilian lilian 8,6K avril 12 01:04 ./avoir.rst
-rw-r--r-- 1 lilian lilian  11K avril 12 01:04 ./autostop.fr.rst
-rw-r--r-- 1 lilian lilian 6,4K avril 12 01:04 ./apprendre-python.fr.rst
-rw-r--r-- 1 lilian lilian  14K avril 12 01:04 ./apk.fr.rst
-rw-r--r-- 1 lilian lilian  12K avril 12 01:04 ./apk.en.rst
-rw-r--r-- 1 lilian lilian 2,2K avril 12 01:04 ./blagues.fr.rst
-rw-r--r-- 1 lilian lilian 3,8K avril 12 01:04 ./bitbucket-features.fr.rst
-rw-r--r-- 1 lilian lilian 3,7K avril 12 01:04 ./bitbucket-features.en.rst
-rw-r--r-- 1 lilian lilian  15K avril 12 01:04 ./bin.fr.rst
-rw-r--r-- 1 lilian lilian  15K avril 12 01:04 ./bin.en.rst
-rw-r--r-- 1 lilian lilian  11K avril 12 01:04 ./beacon.fr.rst
-rw-r--r-- 1 lilian lilian  18K avril 12 01:04 ./blog-roll.fr.rst
-rw-r--r-- 1 lilian lilian  18K avril 12 01:04 ./blog-roll.en.rst
-rw-r--r-- 1 lilian lilian  23K avril 12 01:04 ./cv.en.rst
-rw-r--r-- 1 lilian lilian 4,3K avril 12 01:04 ./cookies.fr.rst
-rw-r--r-- 1 lilian lilian 3,0K avril 12 01:04 ./cookies.en.rst
-rw-r--r-- 1 lilian lilian  19K avril 12 01:04 ./conseils-visio.en.rst
-rw-r--r-- 1 lilian lilian  24K avril 12 01:04 ./conseils-email.en.rst
-rw-r--r-- 1 lilian lilian 4,0K avril 12 01:04 ./ga.en.rst
-rw-r--r-- 1 lilian lilian 3,6K avril 12 01:04 ./freedns.rst
-rw-r--r-- 1 lilian lilian 2,1K avril 12 01:04 ./folders.rst
-rw-r--r-- 1 lilian lilian  21K avril 12 01:04 ./firefox-extensions.fr.rst
-rw-r--r-- 1 lilian lilian  19K avril 12 01:04 ./firefox-extensions.en.rst
-rw-r--r-- 1 lilian lilian  15K avril 12 01:04 ./demo.rst
-rw-r--r-- 1 lilian lilian 3,9K avril 12 01:04 ./data-analysis-of-2-years-of-sms-2016-2017.fr.rst
-rw-r--r-- 1 lilian lilian 3,5K avril 12 01:04 ./data-analysis-of-2-years-of-sms-2016-2017.en.rst
-rw-r--r-- 1 lilian lilian 4,5K avril 12 01:04 ./iteri.fr.rst
-rw-r--r-- 1 lilian lilian 4,8K avril 12 01:04 ./iteri.en.rst
-rw-r--r-- 1 lilian lilian 9,0K avril 12 01:04 ./hitch-hiking.en.rst
-rw-r--r-- 1 lilian lilian 9,7K avril 12 01:04 ./graph.fr.rst
-rw-r--r-- 1 lilian lilian 9,5K avril 12 01:04 ./graph.en.rst
-rw-r--r-- 1 lilian lilian  11K avril 12 01:04 ./gnuplot.rst
-rw-r--r-- 1 lilian lilian 7,3K avril 12 01:04 ./gnuplot_embed.rst
-rw-r--r-- 1 lilian lilian 4,0K avril 12 01:04 ./ga.fr.rst
-rw-r--r-- 1 lilian lilian  684 avril 12 01:04 ./my-favorite-tools.en.rst
-rw-r--r-- 1 lilian lilian 3,6K avril 12 01:04 ./mount.fr.rst
-rw-r--r-- 1 lilian lilian 3,1K avril 12 01:04 ./mount.en.rst
-rw-r--r-- 1 lilian lilian  30K avril 12 01:04 ./mes-outils-preferes.fr.rst
-rw-r--r-- 1 lilian lilian 5,0K avril 12 01:04 ./mes-chansons-preferees.fr.rst
-rw-r--r-- 1 lilian lilian 5,1K avril 12 01:04 ./matlab-clones.fr.rst
-rw-r--r-- 1 lilian lilian 4,6K avril 12 01:04 ./matlab-clones.en.rst
-rw-r--r-- 1 lilian lilian 6,1K avril 12 01:04 ./math.rst
-rw-r--r-- 1 lilian lilian 6,0K avril 12 01:04 ./learn-python.en.rst
-rw-r--r-- 1 lilian lilian 3,0K avril 12 01:04 ./latexonwindows.fr.rst
-rw-r--r-- 1 lilian lilian 3,0K avril 12 01:04 ./latexonwindows.en.rst
-rw-r--r-- 1 lilian lilian 4,9K avril 12 01:04 ./js.fr.rst
-rw-r--r-- 1 lilian lilian 4,5K avril 12 01:04 ./js.en.rst
-rw-r--r-- 1 lilian lilian 1,3K avril 12 01:04 ./jokes.en.rst
-rw-r--r-- 1 lilian lilian 6,8K avril 12 01:04 ./jitsi.fr.rst
-rw-r--r-- 1 lilian lilian 6,2K avril 12 01:04 ./jitsi.en.rst
-rw-r--r-- 1 lilian lilian 4,4K avril 12 01:04 ./packing.en.rst
-rw-r--r-- 1 lilian lilian 8,4K avril 12 01:04 ./opendns.fr.rst
-rw-r--r-- 1 lilian lilian 7,8K avril 12 01:04 ./opendns.en.rst
-rw-r--r-- 1 lilian lilian 3,9K avril 12 01:04 ./online-gnu-octave.fr.rst
-rw-r--r-- 1 lilian lilian 3,6K avril 12 01:04 ./online-gnu-octave.en.rst
-rw-r--r-- 1 lilian lilian  23K avril 12 01:04 ./old_apk.fr.rst
-rw-r--r-- 1 lilian lilian  21K avril 12 01:04 ./old_apk.en.rst
-rw-r--r-- 1 lilian lilian 4,2K avril 12 01:04 ./ocaml.fr.rst
-rw-r--r-- 1 lilian lilian 4,2K avril 12 01:04 ./ocaml.en.rst
-rw-r--r-- 1 lilian lilian 5,7K avril 12 01:04 ./ocaml_ace.rst
-rw-r--r-- 1 lilian lilian  16K avril 12 01:04 ./NanoSyntax.rst
-rw-r--r-- 1 lilian lilian  14K avril 12 01:04 ./recherche.fr.rst
-rw-r--r-- 1 lilian lilian 9,1K avril 12 01:04 ./README.rst
-rw-r--r-- 1 lilian lilian 8,5K avril 12 01:04 ./python.rst
-rw-r--r-- 1 lilian lilian  19K avril 12 01:04 ./publis.fr.rst
-rw-r--r-- 1 lilian lilian  19K avril 12 01:04 ./publis.en.rst
-rw-r--r-- 1 lilian lilian 1,3K avril 12 01:04 ./plume-air-paris.fr.rst
-rw-r--r-- 1 lilian lilian 1,2K avril 12 01:04 ./plume-air-paris.en.rst
-rw-r--r-- 1 lilian lilian 7,6K avril 12 01:04 ./pgp.fr.rst
-rw-r--r-- 1 lilian lilian 4,7K avril 12 01:04 ./pgp.en.rst
-rw-r--r-- 1 lilian lilian  12K avril 12 01:04 ./pair-programming-tools.fr.rst
-rw-r--r-- 1 lilian lilian 3,4K avril 12 01:04 ./pair-programming-tools.en.rst
-rw-r--r-- 1 lilian lilian 6,7K avril 12 01:04 ./runblock.en.rst
-rw-r--r-- 1 lilian lilian 133K avril 12 01:04 ./rules-and-principles.en.rst
-rw-r--r-- 1 lilian lilian 1,6K avril 12 01:04 ./rss.rst
-rw-r--r-- 1 lilian lilian  16K avril 12 01:04 ./resume-de-mon-annee-2020.rst
-rw-r--r-- 1 lilian lilian  12K avril 12 01:04 ./resume-de-mon-annee-2019.rst
-rw-r--r-- 1 lilian lilian  16K avril 12 01:04 ./resume-de-mon-annee-2018.rst
-rw-r--r-- 1 lilian lilian  11K avril 12 01:04 ./resume-de-mon-annee-2017.rst
-rw-r--r-- 1 lilian lilian  13K avril 12 01:04 ./research.en.rst
-rw-r--r-- 1 lilian lilian 5,4K avril 12 01:04 ./star-wars.fr.rst
-rw-r--r-- 1 lilian lilian 6,1K avril 12 01:04 ./star-wars.en.rst
-rw-r--r-- 1 lilian lilian 3,5K avril 12 01:04 ./sphinxtabs.fr.rst
-rw-r--r-- 1 lilian lilian 3,3K avril 12 01:04 ./sphinxtabs.en.rst
-rw-r--r-- 1 lilian lilian  23K avril 12 01:04 ./slides.rst
-rw-r--r-- 1 lilian lilian  12K avril 12 01:04 ./skulpt.rst
-rw-r--r-- 1 lilian lilian  562 avril 12 01:04 ./sitemap.fr.rst
-rw-r--r-- 1 lilian lilian  512 avril 12 01:04 ./sitemap.en.rst
-rw-r--r-- 1 lilian lilian  908 avril 12 01:04 ./self-quantified.fr.rst
-rw-r--r-- 1 lilian lilian  16K avril 12 01:04 ./self-quantified.en.rst
-rw-r--r-- 1 lilian lilian 6,9K avril 12 01:04 ./runblock.fr.rst
-rw-r--r-- 1 lilian lilian 1,7K avril 12 01:04 ./todo.rst
-rw-r--r-- 1 lilian lilian 2,7K avril 12 01:04 ./time.rst
-rw-r--r-- 1 lilian lilian  32K avril 12 01:04 ./sublimetext.fr.rst
-rw-r--r-- 1 lilian lilian  29K avril 12 01:04 ./sublimetext.en.rst
-rw-r--r-- 1 lilian lilian 8,1K avril 12 01:04 ./stats-google-analytics.fr.rst
-rw-r--r-- 1 lilian lilian 8,6K avril 12 01:04 ./stats-google-analytics.en.rst
-rw-r--r-- 1 lilian lilian  26K avril 12 01:04 ./tutogit.fr.rst
-rw-r--r-- 1 lilian lilian  25K avril 12 01:04 ./tutogit.en.rst
-rw-r--r-- 1 lilian lilian 6,0K avril 12 01:04 ./try-ocaml.fr.rst
-rw-r--r-- 1 lilian lilian 6,0K avril 12 01:04 ./try-ocaml.en.rst
-rw-r--r-- 1 lilian lilian 9,3K avril 12 01:04 ./transifex.fr.rst
-rw-r--r-- 1 lilian lilian 8,0K avril 12 01:04 ./transifex.en.rst
-rw-r--r-- 1 lilian lilian 9,8K avril 12 01:04 ./trademarks.rst
-rw-r--r-- 1 lilian lilian  19K avril 12 01:04 ./top10.fr.rst
-rw-r--r-- 1 lilian lilian  25K avril 12 01:04 ./wakatime.fr.rst
-rw-r--r-- 1 lilian lilian  24K avril 12 01:04 ./wakatime.en.rst
-rw-r--r-- 1 lilian lilian 7,8K avril 12 01:04 ./vpn.fr.rst
-rw-r--r-- 1 lilian lilian  23K avril 12 01:04 ./visualstudiocode.fr.rst
-rw-r--r-- 1 lilian lilian  20K avril 12 01:04 ./visualstudiocode.en.rst
-rw-r--r-- 1 lilian lilian 2,7K avril 12 01:04 ./zotero.fr.rst
-rw-r--r-- 1 lilian lilian 2,6K avril 12 01:04 ./zotero.en.rst
-rw-r--r-- 1 lilian lilian 8,9K avril 12 01:04 ./wolfram.fr.rst
-rw-r--r-- 1 lilian lilian 8,9K avril 12 01:04 ./wolfram.en.rst
-rw-r--r-- 1 lilian lilian 3,8K avril 12 01:04 ./whatsnew.fr.rst
-rw-r--r-- 1 lilian lilian 3,7K avril 12 01:04 ./whatsnew.en.rst
lrwxrwxrwx 1 lilian lilian   19 avril 12 01:05 ./teaching.fr.rst -> enseignement.fr.rst
lrwxrwxrwx 1 lilian lilian   16 avril 12 01:05 ./research.fr.rst -> recherche.fr.rst
lrwxrwxrwx 1 lilian lilian   15 avril 12 01:05 ./recherche.en.rst -> research.en.rst
lrwxrwxrwx 1 lilian lilian   22 avril 12 01:05 ./packing.fr.rst -> affaires-voyage.fr.rst
lrwxrwxrwx 1 lilian lilian   26 avril 12 01:05 ./my-favorite-tools.fr.rst -> mes-outils-preferes.fr.rst
lrwxrwxrwx 1 lilian lilian   24 avril 12 01:05 ./mes-outils-preferes.en.rst -> my-favorite-tools.en.rst
lrwxrwxrwx 1 lilian lilian   23 avril 12 01:05 ./learn-python.fr.rst -> apprendre-python.fr.rst
lrwxrwxrwx 1 lilian lilian   14 avril 12 01:05 ./jokes.fr.rst -> blagues.fr.rst
lrwxrwxrwx 1 lilian lilian   15 avril 12 01:05 ./hitch-hiking.fr.rst -> autostop.fr.rst
lrwxrwxrwx 1 lilian lilian   15 avril 12 01:05 ./enseignement.en.rst -> teaching.en.rst
lrwxrwxrwx 1 lilian lilian   30 avril 12 01:05 ./ce-que-je-regarde-sur-youtube.en.rst -> what-i-watch-on-youtube.en.rst
lrwxrwxrwx 1 lilian lilian   12 avril 12 01:05 ./blagues.en.rst -> jokes.en.rst
lrwxrwxrwx 1 lilian lilian   19 avril 12 01:05 ./autostop.en.rst -> hitch-hiking.en.rst
lrwxrwxrwx 1 lilian lilian   19 avril 12 01:05 ./apprendre-python.en.rst -> learn-python.en.rst
lrwxrwxrwx 1 lilian lilian   14 avril 12 01:05 ./affaires-voyage.en.rst -> packing.en.rst
lrwxrwxrwx 1 lilian lilian   36 avril 12 01:05 ./what-i-watch-on-youtube.fr.rst -> ce-que-je-regarde-sur-youtube.fr.rst
-rw-r--r-- 1 lilian lilian  39K avril 12 07:55 ./ce-que-je-regarde-sur-youtube.fr.rst
-rw-r--r-- 1 lilian lilian  21K avril 13 12:01 ./teaching.en.rst
-rw-r--r-- 1 lilian lilian  21K avril 13 14:57 ./enseignement.fr.rst
-rw-r--r-- 1 lilian lilian 5,0K avril 13 15:05 ./coronavirus.en.rst
-rw-r--r-- 1 lilian lilian  38K avril 13 17:41 ./what-i-watch-on-youtube.en.rst
-rw-r--r-- 1 lilian lilian  61K avril 13 20:14 ./top10.en.rst
-rw-r--r-- 1 lilian lilian 2,2K avril 14 05:22 ./twitch.en.rst
-rw-r--r-- 1 lilian lilian 9,2K avril 14 05:22 ./pokemon.en.rst
-rw-r--r-- 1 lilian lilian 8,6K avril 14 05:22 ./pokemon.fr.rst
-rw-r--r-- 1 lilian lilian 3,1K avril 14 05:22 ./twitch.fr.rst
-rw-r--r-- 1 lilian lilian  12K avril 18 15:11 ./vieprivee.rst
-rw-r--r-- 1 lilian lilian  21K avril 18 15:11 ./conseils-visio.fr.rst
-rw-r--r-- 1 lilian lilian  28K avril 18 15:13 ./conseils-email.fr.rst
-rw-r--r-- 1 lilian lilian  27K avril 18 15:16 ./cv.fr.rst
-rw-r--r-- 1 lilian lilian  16K avril 18 15:21 ./journal-de-bord-pendant-confinement-coronavirus-2020.fr.rst
-rw-r--r-- 1 lilian lilian  23K mai    6 08:36 ./coronavirus.fr.rst
-rw-r--r-- 1 lilian lilian  13K août   8 21:22 ./index.en.rst
-rw-r--r-- 1 lilian lilian  14K août   8 21:23 ./index.fr.rst
-rw-r--r-- 1 lilian lilian  17K août  24 11:20 ./resume-de-mon-annee-2021.rst
-rw-r--r-- 1 lilian lilian 8,0K août  24 11:34 ./callme.fr.rst
-rw-r--r-- 1 lilian lilian 7,8K août  24 11:34 ./callme.en.rst
-rw-r--r-- 1 lilian lilian  32K août  25 12:40 ./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 }'
./pair-programming-tools.fr.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
./journal-de-bord-pendant-confinement-coronavirus-2020.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-----

iQIzBAABCgAdFiEE/DSleRq5aEZtX0W7LaPXUOHniXEFAmEmIRcACgkQLaPXUOHn
iXHEkA/7BFr4jc0TPZyxwEXPztKNdh3yKnImYRkJ8My5oYi+njCvhAtdFNGhQTBE
gYwuZ7jEDTwLBSNkNqnPEIay8J5y2K0N9x5Ubl5046fO5NpYBKu5HmnvTa/ZMY5H
r/2KLTlAdL2loPsojrTN3klc20PS7+Sls28kO8u35omCVBeIAd7o5BLtImsxnZlv
pnQyZqskFYheY65x+bs97MoT0Y182keDHNQ7q/EHOTNMQjHSRwMbBk9Yk/z1Rirj
hvmuIDCNPQ5uUM61gaOCluPYYDgdt1eAIg5EdJ5mrdBXobCsASq2likwicw+XlF5
1r6p4aMaQqByop9N7tONRKJ4C6wGyVoB6f1MbaDEHohVufjz2D2+mJobgjt7PGDV
4UcJvUPMPMiZJPhaTngTJGF6McXoNlqiNhZBQQ5+oGyajoWMWwe14e+Ig/Uz4iFF
T7h+NOAml7IGAI0/DBbYFTMjwB5fZa19U8X69dbE/7+Lh0/MHYJ/L+mp7atZWcBB
gGUaRFFAB7yBPb15GDtyP0FJjHkDWlr4tIQ+FiRwhFC7yvcdQp2hlkYe87/LR/3g
Yt947RyLQHgDQOLFaFTN9KPmwQuZHmRuaL33EItj/v3B9XUmmqIZVzrb+aEZikiq
lwqLJgiq/yCoFQZG/O921CVZSowbo4uVEQDqNqIE9W7FEyECxiM=
=iIzi
-----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 _ ' ')") :)"
cat: /home/lilian/current: Aucun fichier ou dossier de ce type

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

$ git status --porcelain
 M a-faire-avant-30-ans.rst
 M conf.py

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;.::c..dl  .xOko, ....xNMMM|
|MMMWd,;:c..kkc. ;;'. .okkKWMMMM|
|MMMMMX:';..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|
|MMMMMMMO:. ',,,,,. .. 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|
|MMMMMMMMMMMMMMMMMWKoc:'........';;,'.'cdddddOWMMMMMMMMMMMMMMMM|
|MMMMMMMMMMMMMMN0Ox:...;cclooooodxkxc,,,'...':xO0XWMMMMMMMMMMMM|
|MMMMMMMMMMMMWXl.  .;cccclx00000klc;.  c0000Ko.  :KWWMWWMMMMMMM|
|MMMMMMMMMMWOc,'''',:c:'.'cdddddc'.':lok00kdd:   .:ccc:c0MMMMMM|
|MMMMMMMMWKx;..'ccc:;;,...,;;;;;'..'xK00OOo;;'        ..dWMMMMM|
|MMMMMMMNd..':;:ccc,. .lkx;     ,dkO000xll,          :0XNMMMMMM|
|MMMMMMMXc. 'cccccc'  .dKOc''.  .ldo:;,'...  ;xkkkkkkKWMMMMMMMM|
|MMMMMMMMWOc;,,:ccc'  .dK0xdo,   .',,,'.  .';lddddxOXWMMMMMMMMM|
|MMMMMMMMMMW0:.'ccc'  .dK0000:     .dKO;  ;O0d.    .:KMMMMMMMMM|
|MMMMMMMMMMMMNkc;,..  .dK0000c  .cloOKO;  ;O0koll:. 'OMMMMMMMMM|
|MMMMMMMMMMMMMMNKk;.  .oOkO00c  ,kK000Oc..:xkkkxkd;.,OMMMMMMMMM|
|MMMMMMMMMMMMMMMMMWd. .;c:dO0:  'x00OO0Okkoc:;...,xXXWMMMMMMMMM|
|MMMMMMMMMMMMMMMMMWd.   ..;ol,  .:ooooooll,..,x000NMMMMMMMMMMMM|
|MMMMMMMMMMMMMMMMMNo.  ....,,.   ',,,,,,,,.  '0MMMMMMMMMMMMMMMM|
|MMMMMMMMMMMMMMWWWNo. .,c:.                  '0MMMMMMMMMMMMMMMM|
|MMMMMMMMMMMMMWx,,''',;:c:.  'oodddc.  .,,.  '0MMMMMMMMMMMMMMMM|
|MMMMMMMMMMMMMWl   .;cccc:.  ;00K00x'  ;xd;  'OMMMMMMMMMMMMMMMM|
|MMMMMMMMMMMMMMo.  .,::::;.  ;kOOOOd.  :OO:  'OMMMMMMMMMMMMMMMM|
|MMMMMMMMMMMMMMo    ... ..   .......   ,ol,  .OMMMMMMMMMMMMMMMM|
|MMMMMMMMMMMMMWk;;;.   .'''''''''',.   .,,.  'OWMMMMMMMMMMMMMMM|
|MMMMMMMMMMMMWNKOOOc. .cxdddddddddxl.        .kXNWMMMMMMMMMMMMM|
|MMMMMMMMMMMMWO;....   ........'''''.'',,,;;:codkKWMMMMMMMMMMMM|
|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) :
  2129	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
    Aug   Sep     Oct       Nov     Dec     Jan       Feb     Mar     Apr     May       Jun     Jul       Aug 
                                              .   .       .     .       o O                                     
    M                                             .   0 o             O .                                 .     
              .               .   .         o       o   . .   o     . . .                                     . 
    W           .       .           .             . O o       o .   .                                   .       
                                          .           o .       . .           .                                 
    F         .     .   .                     .     O .   .         O .                                         
              .   .       .               .   . .     . . .       . . o                                         

                                                                                          Less   . o O 0  More
 142: Total commits
   6: Days ( Feb 10 2021 - Feb 16 2021 ) - Longest streak excluding weekends       
   5: Days ( Apr  9 2021 - Apr 13 2021 ) - Longest streak including weekends       
   0: Days - 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.05.0

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…