Skip to content

Commit

Permalink
Merge pull request #1782 from osuchw/master
Browse files Browse the repository at this point in the history
Proposed fix for #1781
  • Loading branch information
jakevdp authored Nov 11, 2019
2 parents b98ab5b + ac5024c commit 1d80b59
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion altair/sphinxext/altairgallery.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def main(app):
if next_ex:
example['next_ref'] = "gallery_{name}".format(**next_ex)
target_filename = os.path.join(target_dir, example['name'] + '.rst')
with open(os.path.join(target_filename), 'w') as f:
with open(os.path.join(target_filename), 'w', encoding='utf-8') as f:
f.write(EXAMPLE_TEMPLATE.render(example))


Expand Down
5 changes: 3 additions & 2 deletions altair/sphinxext/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,16 @@ def get_docstring_and_rest(filename):
except AttributeError:
# this block can be removed when python 3.6 support is dropped
if node.body and isinstance(node.body[0], ast.Expr) and \
isinstance(node.body[0].value, ast.Str):
isinstance(node.body[0].value, (ast.Str, ast.Constant)):
docstring_node = node.body[0]
docstring = docstring_node.value.s
# python2.7: Code was read in bytes needs decoding to utf-8
# unless future unicode_literals is imported in source which
# make ast output unicode strings
if hasattr(docstring, 'decode') and not isinstance(docstring, six.text_type):
docstring = docstring.decode('utf-8')
lineno = docstring_node.lineno # The last line of the string.
# python3.8: has end_lineno
lineno = getattr(docstring_node, 'end_lineno', None) or docstring_node.lineno # The last line of the string.
# This get the content of the file after the docstring last line
# Note: 'maxsplit' argument is not a keyword argument in python2
rest = content.split('\n', lineno)[-1]
Expand Down

0 comments on commit 1d80b59

Please sign in to comment.