We are refactoring our code base.
Old:
from a.b import foo_method
New:
from b.d import bar_method
Both methods (foo_method()
and bar_method()
) are the same. It just changed the name an the package.
Since above example is just one example of many ways a method can be imported, I don't think a simple regular expression can help here.
How to refactor the importing of a module with a command line tool?
A lot of source code lines need to be changed, so that an IDE does not help here.
You'll need to write/find some script that will do text replacement of all occurrences in some folder. I remember that Notepad++ could do that.
But as you mentioned, that regexp will not help here, then no scripts (even Open Source) will help here too. And you'll definitely need to have some intelligence here, that will build index of your dependencies/modules/files/packages/etc. and will be able to manipulate them on that level. And that is the purpose for which IDE were built for.
You can choose any that you like: PyCharm, Sublime, Visual Studio or any other that are not just text editor but something that has refactoring functionality.
In any case, I would suggest you to do following refactoring steps:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With