diff --git a/IPython/core/application.py b/IPython/core/application.py index 1801627..af28133 100644 --- a/IPython/core/application.py +++ b/IPython/core/application.py @@ -44,6 +44,14 @@ else: "/etc/ipython", ] + +ENV_CONFIG_DIRS = [] +_env_config_dir = os.path.join(sys.prefix, 'etc', 'ipython') +if _env_config_dir not in SYSTEM_CONFIG_DIRS: + # only add ENV_CONFIG if sys.prefix is not already included + ENV_CONFIG_DIRS.append(_env_config_dir) + + _envvar = os.environ.get('IPYTHON_SUPPRESS_CONFIG_ERRORS') if _envvar in {None, ''}: IPYTHON_SUPPRESS_CONFIG_ERRORS = None @@ -403,6 +411,7 @@ class BaseIPythonApplication(Application): def init_config_files(self): """[optionally] copy default config files into profile dir.""" + self.config_file_paths.extend(ENV_CONFIG_DIRS) self.config_file_paths.extend(SYSTEM_CONFIG_DIRS) # copy config files path = self.builtin_profile_dir diff --git a/IPython/core/shellapp.py b/IPython/core/shellapp.py index ab8fbe4..2136482 100644 --- a/IPython/core/shellapp.py +++ b/IPython/core/shellapp.py @@ -11,12 +11,14 @@ from __future__ import absolute_import from __future__ import print_function 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 import py3compat from IPython.utils.contexts import preserve_keys @@ -331,7 +333,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 \ @@ -343,9 +347,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 diff --git a/docs/source/whatsnew/pr/env-config.rst b/docs/source/whatsnew/pr/env-config.rst new file mode 100644 index 0000000..9023540 --- /dev/null +++ b/docs/source/whatsnew/pr/env-config.rst @@ -0,0 +1,5 @@ + +- IPython now looks for config files in ``{sys.prefix}/etc/ipython`` + for environment-specific configuration. +- Startup files can be found in ``/etc/ipython/startup`` or ``{sys.prefix}/etc/ipython/startup`` + in addition to the profile directory, for system-wide or env-specific startup files.