I am running into a problem that I need to change a subpakcage of a big third party package. the big package, lets say foo, includes many subpackages, and I want to modify one of them, lets say bar. After weighing many options, I decide to dynamically change sys.modules when my django project starts. What i do is like this:
INSTALLED_APP=(...)
import sys, myproject.mybar #mybar is the the modified version
sys.modules['foo.bar']=myproject.mybar
This works fine in most cases, and whenever "from foo.bar import x,y,z" happens, it can be redirected to myproject.mybar. However, somewhere in the foo package, there is an import syntax like
import foo.bar.x
user = foo.bar.x.get_user(request)
This causes a "'module' object has no attribute" exception. Mybar package does have x module and get_user() method, and I am not sure why this happened. Anyone can help me to point me out what i miss here, also any suggestion to do what I am trying to achieve (modifying a subpackage) in a more pythonic and djangonic way?
P.S. the foo package is really big, and I dont want to include all of it in myproject. Thank for your help in advance Python community ( :