From f57940fc5478e23d15a94adcabf4621aaf9123c2 Mon Sep 17 00:00:00 2001 From: Sergii Khomenko Date: Mon, 15 Apr 2019 22:24:09 +0200 Subject: [PATCH] Continue line break only if one has started --- tensorflow/tools/compatibility/ipynb.py | 37 +++++++++++++------------ 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/tensorflow/tools/compatibility/ipynb.py b/tensorflow/tools/compatibility/ipynb.py index e2c41097f46..1d6cbfdbe57 100644 --- a/tensorflow/tools/compatibility/ipynb.py +++ b/tensorflow/tools/compatibility/ipynb.py @@ -63,32 +63,32 @@ def process_file(in_filename, out_filename, upgrader): 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', ['%', '!', '?']) - True - """ + >>> skip_magic('!ls -laF', ['%', '!', '?']) + True + """ - for magic in magic_list: - if code_line.startswith(magic): - return True + for magic in magic_list: + if code_line.startswith(magic): + return True - return False + return False def check_line_split(code_line): - r""" - Checks if a line was splitted with `\`. + r""" + Checks if a line was splitted with `\`. - >>> skip_magic("!gcloud ml-engine models create ${MODEL} \\\n") - True - """ + >>> skip_magic("!gcloud ml-engine models create ${MODEL} \\\n") + True + """ - if code_line.endswith('\\\n'): - return True + if code_line.endswith('\\\n'): + return True - return False + return False def _get_code(input_file): @@ -116,6 +116,9 @@ def _get_code(input_file): # if this cell ends with `\` -> skip the next 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 # in order to migrate only related things, and make the diff # the smallest -> here is another hack