Switch to regex; update styles
This commit is contained in:
parent
f57940fc54
commit
850d385564
@ -21,6 +21,7 @@ from __future__ import print_function
|
|||||||
import collections
|
import collections
|
||||||
import copy
|
import copy
|
||||||
import json
|
import json
|
||||||
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
@ -63,8 +64,13 @@ 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.
|
|
||||||
|
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', ['%', '!', '?'])
|
>>> skip_magic('!ls -laF', ['%', '!', '?'])
|
||||||
True
|
True
|
||||||
@ -78,18 +84,18 @@ def skip_magic(code_line, magic_list):
|
|||||||
|
|
||||||
|
|
||||||
def check_line_split(code_line):
|
def check_line_split(code_line):
|
||||||
r"""
|
r"""Checks if a line was split with `\`.
|
||||||
Checks if a line was splitted 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")
|
>>> skip_magic("!gcloud ml-engine models create ${MODEL} \\\n")
|
||||||
True
|
True
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if code_line.endswith('\\\n'):
|
return re.search(r'\\\s*\n$', code_line)
|
||||||
return True
|
|
||||||
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def _get_code(input_file):
|
def _get_code(input_file):
|
||||||
"""Loads the ipynb file and returns a list of CodeLines."""
|
"""Loads the ipynb file and returns a list of CodeLines."""
|
||||||
|
Loading…
Reference in New Issue
Block a user