On May15, 11:08am, Jonathan Lundell <jlund...@pobox.com> wrote:
> On May 14, 2010, at 11:27 AM, Iceberg wrote:
>
> > Turns out that the fix [1] is not completed. Most apps work when using
> > "web2py -f another_web2py_folder", but not those contains
> > local_import('my_module', app='my_app').
>
> > Should be easy to fix, but I even tried to add following lines at line
> > 706 of gluon/widget.py, yet have no luck.
> >    sys.path.append(options.folder)
> >    sys.path.append(os.path.join(options.folder,'applications'))
>
> > What can I do?
>
> > [1]http://code.google.com/p/web2py/source/detail?r=52c0b092adef8a96f1f18...
>
> Suggestion.
>
> path = os.path.normpath(path)
> if path not in sys.path: sys.path.insert(0, path)
>
> Two things: normalizing the path is a good idea, and using insert instead of 
> append means that the new path will override what's in the old one.


Hi Jonathan, thanks for your throwing lights, two at a time. :-)

I try os.path.normpath(options.folder) but it is not the case. Because
options.folder is already in local platform format. Besides, it seems
the built-in import statement tolerates sys.path as ['C:\\foo', '../
bar'] anyway.

Mysteriously, using sys.path.insert(...) rather than
sys.path.append(...) does help. But I just don't understand. I used to
think that the build-in import statement always goes through all
folders inside sys.path, one by one, so in theory it does not matter
whether a path appears in sys.path earlier or later. (Unless two
different version of same name module exist in two different path, but
it is not the case this time.)  //shrug   Any explanation for that,
Jonathan?


@Massimo, thanks for your latest attempt, but it should be adjusted as
below. And please also keep the comment which is valuable also.

  sys.path.insert(0, path) # somehow it need to be ahead of cwd


Thank you two.

Regards,
Iceberg

Reply via email to