[IPython-dev] Getting the IPython path in a config file

Juergen Hasch python at elbonia.de
Sat Dec 20 08:29:46 EST 2014


Hi,
I am using IPython with custom templates, as well as pre- and postprocessors.

For custom templates I need to specify the path to the template, whereas pre- or postprocessors need to be in the Python
path.

Now I would like to keep the custom stuff together with the rest of the IPython data, so this is what my
"ipython_nbconvert_config.py" looks like:

	import sys
	import os
	ipythondir = sys.path[-1]
	extensions = os.path.join(ipythondir,'extensions')
	sys.path.append( extensions )

	c = get_config()

	c.Exporter.template_file = 'hide_input_output.tpl'
	c.Exporter.template_path = [ os.path.join(ipythondir,'templates') ]
	c.Exporter.preprocessors = ['codefolding.CodeFoldingPreprocessor', 'pymdpreprocessor.PyMarkdownPreprocessor' ]
	c.Exporter.postprocessors = ['embed.EmbedPostProcessor']

Is there a better way than to look at sys.path[-1] to get the path to the IPython directory inside a config file ?
I know I could set a custom IPYTHONDIR environment variable, but that kind of defeats the purpose of using the current
IPython directory.

  Juergen



More information about the IPython-dev mailing list