-
Notifications
You must be signed in to change notification settings - Fork 207
[MRG+1]: Use unicode #256
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
[MRG+1]: Use unicode #256
Conversation
Out of interest, do you get the error on Windows? I am wondering if this could be related to https://github.com/sphinx-gallery/sphinx-gallery/pull/254/files. It would be great to have a test or at least way to reproduce the problem. |
No, I'm on OSX. I agree it would be nice to test, but I suspect it has to do with parsing a folder / README.txt. I need to make a test from scratch for this case, right? |
Okay, test added and CIs are happy. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs a rebase as I recently merged a PR. I prefer using the codecs module and opening with utf-8 encoding, that using the binary open and having to remember to call the encoder or decoder down the line. It seems to work on my machine on Python 2 & 3
@@ -111,7 +111,7 @@ def test_extract_intro(): | |||
finally: | |||
os.remove(f.name) | |||
assert 'Docstring' not in result | |||
assert result == 'This is the description of the example which goes on and on, Óscar' | |||
assert result == 'This is the description of the example which goes on and on, Óscar' # noqa |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this comment doing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
turns off quality analysis / PEP8 in editors
sphinx_gallery/gen_rst.py
Outdated
@@ -399,8 +399,8 @@ def generate_dir_rst(src_dir, target_dir, gallery_conf, seen_backrefs): | |||
print(80 * '_') | |||
return "", [] # because string is an expected return type | |||
|
|||
with open(os.path.join(src_dir, 'README.txt')) as fid: | |||
fhindex = fid.read() | |||
with open(os.path.join(src_dir, 'README.txt'), 'rb') as fid: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer opening with codecs.open that binary
sphinx_gallery/gen_gallery.py
Outdated
|
||
fhindex.write(SPHX_GLR_SIG) | ||
fhindex.flush() | ||
with open(os.path.join(gallery_dir, 'index.rst'), 'wb') as fhindex: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer codecs.open with encoding='utf-8', then forget about the encode instruction down the line
Okay changed to use However, whatever you merged has broken tests on my machine. Formerly
|
Hmm AppVeyor and Travis are happy on |
Okay CIs are happy, ready from my end. |
LGTM. 👍 for merge once CI is green |
@Titan-C : merge? |
sphinx_gallery/tests/test_gen_rst.py
Outdated
|
||
def test_gen_dir_rst(): | ||
"""Test gen_dir_rst.""" | ||
_app = sphinx_compatibility._app |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious, can you explain why this is necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is because PR #250 uses a sphinx status iterator to reduce the amount of text sent to stdout when building the gallery in gen_dir_rst
. Sphinx changed the API for that iterator, thus there is also a compatibility layer provided by sphinx_compatibility
This function must use the pytest.fixture already
in place instead of repeating what is already implemented in there:
def test_gen_dir_rst(fakesphinxapp):
and in sphinx_gallery/tests/conftest.py change it to:
class FakeSphinxApp:
def __init__(self):
self.calls = collections.defaultdict(list)
def status_iterator(self, *args, **kwargs):
self.calls['status_iterator'].append(Params(args, kwargs))
for it in args[0]:
yield it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to work in my machine and travis is green. You can cherrypick from
https://github.com/Titan-C/sphinx-gallery/commits/Eric89GXL/unicode
Ahh yes, much cleaner thanks @Titan-C. Cherry-picked and CIs are happy. |
Merging. Thanks @Eric89GXL |
I had some ASCII encode/decode errors without this. I can try to come up with a test if necessary but it might take some time.