Issue #1055 resolved

Cannot open config file in simple WebSupport example

Giovanni Bajo avatarGiovanni Bajo created an issue

Hello, I was trying the WebSupport in Sphinx, but I hit what it looks like a simple blocking bug. I prepared this simple build-docs.py script:

#!/usr/bin/env python
from sphinx.websupport import WebSupport
support = WebSupport(srcdir="docs", staticdir="static",
        builddir=".build", search="whoosh",
        docroot="docs", staticroot="static")
support.build()

but when I run it, I get this:

  File "[...]/lib/python2.7/site-packages/sphinx/config.py", line 199, in __init__
    f = open(config_file, 'rbU')
IOError: [Errno 2] No such file or directory: 'docs/conf.py'

It looks like the culprit is in sphinx/config.py:

       config = {}
        if dirname is not None:
            config_file = path.join(dirname, filename)
            config['__file__'] = config_file
            config['tags'] = tags
            olddir = os.getcwd()
            try:
                # we promise to have the config dir as current dir while the
                # config file is executed
                os.chdir(dirname)
                # get config source -- 'b' is a no-op under 2.x, while 'U' is
                # ignored under 3.x (but 3.x compile() accepts \r\n newlines)
                f = open(config_file, 'rbU')

Since it chdir inside the directory, config_file cannot work since it contains dirname. It has to be changed to filename.

I've attached a patch.

Comments (5)

  1. Takayuki Shimizukawa

    I think you need to specify absolute-path to srcdir instead of relative-path.

    Web application script (Flask in reference) that using WebSupport will be invoked from Apache, ngingx or other web server process. In this case, you should use the absolute path instead of relative-path.

  2. Giovanni Bajo

    It would be impossible to specify an absolute path in my setup, the application code gets relocated to different servers. But WebSupport could call absname() at any point, if it feels like it. In alternative, my patch fixes the issue.

  3. Takayuki Shimizukawa

    How is it by this method?

    from sphinx.websupport import WebSupport
    import os
    BASEDIR = os.path.dirname(os.path.abspath(__file__))
    bjoin = lambda *p: os.path.join(BASEDIR, *p)
    
    support = WebSupport(srcdir=bjoin("docs"), staticdir=bjoin("static"), ...
    
  4. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.