Skip to content

Refactor %%cython to use IPython magic_arguments module#39434

Closed
user202729 wants to merge 5 commits intosagemath:developfrom
user202729:cython-cell-magic-refactor
Closed

Refactor %%cython to use IPython magic_arguments module#39434
user202729 wants to merge 5 commits intosagemath:developfrom
user202729:cython-cell-magic-refactor

Conversation

@user202729
Copy link
Contributor

@user202729 user202729 commented Feb 2, 2025

Refactor to use https://ipython.readthedocs.io/en/stable/api/generated/IPython.core.magic_arguments.html

Feature was originally added in #38945 before I realize the IPython helper module exists.

There's slight change in error message for unbalanced quotes, but I think it doesn't matter. (Edit: for simple cases it doesn't matter. See discussion in ipython/ipython#2001 )

📝 Checklist

  • The title is concise and informative.
  • The description explains in detail what this PR is about.
  • I have linked a relevant issue or discussion.
  • I have updated the documentation and checked the documentation preview.

⌛ Dependencies

@github-actions
Copy link

github-actions bot commented Feb 2, 2025

Documentation preview for this PR (built with commit 6eb035f; changes) is ready! 🎉
This preview will update shortly after each push to this PR.

@user202729
Copy link
Contributor Author

user202729 commented Feb 2, 2025

The documentation rendering doesn't seem to work too well?

image

Obviously because of the added text in the docstring by the decorators.

sage: from sage.repl.ipython_extension import SageMagics
sage: print(SageMagics.cython.__doc__)
::

  %cython [--verbose VERBOSE] [--compile-message | --no-compile-message]
              [--use-cache | --no-use-cache] [--create-local-c-file | --no-create-local-c-file]
              [--annotate | --no-annotate] [--view-annotate [{none,auto,webbrowser,displayhtml}]]
              [--sage-namespace | --no-sage-namespace]
              [--create-local-so-file | --no-create-local-so-file]

Cython cell magic.

This is syntactic sugar on the
:func:`~sage.misc.cython.cython_compile` function.

[...]

Test invalid quotes::

    sage: # needs sage.misc.cython
    sage: shell.run_cell('''
    ....: %%cython --a='
    ....: print(1)
    ....: ''')
    UsageError: argument --annotate/--no-annotate: ignored explicit argument "'"

options:
  --verbose VERBOSE, -v VERBOSE
  --compile-message, --no-compile-message
  --use-cache, --no-use-cache
  --create-local-c-file, --no-create-local-c-file
  --annotate, --no-annotate
  --view-annotate <[{none,auto,webbrowser,displayhtml}]>
  --sage-namespace, --no-sage-namespace
  --create-local-so-file, --no-create-local-so-file

sage: 

Besides, why is the initial line % instead of %%? (ipython/ipython#14715)

@kwankyu
Copy link
Collaborator

kwankyu commented Feb 3, 2025

Then I see no real benefit of using the IPython helper module for sage users...

@user202729 user202729 marked this pull request as draft February 3, 2025 01:03
@user202729 user202729 closed this Mar 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants