diff --git a/sparkmagic/sparkmagic/kernels/wrapperkernel/usercodeparser.py b/sparkmagic/sparkmagic/kernels/wrapperkernel/usercodeparser.py index 47efbd99..7b7c1069 100644 --- a/sparkmagic/sparkmagic/kernels/wrapperkernel/usercodeparser.py +++ b/sparkmagic/sparkmagic/kernels/wrapperkernel/usercodeparser.py @@ -23,6 +23,7 @@ class UserCodeParser(object): ] def get_code_to_run(self, code): + code = code.lstrip() try: all_but_first_line = code.split(None, 1)[1] except IndexError: diff --git a/sparkmagic/sparkmagic/tests/test_usercodeparser.py b/sparkmagic/sparkmagic/tests/test_usercodeparser.py index f140ef39..52a3ebc0 100644 --- a/sparkmagic/sparkmagic/tests/test_usercodeparser.py +++ b/sparkmagic/sparkmagic/tests/test_usercodeparser.py @@ -77,6 +77,15 @@ def test_other_line_magic(): assert cell == parser.get_code_to_run(cell) +def test_leading_whitespace_magic(): + parser = UserCodeParser() + cell = """\n%magic +hi +hi +hi""" + + assert cell.lstrip() == parser.get_code_to_run(cell) + def test_scala_code(): parser = UserCodeParser()