Skip to content

--config option executing 3 times? #14723

Open

Description

@diogo-rossi

I don't know if this is an issue or an expected behaviour, but the configuration file gets executed 3 times:

Documentation:

--config=<Unicode>
    Path to an extra config file to load.
        If specified, load this config file in addition to any other IPython
    config.
    Default: ''
    Equivalent to: [--BaseIPythonApplication.extra_config_file]

Extra configuration file

# ~/config_folder/extra_config.py
print("hello")

Execution test

❯ ipython --config=~/config_folder/extra_config.py
hello
hello
hello
Python 3.12.8 | packaged by conda-forge | (main, Dec  5 2024, 14:06:27) [MSC v.1942 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.32.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]:

Is that ok?

Activity

  1. Yann-P commented on Feb 7, 2025

    @Yann-P
    Contributor

    Looks like --config is not intended to be used with absolute paths.

    ipython --debug --config /Users/yann/ipython/extra_config.py
    [TerminalIPythonApp] Using existing profile dir: '/Users/yann/.ipython/profile_default'
    [TerminalIPythonApp] Searching path ['/Users/yann/.ipython/profile_default', '/opt/homebrew/opt/[email protected]/Frameworks/Python.framework/Versions/3.11/etc/ipython', '/usr/local/etc/ipython', '/etc/ipython'] for config files
    [TerminalIPythonApp] Attempting to load config file: ipython_config.py
    [TerminalIPythonApp] Looking for ipython_config in /etc/ipython
    [TerminalIPythonApp] Looking for ipython_config in /usr/local/etc/ipython
    [TerminalIPythonApp] Looking for ipython_config in /opt/homebrew/opt/[email protected]/Frameworks/Python.framework/Versions/3.11/etc/ipython
    [TerminalIPythonApp] Looking for ipython_config in /Users/yann/.ipython/profile_default
    [TerminalIPythonApp] Loaded config file: /Users/yann/.ipython/profile_default/ipython_config.py
    [TerminalIPythonApp] Attempting to load config file: ipython_config.py
    [TerminalIPythonApp] Looking for /Users/yann/ipython/extra_config in /etc/ipython
    hello
    [TerminalIPythonApp] Loaded config file: /Users/yann/ipython/extra_config.py
    [TerminalIPythonApp] Looking for /Users/yann/ipython/extra_config in /usr/local/etc/ipython
    hello
    [TerminalIPythonApp] Loaded config file: /Users/yann/ipython/extra_config.py
    [TerminalIPythonApp] Looking for /Users/yann/ipython/extra_config in /opt/homebrew/opt/[email protected]/Frameworks/Python.framework/Versions/3.11/etc/ipython
    hello
    [TerminalIPythonApp] Loaded config file: /Users/yann/ipython/extra_config.py
    [TerminalIPythonApp] Looking for /Users/yann/ipython/extra_config in /Users/yann/.ipython/profile_default
    hello
    [TerminalIPythonApp] Loaded config file: /Users/yann/ipython/extra_config.py
    Python 3.11.11 (main, Dec  3 2024, 17:20:40) [Clang 16.0.0 (clang-1600.0.26.4)]
    Type 'copyright', 'credits' or 'license' for more information
    IPython 9.0.0.dev -- An enhanced Interactive Python. Type '?' for help.
    
    [TerminalIPythonApp] Loading IPython extensions...
    [TerminalIPythonApp] Loading IPython extension: storemagic
    [TerminalIPythonApp] Starting IPython's mainloop...
    

    It looks in four directories but always finds it because of the absolute path. That explains why it's loaded many times (4 times for me on mac)

    By moving the config file to one of the expected directories it only loads once.

    ➜  ipython git:(main)  cp extra_config.py /Users/yann/.ipython/profile_default
    ➜  ipython git:(main)  ipython --config extra_config.py 
    hello
    Python 3.11.11 (main, Dec  3 2024, 17:20:40) [Clang 16.0.0 (clang-1600.0.26.4)]
    Type 'copyright', 'credits' or 'license' for more information
    IPython 9.0.0.dev -- An enhanced Interactive Python. Type '?' for help.
    
    
    

    A better solution could be to detect if the path is absolute and only load it once

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions