diff --git a/IPython/core/shellapp.py b/IPython/core/shellapp.py index f46a0e5..afee8eb 100644 --- a/IPython/core/shellapp.py +++ b/IPython/core/shellapp.py @@ -172,6 +172,10 @@ class InteractiveShellApp(Configurable): exec_files = List(Unicode, config=True, help="""List of files to run at IPython startup.""" ) + exec_PYTHONSTARTUP = Bool(True, config=True, + help="""Run the file referenced by the PYTHONSTARTUP environment + variable at IPython startup.""" + ) file_to_run = Unicode('', config=True, help="""A file to be run""") @@ -354,8 +358,9 @@ class InteractiveShellApp(Configurable): """Run files from profile startup directory""" startup_dir = self.profile_dir.startup_dir startup_files = [] - if os.environ.get('PYTHONSTARTUP', False): - startup_files.append(os.environ['PYTHONSTARTUP']) + if self.exec_PYTHONSTARTUP: + if os.environ.get('PYTHONSTARTUP', False): + startup_files.append(os.environ['PYTHONSTARTUP']) startup_files += glob.glob(os.path.join(startup_dir, '*.py')) startup_files += glob.glob(os.path.join(startup_dir, '*.ipy')) if not startup_files: diff --git a/docs/source/interactive/reference.rst b/docs/source/interactive/reference.rst index 08db774..5de6e16 100644 --- a/docs/source/interactive/reference.rst +++ b/docs/source/interactive/reference.rst @@ -761,10 +761,10 @@ won't work:: IPython as your default Python environment ========================================== -Python honors the environment variable PYTHONSTARTUP and will execute at -startup the file referenced by this variable. If you put the following code at -the end of that file, then IPython will be your working environment anytime you -start Python:: +Python honors the environment variable :envvar:`PYTHONSTARTUP` and will +execute at startup the file referenced by this variable. If you put the +following code at the end of that file, then IPython will be your working +environment anytime you start Python:: from IPython.frontend.terminal.ipapp import launch_new_instance launch_new_instance() @@ -774,6 +774,11 @@ The ``raise SystemExit`` is needed to exit Python when it finishes, otherwise you'll be back at the normal Python '>>>' prompt. +You'll also need to set the config option +``InteractiveShellApp.exec_PYTHONSTARTUP = False``, otherwise IPython +will try to run :envvar:`PYTHONSTARTUP` again, sending it into an +infinite loop. + This is probably useful to developers who manage multiple Python versions and don't want to have correspondingly multiple IPython versions. Note that in this mode, there is no way to pass IPython any