@publisher
def delete_empty_namespaces():
    # only allow namespaces with DAG objects in it and no child namespaces
    empty_namespaces = [
        ns for ns in pm.listNamespaces(recursive=True)
        if len(pm.ls(ns.listNodes(), dag=True, mat=True)) == 0
        and len(ns.listNamespaces()) == 0
    ]

    # remove all empty
    for ns in empty_namespaces:
        pm.namespace(rm=ns, mnr=1)

    # if len(empty_namespaces):
    #     raise PublishError(
    #         'There are empty <b>namespaces</b><br><br>'
    #         'Please remove them!!!'
    #     )
checks and deletes empty namespaces
dataset/ETHPy150Open eoyilmaz/anima/anima/env/mayaEnv/publish.py/delete_empty_namespaces