[web2py] Re: Custom import creates module name conflicts (2.1.1)
I have in app's modules dir a modul named sftp.py and I try to use paramiko but sftp.py modul can't import it because paramiko has it's own modul named as sftp.py and custom_import find the app's module first and nor paramiko's :( http://code.google.com/p/web2py/issues/detail?id=1125 2012. október 22., hétfő 23:31:14 UTC+2 időpontban Jim Karsten a következőt írta: > > Thanks, Massimo. > > I upgraded to web2py v2.2.1 and that patch addresses the 'ImportError: > cannot import name web2py_uuid' error. > > I still have name clashes with my constants.py module and MySQLdb. For now > I am going to rename my module. I have some reservations about the new > custom_importer as it can produce these clash problems and there is little > I can do to prepare for them or protect my code from them. > > On Friday, October 19, 2012 7:37:44 PM UTC-4, Massimo Di Pierro wrote: >> >> Good catch. Fixed in trunk >> >> On Friday, 19 October 2012 16:54:54 UTC-5, Jim Karsten wrote: >>> >>> I upgraded to v 2.1.1 and now see problems with module name conflicts >>> due to the custom importer. Previously I used v2.0.9 without problems. >>> >>> I have a custom application module named utils.py. This appears to >>> conflict with the gluon.utils module. I was able to simulate using the >>> basic web2py zip file and then creating a simple module >>> applications/welcome/modules/utils.py. When I access the welcome default >>> page, I get this error: >>> >>> Traceback (most recent call last): >>> File "/root/tmp/web2py/web2py/gluon/restricted.py", line 209, >>> in restricted exec ccode in environment >>> File "/root/tmp/web2py/web2py/applications/welcome/models/db.py", line >>> 42, >>> in from gluon.tools import Auth, Crud, Service, PluginManager, >>> prettydate >>> File "/root/tmp/web2py/web2py/gluon/custom_import.py", line 89, >>> in custom_importer return >>> NATIVE_IMPORTER(name,globals,locals,fromlist,level) >>> File "/root/tmp/web2py/web2py/gluon/tools.py", line 30, in from utils >>> import web2py_uuid >>> ImportError: cannot import name web2py_uuid >>> >>> I disabled the custom importer by issuing a return immediately in >>> gluon/custom_import.py def custom_import_install() and the problem goes >>> away. >>> >>> I can also correct this specific issue if I change this line in >>> gluon/tools.py >>> >>> -from utils import web2py_uuid >>> +from gluon.utils import web2py_uuid >>> >>> This last change works, but it isn't a complete solution. For example, >>> in another application I have a constants.py module. It is conflicting with >>> a constants module MySQLdb makes use of. Deep in the code of MySQLdb there >>> is a line: >>> >>> from constants import CLIENT, FIELD_TYPE >>> >>> That import fails as it tries to find those classes in my custom module. >>> I can always rename my custom module, but this becomes a cat and mouse >>> game. I can't know every module name already in use. >>> >>> Any suggestions for this? It's a bit of a show stopper for me. Perhaps >>> an option should be available to disable the custom importer. >> >> --
[web2py] Re: Custom import creates module name conflicts (2.1.1)
Thanks, Massimo. I upgraded to web2py v2.2.1 and that patch addresses the 'ImportError: cannot import name web2py_uuid' error. I still have name clashes with my constants.py module and MySQLdb. For now I am going to rename my module. I have some reservations about the new custom_importer as it can produce these clash problems and there is little I can do to prepare for them or protect my code from them. On Friday, October 19, 2012 7:37:44 PM UTC-4, Massimo Di Pierro wrote: > > Good catch. Fixed in trunk > > On Friday, 19 October 2012 16:54:54 UTC-5, Jim Karsten wrote: >> >> I upgraded to v 2.1.1 and now see problems with module name conflicts due >> to the custom importer. Previously I used v2.0.9 without problems. >> >> I have a custom application module named utils.py. This appears to >> conflict with the gluon.utils module. I was able to simulate using the >> basic web2py zip file and then creating a simple module >> applications/welcome/modules/utils.py. When I access the welcome default >> page, I get this error: >> >> Traceback (most recent call last): >> File "/root/tmp/web2py/web2py/gluon/restricted.py", line 209, >> in restricted exec ccode in environment >> File "/root/tmp/web2py/web2py/applications/welcome/models/db.py", line >> 42, >> in from gluon.tools import Auth, Crud, Service, PluginManager, prettydate >> File "/root/tmp/web2py/web2py/gluon/custom_import.py", line 89, >> in custom_importer return >> NATIVE_IMPORTER(name,globals,locals,fromlist,level) >> File "/root/tmp/web2py/web2py/gluon/tools.py", line 30, in from utils >> import web2py_uuid >> ImportError: cannot import name web2py_uuid >> >> I disabled the custom importer by issuing a return immediately in >> gluon/custom_import.py def custom_import_install() and the problem goes >> away. >> >> I can also correct this specific issue if I change this line in >> gluon/tools.py >> >> -from utils import web2py_uuid >> +from gluon.utils import web2py_uuid >> >> This last change works, but it isn't a complete solution. For example, in >> another application I have a constants.py module. It is conflicting with a >> constants module MySQLdb makes use of. Deep in the code of MySQLdb there is >> a line: >> >> from constants import CLIENT, FIELD_TYPE >> >> That import fails as it tries to find those classes in my custom module. >> I can always rename my custom module, but this becomes a cat and mouse >> game. I can't know every module name already in use. >> >> Any suggestions for this? It's a bit of a show stopper for me. Perhaps an >> option should be available to disable the custom importer. > > --
[web2py] Re: Custom import creates module name conflicts (2.1.1)
Good catch. Fixed in trunk On Friday, 19 October 2012 16:54:54 UTC-5, Jim Karsten wrote: > > I upgraded to v 2.1.1 and now see problems with module name conflicts due > to the custom importer. Previously I used v2.0.9 without problems. > > I have a custom application module named utils.py. This appears to > conflict with the gluon.utils module. I was able to simulate using the > basic web2py zip file and then creating a simple module > applications/welcome/modules/utils.py. When I access the welcome default > page, I get this error: > > Traceback (most recent call last): > File "/root/tmp/web2py/web2py/gluon/restricted.py", line 209, > in restricted exec ccode in environment > File "/root/tmp/web2py/web2py/applications/welcome/models/db.py", line 42, > in from gluon.tools import Auth, Crud, Service, PluginManager, prettydate > File "/root/tmp/web2py/web2py/gluon/custom_import.py", line 89, > in custom_importer return > NATIVE_IMPORTER(name,globals,locals,fromlist,level) > File "/root/tmp/web2py/web2py/gluon/tools.py", line 30, in from utils > import web2py_uuid > ImportError: cannot import name web2py_uuid > > I disabled the custom importer by issuing a return immediately in > gluon/custom_import.py def custom_import_install() and the problem goes > away. > > I can also correct this specific issue if I change this line in > gluon/tools.py > > -from utils import web2py_uuid > +from gluon.utils import web2py_uuid > > This last change works, but it isn't a complete solution. For example, in > another application I have a constants.py module. It is conflicting with a > constants module MySQLdb makes use of. Deep in the code of MySQLdb there is > a line: > > from constants import CLIENT, FIELD_TYPE > > That import fails as it tries to find those classes in my custom module. I > can always rename my custom module, but this becomes a cat and mouse game. > I can't know every module name already in use. > > Any suggestions for this? It's a bit of a show stopper for me. Perhaps an > option should be available to disable the custom importer. --