Currently I have the following directory structure in the master git
branch:
/dir1
__init__.py
module.py
This will be changed to (in my branch):
/dir1
__init__.py
/dir2
module1.py # With 70% of code of module.py
module2.py # With 30% of code of module.py
Issues:
I know its not possible to make
git
track both new files, but sincegit
recognizes renames (and it considers organizing into folders as renames) I will be able to track changes tomodule.py
from the master branch to my branch'smodule1.py
, at least for the 70% of the code (I'll have to updatemodule2.py
manually). So is there a better way to deal with this?For API consistency, I'd like people who use older version of my package to still use
from dir1.module import abc
(without having amodule.py
indir1
) This can be done like described here, but that comes with the dangers of messing with thesys
path variables, which is not advised for stability and safety considerations. Is there a better way I could make the API backward-compatible and still safe/stable?
However, my situation is more complex. For a more representative example, consider moving from:
/dir1
__init__.py
module_2.py
def add2(a, b):
return a + b
def sub2(a, b):
return a - b
module_3.py
def add3(a, b, c):
return a + b + c
to:
/dir1
__init__.py
/dir2
__init__.py
module_add.py
# ... Constitutes 70% of code from `dir1/module_2.py`
def add2(a, b):
return a + b
# A few more additional lines added from `dir1/module_3.py`
def add3(a, b, c):
return a + b + c
module_sub.py
# Constitutes the 30% from /dir1/module2.py
def sub2(a, b):
return a - b
So in essence I am splitting up the different functionalities of dir1/module_2.py
and dir1/module_3.py
and regrouping them into separate module_add.py
and module_sub.py
and putting it under /dir1/dir2
However, version 1 users getting the version 2 package should still be able to do:
from module_2 import add2, sub2
from module_3 import add3
Things I can't do:
- Have
module_2.py
ormodule_3.py
indir1
(I need git to associate and track the master branch'sdir1/module_2.py
todir1/dir2/module_2.py
of my branch); - Change or mess around
sys.path
in any way that reduces stability/safety; or - Rename
dir2
to e.g.module_2
.