Continue line break only if one has started

This commit is contained in:
Sergii Khomenko 2019-04-15 22:24:09 +02:00
parent fab6ba6e06
commit f57940fc54

View File

@ -63,32 +63,32 @@ def process_file(in_filename, out_filename, upgrader):
def skip_magic(code_line, magic_list): def skip_magic(code_line, magic_list):
""" """
Checks if the cell has magic, that is not python-based. Checks if the cell has magic, that is not python-based.
>>> skip_magic('!ls -laF', ['%', '!', '?']) >>> skip_magic('!ls -laF', ['%', '!', '?'])
True True
""" """
for magic in magic_list: for magic in magic_list:
if code_line.startswith(magic): if code_line.startswith(magic):
return True return True
return False return False
def check_line_split(code_line): def check_line_split(code_line):
r""" r"""
Checks if a line was splitted with `\`. Checks if a line was splitted with `\`.
>>> skip_magic("!gcloud ml-engine models create ${MODEL} \\\n") >>> skip_magic("!gcloud ml-engine models create ${MODEL} \\\n")
True True
""" """
if code_line.endswith('\\\n'): if code_line.endswith('\\\n'):
return True return True
return False return False
def _get_code(input_file): def _get_code(input_file):
@ -116,6 +116,9 @@ def _get_code(input_file):
# if this cell ends with `\` -> skip the next line # if this cell ends with `\` -> skip the next line
is_line_split = check_line_split(code_line) is_line_split = check_line_split(code_line)
if is_line_split:
is_line_split = check_line_split(code_line)
# Sometimes, people leave \n at the end of cell # Sometimes, people leave \n at the end of cell
# in order to migrate only related things, and make the diff # in order to migrate only related things, and make the diff
# the smallest -> here is another hack # the smallest -> here is another hack