Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some magics (e. g %%mathematica) have vanished #35246

Closed
2 tasks done
EmmanuelCharpentier opened this issue Mar 8, 2023 · 19 comments
Closed
2 tasks done

Some magics (e. g %%mathematica) have vanished #35246

EmmanuelCharpentier opened this issue Mar 8, 2023 · 19 comments

Comments

@EmmanuelCharpentier
Copy link
Contributor

Is there an existing issue for this?

  • I have searched the existing issues for a bug report that matches the one I want to file, without success.

Did you read the documentation and troubleshoot guide?

  • I have read the documentation and troubleshoot guide

Environment

- **OS**: Debian testing
- **Sage Version**: 10.0.beta1 and 10.0.beta3

Steps To Reproduce

sage: %%mathematica
....: D[Sin[x], x]
....: 
....: 

Expected Behavior

Cos[x]

Actual Behavior

UsageError: Cell magic `%%mathematica` not found.

Additional Information

FWIW, in a console :

sage: %display ascii_art # see https://github.com/sagemath/sage/issues/30661
sage: %lsmagic
Available line magics:
%alias  %alias_magic  %attach  %autoawait  %autocall  %autoindent  %automagic  %bookmark  %cat  %cd  %clear  %colors  %conda  %config  %cp  %cpaste  %crun  %debug  %dhist  %dirs  %display  %doctest_mode  %ed  %edit  %env  %gap  %gp  %gui  %hist  %history  %iload  %killbgscripts  %ldir  %less  %lf  %lk  %ll  %load  %load_ext  %loadpy  %logoff  %logon  %logstart  %logstate  %logstop  %ls  %lsmagic  %lx  %macro  %magic  %magma  %man  %matplotlib  %maxima  %mkdir  %more  %mv  %notebook  %page  %paste  %pastebin  %pdb  %pdef  %pdoc  %pfile  %pinfo  %pinfo2  %pip  %polymake  %popd  %pprint  %precision  %prun  %psearch  %psource  %pushd  %pwd  %pycat  %pylab  %quickref  %recall  %rehashx  %reload_ext  %rep  %rerun  %reset  %reset_selective  %rm  %rmdir  %run  %runfile  %sage0  %save  %sc  %set_env  %singular  %store  %sx  %system  %tb  %time  %timeit  %unalias  %unload_ext  %who  %who_ls  %whos  %xdel  %xmode

Available cell magics:
%%!  %%HTML  %%SVG  %%bash  %%capture  %%cython  %%debug  %%file  %%fortran  %%gap  %%gp  %%html  %%javascript  %%js  %%latex  %%magma  %%markdown  %%maxima  %%perl  %%polymake  %%prun  %%pypy  %%python  %%python2  %%python3  %%ruby  %%sage0  %%script  %%sh  %%singular  %%svg  %%sx  %%system  %%time  %%timeit  %%writefile

Automagic is ON, % prefix IS NOT needed for line magics.

The %sage0 and %%sage0 entries look suspicious...

@EmmanuelCharpentier
Copy link
Contributor Author

Not able to add/modify labels (I may not yet be in "triage"). Should be t:bug, c:core, p:minor

Furthermore @John H Palmieri, but don't know his Github handle...

@miguelmarco
Copy link
Contributor

I also found that %%lisp has disappeared.

@miguelmarco
Copy link
Contributor

My guess is that it has to do with moving their import to lazy_import in 5f08ad8

After that change, the creation of the magic commands ignores it:

for name, obj in sage.interfaces.all.__dict__.items():
if isinstance(obj, sage.interfaces.interface.Interface):
yield cls(name, obj)

@miguelmarco
Copy link
Contributor

A workaround i found is to register the magic command manually:

from sage.interfaces.lisp import lisp
from sage.repl.interface_magic import InterfaceMagic
shell = get_ipython()
interface=InterfaceMagic("lisp", lisp)
shell.register_magic_function(interface.line_magic_factory(), magic_name="lisp", magic_kind='line')
shell.register_magic_function(interface.cell_magic_factory(), magic_name=interface._name, magic_kind='cell')

@jhpalmieri
Copy link
Member

See also #34547 (comment).

@miguelmarco
Copy link
Contributor

See also #34547 (comment).

Thanks. I guess we have the answer to your question about whether we care. Would it be possible to register the magic commands but still lazy_import them?

@jhpalmieri
Copy link
Member

I don't know, partly because I don't know why lazily importing broke the commands.

@miguelmarco
Copy link
Contributor

The code that registers the magic commands specifically checks if they are instances of Interface :

for name, obj in sage.interfaces.all.__dict__.items():
if isinstance(obj, sage.interfaces.interface.Interface):
yield cls(name, obj)

@jhpalmieri
Copy link
Member

Should be fixed by #35680. Emmanuel, can you verify?

@EmmanuelCharpentier
Copy link
Contributor Author

EmmanuelCharpentier commented May 26, 2023 via email

vbraun pushed a commit that referenced this issue Jun 3, 2023
    
### 📚 Description

Addresses  #35246

The lazy imported interfaces are not registered as magic modes. This
patch registers them too.

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. It should be `[x]` not `[x
]`. -->

- [x] The title is concise, informative, and self-explanatory.
- [x] The description explains in detail what this PR is about.
- [x] I have linked a relevant issue or discussion.
- [] I have created tests covering the changes.
- [] I have updated the documentation accordingly.
    
URL: #35680
Reported by: miguelmarco
Reviewer(s): John H. Palmieri
@EmmanuelCharpentier
Copy link
Contributor Author

Merging #35680 fixed some of these problems. But some other magics are still missing :

sage: %bg foo=(x/(x^5+a^5)).integrate(x, algorithm="fricas")
UsageError: Line magic function `%bg` not found.

The lack of %bg justifies (IMHO) upgrading the priority if this bug to major.

The related #30661 is still open :

sage: %display simple
sage: %lsmagic
<IPython.core.magics.basic.MagicsDisplay object at 0x7f25ff917650>
sage: %display ascii_art
sage: %lsmagic
Available line magics:
%Axiom  %ECM  %FriCAS  %Gap3  %Genus2reduction  %Gfan  %Giac  %Kash  %LiE  %Lisp  %Macaulay2  %Maple  %Mathematica  %Mathics  %Matlab  %Mupad  %Mwrank  %Octave  %PSage  %R  %alias  %alias_magic  %attach  %autoawait  %autocall  %autoindent  %automagic  %axiom  %bookmark  %cat  %cd  %clear  %colors  %conda  %config  %cp  %cpaste  %crun  %debug  %dhist  %dirs  %display  %doctest_mode  %ecm  %ed  %edit  %env  %four_ti_2  %fricas  %frobby  %gap  %gap3  %gap3_version  %genus2reduction  %gfan  %giac  %gnuplot  %gp  %gui  %hist  %history  %iload  %kash  %kash_version  %killbgscripts  %ldir  %less  %lf  %lie  %lisp  %lk  %ll  %load  %load_ext  %loadpy  %logoff  %logon  %logstart  %logstate  %logstop  %ls  %lsmagic  %lx  %macaulay2  %macro  %magic  %magma  %magma_free  %man  %maple  %mathematica  %mathics  %matlab  %matlab_version  %matplotlib  %maxima  %mkdir  %more  %mupad  %mv  %mwrank  %notebook  %octave  %page  %paste  %pastebin  %pdb  %pdef  %pdoc  %pfile  %pinfo  %pinfo2  %pip  %polymake  %popd  %povray  %pprint  %precision  %prun  %psearch  %psource  %pushd  %pwd  %pycat  %pylab  %qepcad  %qepcad_formula  %qepcad_version  %quickref  %r  %r_version  %read_data  %recall  %rehashx  %reload_ext  %rep  %rerun  %reset  %reset_selective  %rm  %rmdir  %run  %runfile  %sage0  %save  %sc  %scilab  %set_env  %singular  %store  %sx  %system  %tachyon_rt  %tb  %time  %timeit  %unalias  %unload_ext  %who  %who_ls  %whos  %xdel  %xmode

Available cell magics:
%%!  %%Axiom  %%ECM  %%FriCAS  %%Gap3  %%Genus2reduction  %%Gfan  %%Giac  %%HTML  %%Kash  %%LiE  %%Lisp  %%Macaulay2  %%Maple  %%Mathematica  %%Mathics  %%Matlab  %%Mupad  %%Mwrank  %%Octave  %%PSage  %%R  %%SVG  %%axiom  %%bash  %%capture  %%cython  %%debug  %%ecm  %%file  %%fortran  %%four_ti_2  %%fricas  %%frobby  %%gap  %%gap3  %%gap3_version  %%genus2reduction  %%gfan  %%giac  %%gnuplot  %%gp  %%html  %%javascript  %%js  %%kash  %%kash_version  %%latex  %%lie  %%lisp  %%macaulay2  %%magma  %%magma_free  %%maple  %%markdown  %%mathematica  %%mathics  %%matlab  %%matlab_version  %%maxima  %%mupad  %%mwrank  %%octave  %%perl  %%polymake  %%povray  %%prun  %%pypy  %%python  %%python2  %%python3  %%qepcad  %%qepcad_formula  %%qepcad_version  %%r  %%r_version  %%read_data  %%ruby  %%sage0  %%scilab  %%script  %%sh  %%singular  %%svg  %%sx  %%system  %%tachyon_rt  %%time  %%timeit  %%writefile

Automagic is ON, % prefix IS NOT needed for line magics.
sage: %display typeset
sage: %lsmagic
<IPython.core.magics.basic.MagicsDisplay object at 0x7f260048c990>

@jhpalmieri
Copy link
Member

Do you have any idea where/how %bg was defined before? I don't think it should have been affected by #34547 — that should only have affected magic commands related to interfaces. When did %bg last work?

@jhpalmieri
Copy link
Member

jhpalmieri commented Jun 25, 2023

Could it have been in a previous version of IPython? I see https://pypi.org/project/ipython-bg/, but it hasn't been modified for 3 years. See also https://stackoverflow.com/questions/10819479/missing-background-magic-command-bg-in-ipython and ipython/ipython#844.

@EmmanuelCharpentier
Copy link
Contributor Author

EmmanuelCharpentier commented Jun 25, 2023 via email

@jhpalmieri
Copy link
Member

We should probably remove that from the tutorial. See #22934 (comment), or we can open a new issue.

@jhpalmieri
Copy link
Member

I created #35836.

@mkoeppe
Copy link
Member

mkoeppe commented Sep 30, 2023

Can this be closed as completed?

@jhpalmieri
Copy link
Member

Okay with me. Emmanuel?

@fchapoton
Copy link
Contributor

@EmmanuelCharpentier please confirm that this issue can be closed

@mkoeppe mkoeppe closed this as not planned Won't fix, can't repro, duplicate, stale Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants