diff --git a/tensorflow/tools/compatibility/ipynb.py b/tensorflow/tools/compatibility/ipynb.py index 1d6cbfdbe57..43674e2c75a 100644 --- a/tensorflow/tools/compatibility/ipynb.py +++ b/tensorflow/tools/compatibility/ipynb.py @@ -21,6 +21,7 @@ from __future__ import print_function import collections import copy import json +import re import shutil import tempfile @@ -63,8 +64,13 @@ 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. + + Args: + code_line: A line of Python code + magic_list: A list of jupyter "magic" exceptions + Returns: + If the line jupyter "magic" line, not Python line >>> skip_magic('!ls -laF', ['%', '!', '?']) True @@ -78,18 +84,18 @@ def skip_magic(code_line, magic_list): def check_line_split(code_line): - r""" - Checks if a line was splitted with `\`. + r"""Checks if a line was split with `\`. + + Args: + code_line: A line of Python code + Returns: + If the line was split with `\` >>> skip_magic("!gcloud ml-engine models create ${MODEL} \\\n") True """ - if code_line.endswith('\\\n'): - return True - - return False - + return re.search(r'\\\s*\n$', code_line) def _get_code(input_file): """Loads the ipynb file and returns a list of CodeLines."""