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

Documentation fails to build with Sphinx 1.2 #117

Closed
Arfrever opened this issue Feb 12, 2013 · 1 comment
Closed

Documentation fails to build with Sphinx 1.2 #117

Arfrever opened this issue Feb 12, 2013 · 1 comment

Comments

@Arfrever
Copy link

Since https://bitbucket.org/birkenfeld/sphinx/commits/471ff5bc89c6 documentation of restkit fails to build. Some paths became unicode strings. Operation with mixed str and unicode triggers implicit decoding of str to unicode with ASCII encoding (instead of UTF-8), which results in UnicodeDecodeError.

$ make html
...
Exception occurred:
  File "/tmp/restkit/doc/./sphinxtogithub.py", line 40, in process
    return text.replace( self.from_, self.to )
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 2822: ordinal not in range(128)
The full traceback has been saved in /tmp/sphinx-err-AEbScF.log, if you want to report the issue to the developers.
make: *** [html] Error 1
$ cat /tmp/sphinx-err-AEbScF.log
# Sphinx version: 1.2pre
# Python version: 2.7.3+
# Docutils version: 0.10 release
# Jinja2 version: 2.6
Traceback (most recent call last):
  File "/usr/lib64/python2.7/site-packages/sphinx/cmdline.py", line 238, in main
    app.build(force_all, filenames)
  File "/usr/lib64/python2.7/site-packages/sphinx/application.py", line 217, in build
    self.emit('build-finished', None)
  File "/usr/lib64/python2.7/site-packages/sphinx/application.py", line 350, in emit
    results.append(callback(self, *args))
  File "/tmp/restkit/doc/./sphinxtogithub.py", line 311, in sphinx_extension
    layout.process()
  File "/tmp/restkit/doc/./sphinxtogithub.py", line 175, in process
    handler.process()
  File "/tmp/restkit/doc/./sphinxtogithub.py", line 56, in process
    text = replacer.process( text )
  File "/tmp/restkit/doc/./sphinxtogithub.py", line 40, in process
    return text.replace( self.from_, self.to )
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 2822: ordinal not in range(128)

Patch:

--- doc/sphinxtogithub.py
+++ doc/sphinxtogithub.py
@@ -2,10 +2,22 @@

 import optparse as op
 import os
+import re
+import sphinx
 import sys
 import shutil


+def get_number(text):
+    m = re.match("[0-9]+", text)
+    if m:
+        return int(m.group(0))
+    else:
+        return 0
+
+def get_sphinx_version():
+    return tuple(get_number(x) for x in sphinx.__version__.split("."))
+
 class NoDirectoriesError(Exception):
     "Error thrown when no directories starting with an underscore are found"

@@ -51,10 +63,14 @@ class FileHandler(object):
     def process(self):

         text = self.opener(self.name).read()
+        if get_sphinx_version() >= (1, 2):
+            text = text.decode("utf-8")

         for replacer in self.replacers:
             text = replacer.process( text )

+        if get_sphinx_version() >= (1, 2):
+            text = text.encode("utf-8")
         self.opener(self.name, "w").write(text)

 class Remover(object):
@benoitc
Copy link
Owner

benoitc commented Feb 12, 2013

Thanks, looks good for me. can you send it as a pr ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants