From 4e7bf8daa9ab3271ff7df0b5c88eb8e555a9fba4 2017-06-07 14:52:54 From: Min RK Date: 2017-06-07 14:52:54 Subject: [PATCH] allow startup files in system-wide config dirs allows creating `/etc/ipython/startup/everybody.py` as a startup file for all IPython users on a system --- diff --git a/IPython/core/shellapp.py b/IPython/core/shellapp.py index e159fc4..4b855c3 100644 --- a/IPython/core/shellapp.py +++ b/IPython/core/shellapp.py @@ -8,12 +8,14 @@ launch InteractiveShell instances, load extensions, etc. # Distributed under the terms of the Modified BSD License. import glob +from itertools import chain import os import sys from traitlets.config.application import boolean_flag from traitlets.config.configurable import Configurable from traitlets.config.loader import Config +from IPython.core.application import SYSTEM_CONFIG_DIRS, ENV_CONFIG_DIRS from IPython.core import pylabtools from IPython.utils.contexts import preserve_keys from IPython.utils.path import filefind @@ -324,7 +326,9 @@ class InteractiveShellApp(Configurable): def _run_startup_files(self): """Run files from profile startup directory""" - startup_dir = self.profile_dir.startup_dir + startup_dirs = [self.profile_dir.startup_dir] + [ + os.path.join(p, 'startup') for p in chain(ENV_CONFIG_DIRS, SYSTEM_CONFIG_DIRS) + ] startup_files = [] if self.exec_PYTHONSTARTUP and os.environ.get('PYTHONSTARTUP', False) and \ @@ -336,9 +340,9 @@ class InteractiveShellApp(Configurable): except: self.log.warning("Unknown error in handling PYTHONSTARTUP file %s:", python_startup) self.shell.showtraceback() - - startup_files += glob.glob(os.path.join(startup_dir, '*.py')) - startup_files += glob.glob(os.path.join(startup_dir, '*.ipy')) + for startup_dir in startup_dirs[::-1]: + startup_files += glob.glob(os.path.join(startup_dir, '*.py')) + startup_files += glob.glob(os.path.join(startup_dir, '*.ipy')) if not startup_files: return