jupyter / nbconvert

Jupyter Notebook Conversion
https://nbconvert.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
1.7k stars 562 forks source link

Is it possible to use ipython_kernel_config.py with nbconvert --execute? #1344

Open mgeier opened 3 years ago

mgeier commented 3 years ago

When I have a notebook using the IPython kernel, I would like nbconvert --execute to find and apply the settings from ipython_kernel_config.py (in the current directory), just like when executing it with JupyterLab.

Is there a way to achieve this?

This should of course not be limited to the IPython kernel. It would be great if nbconvert --execute could respect whatever configuration is relevant for the currently used kernel.

If this is not available out-of-the-box, is it possible to programmatically load the configuration for a given notebook (according to its kernel metadata) and pass that configuration to the nbconvert Python API?

MSeal commented 3 years ago

I believe the config should be loaded like other Jupyter applications because the CLI is inheriting from core and that has some config controls here: https://github.com/jupyter/jupyter_core/blob/master/jupyter_core/application.py#L64-L74. It's possible the config isn't passing over the boundary to nbclient? I'm not sure. Likely some trial and error would be needed to figure that out.

mgeier commented 3 years ago

Well I guess this mechanism leads to nbconvert_config.py to be used, right?

https://github.com/jupyter/jupyter_core/blob/master/jupyter_core/application.py#L96-L102

I assume this works fine (I haven't tried).

But my question is a different one. I'm interested in loading a configuration file based on the currently used kernel.

MSeal commented 3 years ago

Yeah that should be the mechanism.

But my question is a different one. I'm interested in loading a configuration file based on the currently used kernel.

Ahh. Is there a convention for this in Lab that you were referring to? If so I'm not too familiar outside of using local config file in the working directory.

mgeier commented 3 years ago

Is there a convention for this in Lab that you were referring to?

I don't know.

I just know that it works in Lab and doesn't work in nbconvert.

If so I'm not too familiar outside of using local config file in the working directory.

A local config file in the working directory is exactly what I need.

But I think it would be nice if we could support the whole config mechanism that's also used in Lab.

MSeal commented 3 years ago

But I think it would be nice if we could support the whole config mechanism that's also used in Lab.

I think one of the lab folks would need to chime in on what's normalized therein. Preferably the jupyter Application should be loading config in a consistent manner with the jupyter servers, so I'd rather see someone port logic over from lab to jupyter_core if there's a deviation in how the default config works that should be shared. In some cases lab has lab specific conventions that should stay with lab because they're no solidified or experimental.

@jasongrout @blink1073 could probably fill in more on this front than I know.

mgeier commented 3 years ago

Is it possible that this issue has been resolved in the meantime?

I've just tried it (via nbsphinx) and now all of a sudden the config file ipython_kernel_config.py (in the directory of the notebook) seems to be taken into account, which is great!

Has there been a change in nbclient to make that possible? Or in traitlets?

MSeal commented 3 years ago

I'm not sure to be honest, I was disconnected from these changes for a couple months though I didn't see any changes in nbclient I'd expect to impact traitlet loading ... traitlets has had more attention this year so it might have a different default behavior now for config loading.