Mapping module imports in Python for easy refactoring

前端 未结 4 470
逝去的感伤
逝去的感伤 2021-02-07 10:40

I have a bunch of Python modules I want to clean up, reorganize and refactor (there\'s some duplicate code, some unused code ...), and I\'m wondering if there\'s a tool to make

4条回答
  •  遇见更好的自我
    2021-02-07 11:29

    chuckmove is a tool that lets you recursively rewrite imports in your entire source tree to refer to a new location of a module.

    chuckmove --old sound.utils --new media.sound.utils src
    

    ...this descends into src, and rewrites statements that import sound.utils to import media.sound.utils instead. It supports the whole range of Python import formats. I.e. from x import y, import x.y.z as w etc.

提交回复
热议问题