Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows paths #86

Closed
evyasonov opened this issue Jul 31, 2023 · 0 comments · Fixed by #88
Closed

Windows paths #86

evyasonov opened this issue Jul 31, 2023 · 0 comments · Fixed by #88
Labels
bug Concrete, reproducible bugs ready Issues ready to be worked on

Comments

@evyasonov
Copy link

evyasonov commented Jul 31, 2023

It's better to use os.path module (os.path.basename(), os.path.splitext()) when handing path:

msg = jupyterlab_email._email.make_email(
    r"C:\Users\me\Desktop\plots.ipynb",
    None,
    'asd'
)
File jupyterlab_email\_email.py:43, in make_email(path, model, from_, type, template, code, subject, header, footer, also_attach, also_attach_pdf_template, also_attach_html_template, postprocessor, postprocessor_kwargs, logger)
     12 def make_email(
     13     path,
     14     model,
   (...)
     27     logger=None,
     28 ):
     29     """
     30     path        : path to notebook
     31     model       : notebook itself (in case deployment strips outputs or
   (...)
     41     postprocessor : run postprocessor on soup
     42     """
---> 43     name = path.rsplit("/", 1)[1].rsplit(".", 1)[0]
     44     model = nbformat.writes(nbformat.reads(json.dumps(model), 4))
     46     logger = logger or logging

IndexError: list index out of range

Also, who do you use system executor in run() while you execute a notebook from the code directly

import nbformat
import nbconvert
import nbconvert.preprocessors

with open(file_name) as f:
    notebook = nbformat.read(f, as_version=4)
nbconvert.preprocessors.ClearOutputPreprocessor().preprocess(notebook)

error_output = None
try:
    nbconvert.preprocessors.ExecutePreprocessor(timeout=None).preprocess(notebook)
except nbconvert.preprocessors.CellExecutionError as e:
    error_output = str(e)

exporter = nbconvert.HTMLExporter(template_name='lab', embed_images=True, exclude_input = opts.mode == 'report')
(body, resources) = exporter.from_notebook_node(notebook)
with open(output_path, mode='w', encoding='utf-8') as f:
    f.write(body)

? No color conversion is needed (or at least you can use --colors=nocolor option), no regex, no subprocess -- looks much simpler

@timkpaine timkpaine added ready Issues ready to be worked on bug Concrete, reproducible bugs labels Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Concrete, reproducible bugs ready Issues ready to be worked on
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants