Re: [sphinx-users] First steps with Pyhton and Sphinx

2018-09-25 Thread c.buhtz
Dear Matthias,

thank you for your tips.

Let me ask the general question. Why do I have to name explicit a
module, function, method or member?

When using a tool like Sphinx I would assume that the tool scan all my
code (all py-files) and create the html-doc out of it depending on the
doc-strings. Automatic!

The Sphinx configuration feels to heavy at this point.

 On 2018-09-25 09:09 Matthias Geier
 wrote:
> Welcome to Python and Sphinx!
> 
> Your project setup looks good, there is only one thing where I see a
> potential problem (but I'm not sure):
> 
> You did include the option "napoleon_include_private_with_doc", but
> the function you are showing (_SetupLogging) is not a member function
> (i.e. it is not part of a class).
> The documentation just speaks of "member functions":
> http://www.sphinx-doc.org/en/master/usage/extensions/napoleon.html#confval-napoleon_include_private_with_doc
> 
> You may have to specify your "private" function explicitly:
> 
> .. autofunction:: _SetupLogging
> 
> But as I said, I'm not sure about this.
> 
> In order for other people here to reproduce your problem, it is
> typically easier if you provide a very minimal but fully working
> example.
> In your case you would only need one .py file (with only one
> function). You could include the "automodule" stuff directly in
> index.rst, not needing any more .rst file.
> And then you need a working conf.py, which you also should strip down
> to the bare minimum (that still works as it is).
> And you should specify in which directories the files are, as you
> already did.
> 
> You can include all this in the message (it's only a few lines per
> file), people can quickly copy this to some files and try it out for
> themselves.
> 
> You could also share your test project online, e.g. on a Github Gist
> or something similar, and provide just a link here.
> 
> But most importantly, oftentimes when you create a minimal version of
> your problem, you'll find the solution by yourself before even sharing
> it!
> 
> cheers,
> Matthias
> On Tue, Sep 25, 2018 at 12:55 AM  wrote:
> >
> > I have problems starting with Sphinx on my Python3 code.
> > I read some tutorials and think I understand it. I also looked in
> > some example code on GitHub (project: backintime).
> >
> > But in the result I see only the name of the main module, not more.
> > I use sphinx and python3.6 on Debian unstable.
> >
> > Because I saw it in an example I name the main module explicite. But
> > what I would expect is that Sphinx looking in each py-file by
> > itself.
> >
> > This is the folder and structure with some (not all) files
> >
> > .
> > ├── doc
> > │   ├── build
> > │   │   ├── doctrees
> > │   │   │   ├── environment.pickle
> > │   │   │   ├── feedybus.doctree
> > │   │   │   ├── index.doctree
> > │   │   │   └── modules.doctree
> > │   │   └── html
> > │   │   ├── feedybus.html
> > │   │   ├── genindex.html
> > │   │   ├── index.html
> > │   │   ├── modules.html
> > │   │   ├── objects.inv
> > │   │   ├── py-modindex.html
> > │   │   ├── search.html
> > │   │   ├── searchindex.js
> > │   │   ├── _sources
> > │   │   │   ├── feedybus.rst.txt
> > │   │   │   ├── index.rst.txt
> > │   │   │   └── modules.rst.txt
> > │   │   └── _static
> > │   │   ├── ajax-loader.gif
> > │   │   ├── alabaster.css
> > │   │   ├── basic.css
> > │   │   ├── comment-bright.png
> > │   │   ├── comment-close.png
> > │   │   ├── comment.png
> > │   │   ├── custom.css
> > │   │   ├── doctools.js
> > │   │   ├── documentation_options.js
> > │   │   ├── down.png
> > │   │   ├── down-pressed.png
> > │   │   ├── file.png
> > │   │   ├── jquery.js
> > │   │   ├── minus.png
> > │   │   ├── plus.png
> > │   │   ├── pygments.css
> > │   │   ├── searchtools.js
> > │   │   ├── underscore.js
> > │   │   ├── up.png
> > │   │   ├── up-pressed.png
> > │   │   └── websupport.js
> > │   ├── Makefile
> > │   └── source
> > │   ├── conf.py
> > │   ├── feedybus.rst
> > │   ├── index.rst
> > │   ├── modules.rst
> > │   ├── _static
> > │   └── _templates
> > ├── feedybus
> > │   ├── application.py
> > │   ├── basics.py
> > │   ├── config.py
> > │   ├── data.py
> > │   ├── entrieslistview.py
> > │   ├── fetchfeeds.py
> > │   ├── graphic
> > │   │   ├── bullet.svg
> > │   │   ├── checked.png
> > │   │   ├── exit.png
> > │   │   ├── ...etc...
> > │   ├── __init__.py
> > │   ├── __main__.py
> > │   ├── make.bat
> > │   ├── Makefile
> > │   ├── treeview.py
> > │   └── window.py
> > ├── Feedybus.sh
> >
> > This are IMO the relevant lines from conf.py
> >
> > import os
> > import sys
> > sys.path.insert(0, os.path.abspath('../..'))
> > # ...
> > extensions = [
> > 'sphinx.ext.autodoc',
> > 'sphinx.ext.napoleon',
> > 'sphinx.ext.intersphinx',
> > 

Re: [sphinx-users] Register additional visit/depart functions for existing nodes?

2018-09-25 Thread Matthias Geier
On Fri, Sep 21, 2018 at 5:10 PM Komiya Takeshi wrote:
>
> >Can I somehow derive a new node from an existing node without killing
> >the original visit/depart functions?
>
> How about subclassing a Translator class?
> You can get original implementation with calling super() function.

Thanks a lot Takeshi, I didn't think about that!

> And you can use custom translators with app.set_translator() API.

I tried it with a subclass of LaTeXTranslator and it works nicely.
One advantage is that I can use the "classes" attribute to influence
the behavior, very similar to how CSS classes influence the HTML
output.

However, I think there is one problem: Only one extension can set a
translator for a given output format, right?
What happens if some other extension also wants to set a translator for 'latex'?

Either way, as far as I've learned up to now, subclassing existing
node classes doesn't really work because the visit/depart methods of
the superclass cannot be used.
I've now decided to just wrap the existing node objects with a custom
node (trivially derived from docutils.nodes.Element). Such classes
don't create any HTML or LaTeX output on their own, so arbitrarily
many of them can be nested without adding stuff to the generated
output.

So instead of e.g. subclassing docutils.nodes.literal_block, I'm just
creating a literal_block node object and put it as (only) child into a
node of my custom class.
This calls my custom visit/depart methods immediately before/after the
visit/depart methods of literal_block. And that's exactly what I
needed.

In case anybody is interested, here's the code I've written to create
those nodes:
https://github.com/spatialaudio/nbsphinx/blob/cbb97918c7b4cd0960a644351402506077b35b9c/src/nbsphinx.py#L707-L762

If somebody has suggestions for improvements, please let me know!

cheers,
Matthias

> Thanks,
> Takeshi KOMIYA
> 2018年9月21日(金) 7:28 Matthias Geier :
> >
> > Dear Sphinx experts.
> >
> > I've asked this already a few years ago
> > (https://groups.google.com/forum/#!topic/sphinx-dev/0chv7BsYuW0) but I
> > didn't get an answer.
> >
> > Now I'm having a very similar problem again and I thought I'll try asking 
> > again.
> >
> > I know that I can create new nodes and register visit/depart functions
> > with app.add_node().
> >
> > But instead of a completely new node, I would like to use an existing
> > node, I just need additional custom visit/depart functions that are
> > called in addition to the original visit/depart functions.
> > In fact, I would like to get the original visit/depart functions for
> > HTML output and my own custom functions for LaTeX output.
> >
> > In my concrete case I would like to use docutils.nodes.container nodes
> > specifying a "classes" argument to select CSS classes that will be
> > used in the HTML renderer.
> > But for LaTeX output I need to add some more stuff in the visit/depart
> > functions.
> >
> > If I derive my own class from docutils.nodes.container and register it
> > with app.add_node(), the CSS classes are not added to the HTML output,
> > because apparently the original visit/depart functions are not
> > executed in that case.
> >
> > Can I somehow derive a new node from an existing node without killing
> > the original visit/depart functions?
> >
> > cheers,
> > Matthias

-- 
You received this message because you are subscribed to the Google Groups 
"sphinx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sphinx-users+unsubscr...@googlegroups.com.
To post to this group, send email to sphinx-users@googlegroups.com.
Visit this group at https://groups.google.com/group/sphinx-users.
For more options, visit https://groups.google.com/d/optout.