def format_script_for_cell(path):
    """Read and format a .py file to be inserted into the json for a cell."""
    header = '\n# Cell content replaced by load magic replacement.\n'
    with open(str(path), encoding='utf8') as f:
        solution = f.read()
        if not solution:
            raise RuntimeError('Solution {} has no content.'.format(path))
        return header + solution