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

Ignore all magics #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Ignore all magics #6

wants to merge 2 commits into from

Conversation

liurui39660
Copy link

Solves #5
Fix: %%black will be removed even formatting fails.
Fix: Ignore all magic calls.

Rui Liu added 2 commits August 17, 2018 16:13
@@ -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
Copy link
Owner

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:

  1. Pattern the regex replacing and what it is replacing it with.
  2. Give an example.

# Comment magics
cell = re.sub(r"^%", r"##!%", cell)
cell = re.sub(r"\n\s*%", "\n##!%", cell)
try:
Copy link
Owner

Choose a reason for hiding this comment

The 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.

self.shell.set_next_input(formated, replace=True)
except ValueError as e:
formated = cell
print(e)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should have logging.error() instead of printing the exception.

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