Skip to content

Move load_ipython_extension from sage.__init__ to sage.repl.__init__ #32489

@mkoeppe

Description

@mkoeppe

As part of #31420 (Meta-ticket: Review/remove monkey patching in src/sage/__init__.py), we move the definition of load_ipython_extension (introduced in #18726) to sage.repl.__init__

This function was defined in module sage so that %load_ext sage works (see http://www.slabbe.org/blogue/categorie/ipython/). After the move, this would have to be %load_ext sage.repl; but we patch it into the module sage upon import of sage.repl to keep %load_ext sage as well (at least after import sage.all or import sage.repl).

$ ./sage -ipython
Python 3.9.6 (default, Jun 29 2021, 05:25:02) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.16.1 -- An enhanced Interactive Python. Type '?' for help.

With this ticket:

./sage -ipython
...
In [1]: %load_ext sage                                                                                                                                 
The sage module is not an IPython extension.
In [2]: import sage.repl                                                                                                                               
In [3]: %load_ext sage              # succeeds                                                                                                                   

and:

./sage -ipython
...
In [1]: %load_ext sage.repl         # succeeds                                                                                                                          

In a follow up ticket we may also want to define the corresponding function that will make %unload_ext sage work

Depends on #32479

CC: @tscrim @seblabbe @fchapoton @jhpalmieri @kcrisman

Component: refactoring

Author: Matthias Koeppe

Branch/Commit: 53bde1b

Reviewer: John Palmieri

Issue created by migration from https://trac.sagemath.org/ticket/32489

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions