-
-
Notifications
You must be signed in to change notification settings - Fork 12
Ignore all magics #6
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
base: master
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -21,7 +21,7 @@ | |
| from black import format_str | ||
| from IPython.core import magic_arguments | ||
| from IPython.core.magic import Magics, cell_magic, magics_class | ||
|
|
||
| import re | ||
|
|
||
| @magics_class | ||
| class FormattingMagic(Magics): | ||
|
|
@@ -37,10 +37,21 @@ def black(self, line, cell): | |
| args = magic_arguments.parse_argstring(self.black, line) | ||
| line_length = args.line_length | ||
| if cell: | ||
| formated = format_str(src_contents=cell, line_length=line_length) | ||
| if formated and formated[-1] == "\n": | ||
| # Comment magics | ||
| cell = re.sub(r"^%", r"##!%", cell) | ||
| cell = re.sub(r"\n\s*%", "\n##!%", cell) | ||
| try: | ||
|
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. This is a good logic! Can we abstract it out to a method and add tests for that method. It would be amazing if you can do that. Also, we should avoid exception based flow control. |
||
| formated = format_str(src_contents=cell, line_length=line_length) | ||
| if formated and formated[-1] == "\n": | ||
| formated = formated[:-1] | ||
| self.shell.set_next_input(formated, replace=True) | ||
| except ValueError as e: | ||
| formated = cell | ||
| print(e) | ||
|
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. Maybe we should have |
||
| finally: | ||
| # Uncomment magics | ||
| formated = re.sub(r"##!%", "%", formated) | ||
| # No matter success or not, something will always be put back | ||
| self.shell.set_next_input(formated, replace=True) | ||
|
|
||
|
|
||
| def load_ipython_extension(ipython): | ||
|
|
||
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.
Shall we leave a detailed comment on: