-
-
Notifications
You must be signed in to change notification settings - Fork 25.9k
[MRG] DOC, FIX: Support Python 2 and 3 in gen_rst.py #3777
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
Conversation
on my mac locale.getpreferredencoding(False) is US-ASCII and I can build the doc (unless something changed very recently). can you point to a file that contains non-ascii characters? |
There are plenty in comment lines. For example: the letter in the name and weird quotes. The reason of confusion is the version of Python. I tried to build docs in Python 3 and there is indeed a problem with decoding as he tries to access lines of file. In Python 2 it never occurs, because he doesn't try to decode anything at this point. (Is my explanation correct?) I might suggest to reload |
@larsmans our encoding expert what do you think? |
Better than |
Your patch, as-is, would break Sphinx on Python 2. |
@larsmans I realized that. I will change to |
Cool, ping me when you're done. |
Still struggling to get it working. I came to the conclusion that in Python 2 everything should be |
I just used conditions with But there are some problems in Python 2 unrelated to this patch (these errors appear on a clean build from master too.) They look like this (just several of them in total):
The problem was caused by Python 2 reusing fetched by Python 3 data files. So everything is all right, I think it can be merged. Ping @larsmans |
Hey, @larsmans I think it can be merged, please take a look. |
So the problem with
That is slightly annoying. |
I don't think the link is relevant. The problem is that in PY2 and PY3 default string types are different ( The best strategy (as I figured) is to work with default |
Interesting, then you ran into a different error on python 2 than I did. For me the reading worked fine using |
Initially I ran into problems using Python 3. So I modified |
The current solution is fine with me, but I'm not the expert ;) |
@nmayorov what about never decoding and just using byte strings ( |
@Titan-C, you want to follow that, for |
In theory you could do that, but it's going to cause a lot of conflicts in all sources interacting with I see it as follows: everything was working well except when encoding gets wrong, so let's fix it and leave the rest intact. |
@ogrisel could you consider merging this? It's a very small patch, I think it's totally fine. Perhaps it doesn't affect many people, but still a bug. And the project definitely doesn't need another forever hanging pull request (there are already too many imho). |
I think it's fine to merge, especially given that it's likely to change once we adopt sphinx-gallery. |
I rebased on master, fixed the minor merge conflict and removed a few trailing spaces in this branch. I regenerated the doc from scratch locally for both python2 and python3 and checked the examples gallery visually and everything seems to work fine AFAICT. For completeness here is a quick way to reproduce the original problem (only fails inside a python3 environment): mv examples{,_bak}
mkdir examples
cp examples_bak/{plot_digits_pipe.py,README.txt} examples
cd doc && make clean
LANG=fr_FR LC_CTYPE=fr_FR LC_ALL=fr_FR make html Output:
|
Thanks testing @lesteve. I will merge this branch and you fix. |
The encoding (if not specified) used by
open
in Python is platform dependent. On my Windows machine it iscp1251
, so I had troubles building docs with the example gallery because of that (some examples contain non-ASCII characters.)I think setting it explicitly to
utf-8
is a good thing.