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

Skip to content

Enforce UTF8 encoding because that is not default on Windows #254

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions sphinx_gallery/backreferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
from __future__ import print_function
import ast
import os

import platform
import sys

# Try Python 2 first, otherwise load from Python 3
try:
Expand Down Expand Up @@ -130,7 +131,15 @@ def identify_names(code):

def scan_used_functions(example_file, gallery_conf):
"""save variables so we can later add links to the documentation"""
example_code_obj = identify_names(open(example_file).read())

# https://github.com/sphinx-gallery/sphinx-gallery/issues/253
if (platform.system().lower().startswith('win') and
sys.version_info[0] >= 3):
open_kwargs = {'encoding': 'utf8'}
else:
open_kwargs = {}

example_code_obj = identify_names(open(example_file, **open_kwargs).read())
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 not going to work on Python 2.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm running Python2 and it seems to work

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... oh wait, I thought this was on my PR, never mind!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lesteve , what do you mean? The tests passed.

if example_code_obj:
codeobj_fname = example_file[:-3] + '_codeobj.pickle'
with open(codeobj_fname, 'wb') as fid:
Expand Down