How would you split project into 2 parts?

Viacheslav Kondratiuk viakondratiuk at gmail.com
Wed Apr 25 01:17:30 EDT 2018


I need to split a project into 2 parts. To have one part as the main
project and include the second one as a submodule. Those parts located at
different parts of a project.

I can see 2 ways how I can do that:
1. Use PyCharm Refactor->Move functionality. It works fine. It takes a
module or a package, changes all project imports to a new namespace, sorts
those imports according to pep8 (which is not necessary and seems there is
no way to disable it). There are 2 problems with this approach:
a. If I want to move a module to a new package I have to recreate manually
whole dir tree.
b. It's too slow. It takes nearly 1 hour to move a package with 11 modules
into a new namespace.

2. I wrote a script. It has a mapping from an old_path to a new_path. I
extract all namespaces from old_path and replace those with new_path
namespaces by iterating over all *.py files from a project. I can use
fileinput module to replace namespaces in inplace. And when it's done apply
git mv for all specified path.

I wonder if there any tool to do that about which I don't know? Do you see
any problems with my approach? How would you do that?

- Slava



More information about the Python-list mailing list