Dear all, 

I am trying to integrate Sphinx with SCons so that I can build the 
documentation in one command with the rest of a project [1]. In principle, the 
logic of Sphinx' build-system and SCons seems very similar:

1) Build up a dependency tree.
2) Execute what is needed. 

Essentially, I leave all the work in 2) to Sphinx, but I need to have a way to 
tell SCons about the sources after step 1) before actually invoking the build 
[2].

Since my main focus is on LaTeX, I hacked together a solution for that below. 
However, it would be nice to be able to output other formats and the same 
approach will certainly not work well for other builders. More importantly, my 
hack is probably not very safe to use forever...

So my question is whether there is a simpler way to access all dependencies and 
target files that Sphinx is aware of? Or whether it would be very hard to 
implement that? (I'm happy to contribute if I get some pointers) Something like 
Sphinx.get_dependencies()? And, similarly, Sphinx.get_targets()? The further 
internal structure of dependencies in Sphinx wouldn't matter -- all the hard 
work is left to Sphinx, I just need to know about the two sides of the 
dependency tree.

Cheerio,
Hans-Martin


[1] I am aware of Glenn Hutchings' efforts at 
https://bitbucket.org/zondo/sphinx-scons, but my idea is different -- I want to 
create a builder that can be used in a larger project whereas his script needs 
to be invoked stand-alone to make Sphinx' build scripts work cross-platform, as 
far as I can tell. 

[2] In particular, this is necessary for SCons' great VariantDir functionality 
to work.



Code:

Notes:
sphinx_inst is an instance of sphinx.application.Sphinx given the settings in 
conf.py
sphinx_dirs['sources_main'] and sphinx_dirs['targets_main'] are the paths to 
master_doc /  as defined in conf.py


    msg, length, iterator = sphinx_inst.env.update(sphinx_inst.config,
                                                   sphinx_inst.srcdir,
                                                   sphinx_inst.doctreedir,
                                                   sphinx_inst)
    sphinx_inst.info(msg)

    for docname in sphinx_inst.builder.status_iterator(iterator,
                                                      'reading sources... '):
        source.append(sphinx_dirs['sources_main'] + os.path.sep + docname +
                      sphinx_inst.config.source_suffix)

    for key in sphinx_inst.env.dependencies.keys():
        for dep in sphinx_inst.env.dependencies[key]:
            source.append(sphinx_dirs['sources_main'] + os.path.sep + dep)

    if sphinx_builder == 'latex':
        for tgt in sphinx_inst.env.config.latex_documents:
            target.append(sphinx_dirs['targets_main'] + os.path.sep + tgt[1])
        for key in sphinx_inst.env.images.keys():
            target.append(sphinx_dirs['targets_main'] + os.path.sep +
                          sphinx_inst.env.images[key][1])
        for tgt in ('fncychap.sty', 'Makefile', 'python.ist',
                    'sphinx.sty', 'sphinxhowto.cls', 'sphinxmanual.cls',
                    'tabulary.sty'):
            target.append(sphinx_dirs['targets_main'] + os.path.sep + tgt)

-- 
You received this message because you are subscribed to the Google Groups 
"sphinx-dev" group.
To post to this group, send email to sphinx-...@googlegroups.com.
To unsubscribe from this group, send email to 
sphinx-dev+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sphinx-dev?hl=en.

Reply via email to