From dbf9f0b230f4acf80cd8f9f78183b480f24bc218 Mon Sep 17 00:00:00 2001 From: Rishabh Raj Date: Wed, 16 Apr 2014 17:38:55 +0530 Subject: [PATCH] Remove use of redundant variables, cleanup --- doc/ext/notebook.py | 17 +++++++---------- doc/ext/plot2rst.py | 2 +- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/doc/ext/notebook.py b/doc/ext/notebook.py index 5cefdef0..36c6fa1f 100644 --- a/doc/ext/notebook.py +++ b/doc/ext/notebook.py @@ -120,15 +120,13 @@ class Notebook(): return json.dumps(self.template, indent=2) -def python_to_notebook(example_file, notebook_dir, notebook_path): +def python_to_notebook(example_file, notebook_path): """Convert a Python file to an IPython notebook. Parameters ---------- example_file : str Path for source Python file. - notebook_dir : str - Directory for saving the notebook files. notebook_path : str Path for saving the notebook file (includes the filename). @@ -145,18 +143,17 @@ def python_to_notebook(example_file, notebook_dir, notebook_path): # Code and markdown written together in such a section are further # treated as different segments. Each cell has content from one # segment. - segment_has_begun = True docstring = False source = [] - modified_code = _remove_consecutive_duplicates(nb.code) + code = _remove_consecutive_duplicates(nb.code) - for line in modified_code: + for line in code: # A linebreak indicates a segment has ended. - # If the text segment had only comments, then source is blank, - # So, ignore it, as already added in cell type markdown + # If the text segment had only comments, ignore the blank source as + # already added in cell type markdown if line == '\n': - if segment_has_begun and source: + if source: # we've found text segments within the docstring if docstring: nb.add_cell(source, 'markdown') @@ -165,7 +162,7 @@ def python_to_notebook(example_file, notebook_dir, notebook_path): source = [] # if it's a comment elif line.strip().startswith('#'): - line = line.strip(' #') + line = line.lstrip(' #') nb.add_cell(line, 'markdown') elif line == '"""\n': if not docstring: diff --git a/doc/ext/plot2rst.py b/doc/ext/plot2rst.py index 07b54470..128cd4f9 100644 --- a/doc/ext/plot2rst.py +++ b/doc/ext/plot2rst.py @@ -374,7 +374,7 @@ def write_example(src_name, src_dir, rst_dir, cfg): else: shutil.copy(cfg.plot2rst_default_thumb, thumb_path) - python_to_notebook(example_file, notebook_dir, notebook_path) + python_to_notebook(example_file, notebook_path) def save_thumbnail(image, thumb_path, shape):