From 045d48563a877e4be3c3ec462623d8242525054e 2014-07-22 23:02:01 From: Thomas Kluyver Date: 2014-07-22 23:02:01 Subject: [PATCH] Merge pull request #6067 from minrk/output_prefix Avoid duplicate extension in nbconvert --- diff --git a/IPython/nbconvert/nbconvertapp.py b/IPython/nbconvert/nbconvertapp.py index 2b6f14d..c105728 100755 --- a/IPython/nbconvert/nbconvertapp.py +++ b/IPython/nbconvert/nbconvertapp.py @@ -278,6 +278,11 @@ class NbConvertApp(BaseIPythonApplication): basename = os.path.basename(notebook_filename) notebook_name = basename[:basename.rfind('.')] if self.output_base: + # strip duplicate extension from output_base, to avoid Basname.ext.ext + if getattr(exporter, 'file_extension', False): + base, ext = os.path.splitext(self.output_base) + if ext == '.' + exporter.file_extension: + self.output_base = base notebook_name = self.output_base resources = {} resources['profile_dir'] = self.profile_dir.location @@ -293,11 +298,11 @@ class NbConvertApp(BaseIPythonApplication): exc_info=True) self.exit(1) else: - write_resultes = self.writer.write(output, resources, notebook_name=notebook_name) + write_results = self.writer.write(output, resources, notebook_name=notebook_name) #Post-process if post processor has been defined. if hasattr(self, 'postprocessor') and self.postprocessor: - self.postprocessor(write_resultes) + self.postprocessor(write_results) conversion_success += 1 # If nothing was converted successfully, help the user. diff --git a/IPython/nbconvert/tests/test_nbconvertapp.py b/IPython/nbconvert/tests/test_nbconvertapp.py index 24139a8..b9cbec3 100644 --- a/IPython/nbconvert/tests/test_nbconvertapp.py +++ b/IPython/nbconvert/tests/test_nbconvertapp.py @@ -127,6 +127,16 @@ class TestNbConvertApp(TestsBase): with open('notebook2.slides.html') as f: assert '/reveal.css' in f.read() + def test_output_ext(self): + """test --output=outputfile[.ext]""" + with self.create_temp_cwd(['notebook1.ipynb']): + self.call('nbconvert --log-level 0 --to python ' + 'notebook1.ipynb --output nb.py') + assert os.path.exists('nb.py') + + self.call('nbconvert --log-level 0 --to python ' + 'notebook1.ipynb --output nb2') + assert os.path.exists('nb2.py') def test_glob_explicit(self): """