def export(nb_path, filtering=True, filter_type="html"): """Exports notebook to PDF""" convert(nb_path, filtering=filtering, filter_type=filter_type) # create and display output HTML out_html = """ <p>Your file has been exported. Download it <a href="{}" target="_blank">here</a>! """.format(nb_path[:-5] + "pdf") display(HTML(out_html))
def export(nb_path, filtering=True, filter_type="html"): """Exports notebook to PDF FILTER_TYPE can be "html" or "tags" if filtering by HTML comments or cell tags, respectively. Args: nb_path (str): Path to iPython notebook we want to export filtering (bool, optional): Set true if only exporting a subset of nb cells to PDF filter_type (str, optional): "html" or "tags" if filtering by HTML comments or cell tags, respectively. """ convert(nb_path, filtering=filtering, filter_type=filter_type) # create and display output HTML out_html = """ <p>Your file has been exported. Download it <a href="{}" target="_blank">here</a>! """.format(nb_path[:-5] + "pdf") display(HTML(out_html))
def grade(ipynb_path, pdf, tag_filter, html_filter, script): # get path of notebook file base_path = os.path.dirname(ipynb_path) # glob tests test_files = glob('/home/tests/*.py') # get score result = grade_notebook(ipynb_path, test_files, script=script, ignore_errors=True) # output PDF if pdf: nb2pdf.convert(ipynb_path) elif tag_filter: nb2pdf.convert(ipynb_path, filtering=True, filter_type="tags") elif html_filter: nb2pdf.convert(ipynb_path, filtering=True, filter_type="html") return result
def grade(ipynb_path, pdf, tag_filter, html_filter, script): """ Grades a single ipython notebook and returns the score If no PDF is needed, set the pdf, tag_filter, and html_filter parameters to false. For .py files, set script to true. Args: ipynb_path (str): path to the ipython notebook pdf (bool): set true if no filtering needed to generate pdf tag_filter (bool): whether cells should be filtered by tag html_filter (bool): whether cells should be filtered by comments script (bool): whether the input file is a python script Returns: dict: a score mapping with values for each test, student score, and total points possible """ # get path of notebook file base_path = os.path.dirname(ipynb_path) # glob tests test_files = glob('/home/tests/*.py') # get score result = grade_notebook(ipynb_path, test_files, script=script, ignore_errors=True) # output PDF if pdf: nb2pdf.convert(ipynb_path) elif tag_filter: nb2pdf.convert(ipynb_path, filtering=True, filter_type="tags") elif html_filter: nb2pdf.convert(ipynb_path, filtering=True, filter_type="html") return result
def test_pdf_exists(self): convert(self._file) self.assertTrue(os.path.exists(self._output_path) and \ os.path.isfile(self._output_path))