Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider sphinx extension to render different versions of examples code #854

Closed
prjemian opened this issue Oct 26, 2020 · 13 comments
Closed

Comments

@prjemian
Copy link
Contributor

@rayosborn suggested:

Incidentally, I came across a Sphinx extension at https://sphinxcontrib-osexample.readthedocs.io/. It allows you to add code tabs, so if we agree on code examples, we can have a nexusformat tab and a h5py tab, which the users are free to click on. Perhaps @prjemian can say whether he thinks the extension could work for the NeXus manual. Having one API example follow the other would quickly make the documentation unwieldy, and mixing them up would make it incoherent. This might be the best solution, if it works, because the user could choose what to look at.

Originally posted by @rayosborn in #807 (comment)

@prjemian prjemian self-assigned this Oct 26, 2020
@prjemian
Copy link
Contributor Author

Examine this extension to see if can render different code examples. The web page says:

It’s intended to be used for displaying package manager examples. (e.g., apt install or dnf install).

then

Currently supported are: Debian, Ubuntu, Fedora, CentOS, OSX

but the example suggests the tab names are defined in .rst code.

@prjemian
Copy link
Contributor Author

This might lead us to a refactor of the code examples. One could imagine tabs for nexusformat, h5py, h5lite, NAPI-C, h5lite, NAPI-Fortran, h5lite, ... to create the same HDF5/NeXus data file.

@benajamin
Copy link
Contributor

benajamin commented Mar 22, 2021

The extension Ray linked to is derived from sphinxcontrib-examplecode, which claims to do what we want, while the former adapts the tabs idea to installation commands on different OS's (includes some checking that the commands are correct). Both of these extensions use the Sphinx.info() command, which was deprecated and removed long ago and they should be updated to use the logging API before we can use them. This is pretty easily fixed, but I haven't got the promised tabs to work properly yet.

@benajamin
Copy link
Contributor

Google says I should probably just use the Sphinx-tabs extension that does exactly what we want and is still being maintained.

@benajamin
Copy link
Contributor

benajamin commented Mar 22, 2021

I can get the Sphinx-tabs to work, but including text from other files (via .. include:: ) isn't working for me in the code-tabs. I have seen a claim that it works for at least one person, so I will keep trying.

@benajamin
Copy link
Contributor

Progress! include directives do work within the standard tabs and group-tabs, but not in code-tabs.

@benajamin
Copy link
Contributor

I think the recommended Sphinx code would be like:

.. tabs::
   .. group-tab:: Python (h5py)
      .. literalinclude:: BasicWriter_h5py.py
                :tab-width: 4
                :linenos:
                :language: python
   .. group-tab:: Python (nexusformat)
      .. literalinclude:: BasicWriter_nexusformat.py
                :tab-width: 4
                :linenos:
                :language: python
   .. group-tab:: C++
      .. literalinclude:: BasicWriter.cpp
                :tab-width: 4
                :linenos:
                :language: c++

Plus the sphinx-tabs needs to be installed on the compiling system and extensions = ['sphinx_tabs.tabs'] included in the conf.py.

@benajamin
Copy link
Contributor

@prjemian @PeterC-DLS
Do I need to inform the make system of the added dependency on the sphinx-tabs package (installable via pip)?

@prjemian
Copy link
Contributor Author

This dependency is registered in the /environment.yml file. See #899 where it is suggested to create an additional requirements.txt file when setting up a python environment that does not use conda.

@benajamin
Copy link
Contributor

benajamin commented Mar 23, 2021

Printing the html page will print the already open tabs, just as they appear in the browser window at that time.
Compiling a PDF shows firstly the list of tab headings, then each tab in sequence. It would be preferable to have the tab headings printed at the top of each corresponding tab-content, but decent doc-strings at the top of each code file are a functional substitute.
I think that these behaviours are appropriate for our usage and I will continue work implementing tabs for all of the python code in section 2.1.2 of the manual.

@benajamin
Copy link
Contributor

An implementation is underway in branch 854-code-tabs and I'm trying to include tabs (holding nexusformat and h5py based code) throughout section 2.1.2. of the manual and make it somewhat self-consistent in as minimal a fashion possible. This experience is already showing that the code examples being written in #807 lack the context to be useful and so any rewriting of the code examples will require considering the entire situation that the code examples are based on (i.e. the WONI instrument).

@prjemian
Copy link
Contributor Author

prjemian commented Jun 24, 2022

@prjemian prjemian modified the milestones: NXDL 2022.06, NXDL 2023.06 Jun 24, 2022
@prjemian
Copy link
Contributor Author

Closed with #1117

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants