[英]Tool to rewrite absolute imports to relative
Is there a tool to automatically rewrite absolute imports in Python to relative ones? 有没有一种工具可以将Python中的绝对导入自动重写为相对导入?
I wanted to provide a plugin to an application and this plugin needs and contains pygments (which uses absolute imports). 我想为应用程序提供一个插件,此插件需要并包含pygments(使用绝对导入)。 So I wanted to rewrite the pygments code without doing everything by hand.
所以我想重写pygments代码,而无需手工做。
The plugin could add an item to sys.path to include pygments but I wanted to avoid that. 该插件可以将一个项目添加到sys.path中以包含pygments,但我想避免这种情况。
chuckmove might work for you. chuckmove可能会为您工作。 It 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. ...这属于src,并重写导入sound.utils的语句以改为导入media.sound.utils。 It supports the whole range of Python import formats.
它支持整个Python导入格式。 Ie
from x import y
, import xyz as w
etc. 即
from x import y
, import xyz as w
等。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.