spyder: Sphinx >=1.7.0 breaks help on Windows with a working dir on a drive different from the Python install drive

I faced this error while I was coding (typing) in the editor:

after closing it, the Spyder continues to its normal operation, I did not see any after effect.

Windows 10 - Python 3.6.4. The Spyder 3.2.7 was installed using Anaconda

2018-02-28_11-48-56

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 23 (13 by maintainers)

Most upvoted comments

This error message is fired in C:\Python27\Lib\site-packages\spyder\plugins\help.py when an exception in method run of class SphinxThread is handled by the try: except: blocks

This handling prevents the full traceback been shown in Spyder’s Internal terminal If you deactivate the try-except, the traceback appears:

>>> Traceback (most recent call last):
  File "c:\python27\lib\site-packages\spyder\plugins\help.py", line 301, in run
    html_text = sphinxify(doc['docstring'], context)
  File "c:\python27\lib\site-packages\spyder\utils\help\sphinxify.py", line 215, in sphinxify
    sphinx_app.build(None, [rst_name])
  File "c:\python27\lib\site-packages\sphinx\application.py", line 344, in build
    'outdir': path.relpath(self.outdir),
  File "c:\python27\lib\ntpath.py", line 528, in relpath
    % (path_prefix, start_prefix))
ValueError: path is on drive c:, start on drive E:     

The problem explained

  • Help section rendering uses Sphinx to convert rst text help to nice HTML.Sphinx logs this activity.
  • Part of this logging is in build method of class Sphinx c:\Python27\Lib\site-packages\sphinx\application.py circa line 343
                  logger.info(self.builder.epilog % {
                      'outdir': path.relpath(self.outdir),
                      'project': self.config.project
                  })
    
    Calls path.relpath ( os.path.relpath, in Windows defined in c:\python27\lib\ntpath.py ) with a single argument, some temporary dir usually in C:\
  • Being called with a single argument, relpath uses second argument’s default ‘.’, the python current working dir, say os.getcwd()
  • relpath fires a ValueError if called with paths from different drives. So if Spyder’s working dir (python current working dir) is not in drive C: , the exception is fired

Why once per session

This exception switches help display mode from richt text to plain text

plain text mode doesnt use Sphinx, so the problem dissapears unless you switch back to richt text mode.

SOLUTIONS

Being involved Sphinx, Spyder and ntpath.py, there are various options

  • Patch ntpath.py You could patch relpath in c:\python27\lib\ntpath.py , but this could be dangerous, other scripts can expect this exception been fired and handle it their own way.

  • Patch Sphinx (my choose) c:\Python27\Lib\site-packages\sphinx\application.py this way

###                logger.info(self.builder.epilog % {
###                    'outdir': path.relpath(self.outdir),
###                    'project': self.config.project
###                })
                # PATCH----------------------------------------------
                try:
                    the_relpath = path.relpath(self.outdir)
                except ValueError:
                    the_relpath = self.outdir
                logger.info(self.builder.epilog % {
                    'outdir': the_relpath,
                    'project': self.config.project
                })
                # PACH----------------------------------------------
  • Override relpath in Spyder In C:\Python27\Lib\site-packages\spyder\utils\help\sphinxify.py after line 32 , from sphinx.application import Sphinx insert this
#-----------------------------------------------------------#PATCH
real_osp_relpath = osp.relpath
def relpath_patched(path, start='.'):
    try:
        #print '**** relpath_patched OK ****',path
        return real_osp_relpath(path, start)
    except:
        #print '**** relpath_patched avoided exception ****',path
        return path
sphinx.application.os.path.relpath = relpath_patched
# or os.path.relpath = relpath_patched
#-----------------------------------------------------------#PATCH

Warning: Seems to override relpath in all Spyder app modules, not only in sphinx.application

I can confirm that all sphinx help is in fact broken (not showing the tutorial, etc. at all, and only showing plain text of docstrings for Sphinx 1.7.0+ on Windows under the above stated conditions. I can confirm Sphinx <= 1.6.6 is unaffected, so the location for now is to downgrade to that with conda install sphinx=1.6.6 from the Anaconda prompt (or just don’t use a working directory different from your Python/Anaconda install).

Thanks @dalthviz! I figured it was no longer a problem since no one else commented here.

Closing then.

@dalthviz, please investigate this one to see if it’s still a problem.

The code is on Drive D and Anaconda is installed on Drive C as Windows

Well there we go, which is why in my original followup, I asked

Is any of your code on another drive?

With that in hand, I was able to immediately reproduce it after switching my working directory (top right) to another drive, and then went to “Show tutorial” as you mentioned. Therefore, it seems likely the error has to do with use of a relative path (i.e. relative to the working dir) that attempts to access a location on another windows drive somewhere in the Sphinx call. From there, it shouldn’t be too difficult for someone to trace and fix. I appreciate your help!

@CAM-Gerlach

Aha, now it appeared again in the same session which I told you it has not appeared so far,

Now, it can be produced by the same process.

I don’t do anything different to create just this error. For the pattern, it appears after I run a code. if I don’t run a code it does not appear. The code is on Drive D and Anaconda is installed on Drive C as Windows. Everything including the code is identical before and after I upgraded the Sphinx.

Hmm, interesting. So it has happened over multiple previous sessions? Any pattern to that? Also, anything different in your current session—project location/working directory, files open, etc?

@VanitarNordic Thanks. Can you try downgrading to 1.6.6 (with conda install sphinx=1.6.6 and see if the error reoccurs? If not, can you try to locate the version that stops causing the problem? If you can’t find it, did you update anything else at the same time you updated Sphinx and first saw the problem?

The environment information is nice, but probably (hopefully) not necessary. What I asked for was what was stated in the new issue template that was apparently deleted/not followed, specifically your Qt and PyQt versions (from Help > About) and main dependencies (From Help > Dependencies > Copy to clipboard).