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

Refactor %%cython to use IPython magic_arguments module #39434

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from

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

Copy link

github-actions bot commented Feb 2, 2025

Documentation preview for this PR (built with commit 30c837e; 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
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