How to get a list of warnings from sphinx compilation

后端 未结 2 668
北海茫月
北海茫月 2020-12-21 15:25

I am developing a sphinx based collaborative writing tool. Users access the web application (developed in python/Flask) to write a book in sphinx and compile it to pdf.

相关标签:
2条回答
  • 2020-12-21 15:34

    Assuming you used sphinx-quickstart to generate your initial Sphinx documentation set with a makefile, then you can use make to build docs, which in turn uses the Sphinx tool sphinx-build. You can pass the -w <file> option to sphinx-build to write warnings and errors to a file as well as stderr.

    Note that options passed through the command line override any other options set in the makefile and conf.py.

    0 讨论(0)
  • 2020-12-21 15:38

    sphinx.build_main() calls sphinx.cmdline.main(), which in turn creates a sphinx.application.Sphinx object. You could create such an object directly (instead of "making system calls within python"). Use something like this:

    import os
    from sphinx.application import Sphinx
    
    # Main arguments 
    srcdir = "/path/to/source"
    confdir = srcdir
    builddir = os.path.join(srcdir, "_build")
    doctreedir = os.path.join(builddir, "doctrees")
    builder = "html"
    
    # Write warning messages to a file (instead of stderr)
    warning = open("/path/to/warnings.txt", "w")
    
    # Create the Sphinx application object
    app = Sphinx(srcdir, confdir, builddir, doctreedir, builder, 
                 warning=warning)
    
    # Run the build
    app.build()
    
    0 讨论(0)
提交回复
热议问题