Simpler system for running code after InteractiveShell is initialised #914

Closed
takluyver opened this Issue Oct 20, 2011 · 4 comments

3 participants

@takluyver
IPython member

A very common need for config is to run code after the InteractiveShell is initialised - e.g. to define extra magics or aliases, or to import modules. Currently, the user has to track down exec_lines in the config file, and put their code inside a string (i.e. it doesn't get syntax highlighted etc.), or save a file in a suitable place, and add it to exec_files.

I propose either:

  • A file in the profile directory which is automatically run in the shell if it is present, as an addition to the user-specified exec_files. Something like ipython_startup.py.
  • A directory, similar to the /etc/rcN.d/ folders on Linux, in which any files found are run in a predictable order (i.e. to allow prefixes 00-99 if desired). This would allow customisations to be easily distributed: download a file, drop it in your IPYTHONDIR/profile_default/startup/ directory, and an extra magic function will be available.
@minrk
IPython member

I am +1 on this. It's frustrating that we boast this new config system, but a lot of what people want has to be done through the ugly strings of code. I know we have Extensions and Plugins, but those are too heavyweight for what most people want.

In fact, this is quite trivial to implement see here for a working implementation, but we should get consensus before adding something like this.

@markvoorhies

Min's implementation (e80f7aa) works for me for defining local magic. Compared to finding and editing ipython_config.py, this is way easier to figure out. It might be nice to reference this in either the '%quickref' or '%magic' documentation so that it's easy to discover from an interactive session.

@takluyver
IPython member
@minrk
IPython member

@takluyver - yes, that would be easy. I'll do it before making a PR

@minrk minrk added a commit to minrk/ipython that referenced this issue Oct 31, 2011
@minrk minrk add startup_dir to profiles
Any .py or .ipy file in this directory will be run at startup.
Files are run in in lexicographical order, as described in #914
7c21f7c
@minrk minrk closed this Nov 8, 2011
@mattvonrocketstein mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this issue Nov 3, 2014
@minrk minrk add startup_dir to profiles
Any .py or .ipy file in this directory will be run at startup.
Files are run in in lexicographical order, as described in #914
778588b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment