def exec_file(filename, return_locals=False, is_deploy_code=False):
    '''
    Execute a Python file and optionally return it's attributes as a dict.
    '''

    if filename not in PYTHON_CODES:
        with open(filename, 'r') as f:
            code = f.read()

        code = compile(code, filename, 'exec')
        PYTHON_CODES[filename] = code

    # Create some base attributes for our "module"
    data = {
        '__file__': filename,
        'state': pseudo_state,
    }

    # Execute the code with locals/globals going into the dict above
    exec(PYTHON_CODES[filename], data)

    return data
Execute a Python file and optionally return it's attributes as a dict.