References:
        http://stackoverflow.com/questions/23576681/python-check-syntax

def is_valid_python(code, reraise=True, ipy_magic_workaround=False):
    """
    References:
        http://stackoverflow.com/questions/23576681/python-check-syntax
    """
    import ast
    try:
        if ipy_magic_workaround:
            code = '\n'.join(['pass' if re.match(r'\s*%[a-z]*', line) else line for line in code.split('\n')])
        ast.parse(code)
    except SyntaxError:
        if reraise:
            import utool as ut
            print('Syntax Error')
            ut.print_python_code(code)
            raise
        return False
    return True