Message152357
Thanks for the tip Brent. Still, no luck.
jaraco@devjaraco:~$ python2.7 -c 'import master.pkgA; print("pkgA.__package__ is {}".format(master.pkgA.__package__)); import master.pkgA.foo'
pkgA.__package__ is None
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "master/pkgA/foo.py", line 2, in <module>
bar = __import__('pkgB', globals(), level=1).bar
ImportError: No module named pkgB
I considered importlib, but it is only included for Python 2.7+ and I have to support Python 2.6. I'm using programmatic imports for a few reasons:
1) I'm importing the modules for the side effects, so I don't need or want the name in the namespace.
2) If I import it naturally, I get pyflakes warnings that it's an used imports.
3) The order of imports is important. If I place it too early in the imports, it doesn't have the state it needs and fails.
4) By placing it in the top of the file with other imports, it's not obvious why it's being imported, so requires comments.
5) The most appropriate place to invoke this functionality is in a specific function, "run_app".
I see now that there is an importlib backport in the cheeseshop for earlier versions of Python. Given your recommendation, I'll give that a try. |
|
Date |
User |
Action |
Args |
2012-01-30 23:05:31 | jaraco | set | recipients:
+ jaraco, brett.cannon, eric.snow |
2012-01-30 23:05:31 | jaraco | set | messageid: <1327964731.13.0.311264274877.issue13912@psf.upfronthosting.co.za> |
2012-01-30 23:05:30 | jaraco | link | issue13912 messages |
2012-01-30 23:05:30 | jaraco | create | |
|