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

Cannot open config file in simple WebSupport example #1055

Closed
shimizukawa opened this issue Jan 3, 2015 · 5 comments
Closed

Cannot open config file in simple WebSupport example #1055

shimizukawa opened this issue Jan 3, 2015 · 5 comments
Labels

Comments

@shimizukawa
Copy link
Member

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:

#!python
#!/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:

#!python
       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.


@shimizukawa
Copy link
Member Author

From Giovanni Bajo on 2012-12-14 00:26:14+00:00

I've also added a https://bitbucket.org/birkenfeld/sphinx/pull-request/93.

@shimizukawa
Copy link
Member Author

From Takayuki Shimizukawa on 2012-12-14 01:13:03+00:00

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.

@shimizukawa
Copy link
Member Author

From Giovanni Bajo on 2012-12-14 08:12:18+00:00

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.

@shimizukawa
Copy link
Member Author

From Takayuki Shimizukawa on 2012-12-17 09:23:19+00:00

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"), ...

@shimizukawa
Copy link
Member Author

From Georg Brandl on 2012-12-30 17:03:10+00:00

Closes #1055: add changelog entry for 7228c0534f0c.

→ <>

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant