- Difficulty level: easy
- Time need to lean: 10 minutes or less
- Key points:
- Magic
%sessioninfo
shows the session information of all live kernels - Magic
%revisions
shows the git log messages of the current notebook if it is saved in a git repository
- Magic
Magic %sessioninfo
returns the session information of SoS and all the subkernels, which for example include version of the python interpreter and name and version of all imported modules for Python kernels, and the output of function sessionInfo()
for language R.
For example, if you have a new notebook and has not started any subkernel, the magic will only return session information for the SoS kernel:
After you have done some calculation in a subkernel,
The output would include additional information about the subkernel
Session information is not limited to version of the kernels and libraries and might include version of particular tools used for your workflow. Because there is no general way to determine what tools have been used and retrieve their information, you will have to collection such information manually.
To add additional session information to the output of %sessioninfo
magic, you will need to pass it to the %sessioninfo
magic explicitly as a variable. This variable should be a dictionary, with keys being the section headers and items being the session information, which can be a string, a list of strings, a dictionary, or a list of (key, value)
pairs.
For example, let us find the versions of two commands rsync
and awk
, and revision of this document in the variable sessioninfo
.
The information will be added automatically to the output of %sessioninfo
.
We have just showed an example that uses command git rev-parse HEAD
to append revision information to the output of %sessioninfo
. This was an very inconvenient way to do it because SoS provides a magic %revisions
, which displays revisions of the current document if the document is managed by git.
This magic accepts a few options. First, any options that are acceptable to command git log
can be passed to this magic. The most useful ones are options to limit the commits to display such as -n
(number of commits to output), --since=<date>
and --after=<date>
. For example, you can display five most recent commits with command
Another useful option is the --source
option that allows you to link the revision to specific URL (e.g. github). This option should be specified as a string with repo
, revision
, path
, and filename
interpolated as URL to the repository, revision id, and path and name of the document respectively. Here repo
is retrieved from the output of command git ls-remote --get-url origin
without trailing .git
(if available). Because SoS Notebook interpolates magics automatically, you should include variables in double braces.
For example, the github URL of a particular revision of this document is https://github.com/REPO/blob/REVISION/PATH/TO/FILENAME
so the command to link this document to its source on github would be:
Because github
is the most widely used git repository, we provide the aforementioned template by default if you specify option --source
without value. That is to say, if your document is hosted in github.com
, you can simply use
%revisions --source
to link revisions to github.
The links do not have to point to the source of the document. For example, because we always convert this document to HTML in another directory and display it on our homepage, we can link the revisions to the HTML version as follows:
And if you would like to display one or more links next to the revision number, you can do so with the --links
option: