From 2d80fa97662ee9c188b1b7b1ae94384764c814e8 2013-12-22 08:12:01 From: marcmolla Date: 2013-12-22 08:12:01 Subject: [PATCH] solved pdf postprocess issue for nb with accented names --- diff --git a/IPython/nbconvert/postprocessors/pdf.py b/IPython/nbconvert/postprocessors/pdf.py index db00144..3086f19 100644 --- a/IPython/nbconvert/postprocessors/pdf.py +++ b/IPython/nbconvert/postprocessors/pdf.py @@ -18,9 +18,11 @@ import os import sys from IPython.utils.traitlets import Integer, List, Bool +from IPython.utils.encoding import DEFAULT_ENCODING from .base import PostProcessorBase + #----------------------------------------------------------------------------- # Classes #----------------------------------------------------------------------------- @@ -68,13 +70,22 @@ class PDFPostProcessor(PostProcessorBase): A boolean indicating if the command was successful (True) or failed (False). """ + #HACK: Encode file name with the correct encoding + # For Windows must be cp1252 (win application) and we cannot use + # encoding.DEFAULT_ENCODING or sys.stdin.encoding because input + # encoding could be different (cp437 in case of dos console) + if sys.platform == 'win32': + filename = filename.encode('cp1252') + else: + filename = filename.encode('utf-8') + #END_HACK command = [c.format(filename=filename) for c in command_list] 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: stdout = subprocess.PIPE if not self.verbose else None for index in range(count): - p = subprocess.Popen(command, stdout=stdout, stdin=null) + p = subprocess.Popen(command, stdout=stdout, stdin=null, shell=True) out, err = p.communicate() if p.returncode: if self.verbose: diff --git a/IPython/nbconvert/tests/test_nbconvertapp.py b/IPython/nbconvert/tests/test_nbconvertapp.py index cd67c3f..08873a0 100644 --- a/IPython/nbconvert/tests/test_nbconvertapp.py +++ b/IPython/nbconvert/tests/test_nbconvertapp.py @@ -213,6 +213,5 @@ class TestNbConvertApp(TestsBase): o,e = self.call('nbconvert --log-level 0 --to latex ' '"nb1_*" --post PDF ' '--PDFPostProcessor.verbose=True') - assert os.path.isfile('nb1_análisis.tex') - assert os.path.isdir('nb1_análisis_files') - assert os.path.isfile('nb1_análisis.pdf') + assert os.path.isfile(u'nb1_análisis.tex') + assert os.path.isfile(u'nb1_análisis.pdf')