Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[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

Merged
merged 6 commits into from
Jun 28, 2017
Merged

[MRG+1]: Use unicode #256

merged 6 commits into from
Jun 28, 2017

Conversation

larsoner
Copy link
Contributor

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.

@lesteve
Copy link
Member

lesteve commented Jun 27, 2017

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.

@larsoner
Copy link
Contributor Author

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?

@larsoner larsoner changed the title FIX: Use unicode MRG: Use unicode Jun 27, 2017
@larsoner
Copy link
Contributor Author

Okay, test added and CIs are happy.

Copy link
Member

@Titan-C Titan-C left a 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
Copy link
Member

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?

Copy link
Contributor Author

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

@@ -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:
Copy link
Member

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


fhindex.write(SPHX_GLR_SIG)
fhindex.flush()
with open(os.path.join(gallery_dir, 'index.rst'), 'wb') as fhindex:
Copy link
Member

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

@larsoner
Copy link
Contributor Author

Okay changed to use codecs.open and rebased.

However, whatever you merged has broken tests on my machine. Formerly nosetests sphinx_gallery/tests/test_gen_rst.py worked but now I get:

omar:sphinx-gallery larsoner$ nosetests sphinx_gallery/tests/test_gen_rst.py
.......EE....
======================================================================
ERROR: Test that failing examples are only executed until failing block
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/larsoner/anaconda/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
TypeError: test_fail_example() takes exactly 1 argument (0 given)

======================================================================
ERROR: Test if only examples matching pattern are executed
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/larsoner/anaconda/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
TypeError: test_pattern_matching() takes exactly 1 argument (0 given)

----------------------------------------------------------------------
Ran 13 tests in 5.049s

FAILED (errors=2)

@larsoner
Copy link
Contributor Author

Hmm AppVeyor and Travis are happy on upstream/master. I'll debug.

@larsoner
Copy link
Contributor Author

Okay CIs are happy, ready from my end.

@GaelVaroquaux GaelVaroquaux changed the title MRG: Use unicode [MRG+1]: Use unicode Jun 27, 2017
@GaelVaroquaux
Copy link
Contributor

LGTM. 👍 for merge once CI is green

@GaelVaroquaux
Copy link
Contributor

@Titan-C : merge?


def test_gen_dir_rst():
"""Test gen_dir_rst."""
_app = sphinx_compatibility._app
Copy link
Member

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?

Copy link
Member

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

Copy link
Member

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

@larsoner
Copy link
Contributor Author

Ahh yes, much cleaner thanks @Titan-C. Cherry-picked and CIs are happy.

@Titan-C Titan-C merged commit 3f593d3 into sphinx-gallery:master Jun 28, 2017
@Titan-C
Copy link
Member

Titan-C commented Jun 28, 2017

Merging. Thanks @Eric89GXL

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

Successfully merging this pull request may close these issues.

4 participants