Simpler system for running code after InteractiveShell is initialised #914

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

Comments

Projects
None yet
3 participants
@takluyver
Member

takluyver commented Oct 20, 2011

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

This comment has been minimized.

Show comment
Hide comment
@minrk

minrk Oct 21, 2011

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.

Member

minrk commented Oct 21, 2011

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

This comment has been minimized.

Show comment
Hide comment
@markvoorhies

markvoorhies Oct 30, 2011

Contributor

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.

Contributor

markvoorhies commented Oct 30, 2011

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

This comment has been minimized.

Show comment
Hide comment
@takluyver

takluyver Oct 30, 2011

Member

On the note of documentation, Min, is it simple to drop a brief README into
that folder, when we create it, explaining that files in there will be run,
and that they can use get_ipython() to get a reference to the
InteractiveShell object?

Member

takluyver commented Oct 30, 2011

On the note of documentation, Min, is it simple to drop a brief README into
that folder, when we create it, explaining that files in there will be run,
and that they can use get_ipython() to get a reference to the
InteractiveShell object?

@minrk

This comment has been minimized.

Show comment
Hide comment
@minrk

minrk Oct 30, 2011

Member

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

Member

minrk commented Oct 30, 2011

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

minrk added a commit to minrk/ipython that referenced this issue Oct 31, 2011

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

@minrk minrk closed this Nov 8, 2011

mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this issue Nov 3, 2014

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment