Skip to content

Commit

Permalink
Merge pull request ipython#4732 from marcmolla/master
Browse files Browse the repository at this point in the history
Accents in notebook names and in command-line (nbconvert)
  • Loading branch information
minrk committed Jan 25, 2014
2 parents fca0c4b + b1a5261 commit dd59997
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
11 changes: 9 additions & 2 deletions IPython/nbconvert/postprocessors/pdf.py
Expand Up @@ -31,10 +31,10 @@ class PDFPostProcessor(PostProcessorBase):
How many times pdflatex will be called.
""")

latex_command = List(["pdflatex", "{filename}"], config=True, help="""
latex_command = List([u"pdflatex", u"{filename}"], config=True, help="""
Shell command used to compile PDF.""")

bib_command = List(["bibtex", "{filename}"], config=True, help="""
bib_command = List([u"bibtex", u"{filename}"], config=True, help="""
Shell command used to run bibtex.""")

verbose = Bool(False, config=True, help="""
Expand Down Expand Up @@ -69,6 +69,13 @@ def run_command(self, command_list, filename, count, log_function):
or failed (False).
"""
command = [c.format(filename=filename) for c in command_list]
#In windows and python 2.x there is a bug in subprocess.Popen and
# unicode commands are not supported
if sys.platform == 'win32' and sys.version_info < (3,0):
#We must use cp1252 encoding for calling subprocess.Popen
#Note that sys.stdin.encoding and encoding.DEFAULT_ENCODING
# could be different (cp437 in case of dos console)
command = [c.encode('cp1252') for c in command]
times = 'time' if count == 1 else 'times'
self.log.info("Running %s %i %s: %s", command_list[0], count, times, command)
with open(os.devnull, 'rb') as null:
Expand Down
22 changes: 22 additions & 0 deletions IPython/nbconvert/tests/files/nb1_análisis.ipynb
@@ -0,0 +1,22 @@
{
"metadata": {
"name": ""
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": []
}
],
"metadata": {}
}
]
}
22 changes: 22 additions & 0 deletions IPython/nbconvert/tests/test_nbconvertapp.py
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
"""Test NbConvertApp"""

#-----------------------------------------------------------------------------
Expand Down Expand Up @@ -183,3 +184,24 @@ def test_override_config(self):
self.call('nbconvert --log-level 0 --config="override.py"')
assert not os.path.isfile('notebook1.py')
assert os.path.isfile('notebook2.py')

def test_accents_in_filename(self):
"""
Can notebook names include accents?
"""
with self.create_temp_cwd(['nb*.ipynb']):
self.call('nbconvert --log-level 0 --to python nb1_*')
assert os.path.isfile(u'nb1_análisis.py')

@dec.onlyif_cmds_exist('pdflatex')
@dec.onlyif_cmds_exist('pandoc')
def test_filename_spaces(self):
"""
Generate PDFs if notebooks have an accent in their name?
"""
with self.create_temp_cwd(['nb*.ipynb']):
o,e = self.call('nbconvert --log-level 0 --to latex '
'"nb1_*" --post PDF '
'--PDFPostProcessor.verbose=True')
assert os.path.isfile(u'nb1_análisis.tex')
assert os.path.isfile(u'nb1_análisis.pdf')

0 comments on commit dd59997

Please sign in to comment.