-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Add support for custom python cell magics #2744
Changes from 4 commits
3a6c30e
65d48e4
f469c88
f0c67bc
8110734
f18fc2b
7b3f7ab
5eb71d8
00e02c5
e23dc2f
924e900
96cf858
d004e5a
8b12ba3
c495217
376dfe3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from dataclasses import replace | ||
import pathlib | ||
import re | ||
|
||
|
@@ -139,6 +140,17 @@ def test_cell_magic_with_magic() -> None: | |
assert result == expected | ||
|
||
|
||
def test_cell_magic_with_custom_python_magic() -> None: | ||
src = "%%custom_python_magic -n1 -n2\nx=2" | ||
result = format_cell( | ||
src, | ||
fast=True, | ||
mode=replace(JUPYTER_MODE, python_cell_magics={"custom_python_magic"}), | ||
) | ||
expected = "%%custom_python_magic -n1 -n2\nx = 2" | ||
assert result == expected | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should there also be a test to check that if you pass some custom magic, then the default Python magics still get formatted? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably, and that when not passing but trying to format custom it isn't formatted 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No problem, pushed. :-) |
||
|
||
|
||
def test_cell_magic_nested() -> None: | ||
src = "%%time\n%%time\n2+2" | ||
result = format_cell(src, fast=True, mode=JUPYTER_MODE) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit jarring to write
--python-cell-magics custom1 --python-cell-magics custom2
. Should we use a comma-separated list instead?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, though this is how
click
supports multiple options out of the box. This is also howtarget-version
takes multiple arguments. I expect that we would need to introduce a custom callback to support multiple options, which might then also require custom logic when reading from thepyproject.toml
file.My expectation is that this will rather mostly be used in a configuration file and so perhaps the clunkiness on the command line is acceptable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fair!