cycles bake script error: "Circular dependency .."
Cycles is baking on the texture ( not the new image ) itself because you haven't changed the active node through the script, just add nodes.active = node inside add_bake_nodes() like this :

# function to add nodes
def add_bake_nodes(mat, name):

    # make sure using nodes
    if mat.use_nodes == False:
        mat.use_nodes = True

    nodes = mat.node_tree.nodes

    node = nodes.new(type="ShaderNodeTexImage")
    bake_img_txt = "bake_img_" + name
    node.name = bake_img_txt
    nodes[bake_img_txt].location = 300, 160
    nodes[bake_img_txt].image = bpy.data.images[name] 
    nodes[bake_img_txt].select = True
    nodes.active = node   # set it as active node

   ......




"Circular dependency for image" because the image that is used as a texture (read from) is the target of the baking (written to)