Sunday, August 3, 2014

How to modify subpackage in django project

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 ( :

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/04da6770-0bc5-4a52-b7a8-3388a294457b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment