local_import

24 views
Skip to first unread message

Jose

unread,
Jul 2, 2010, 12:52:00 PM7/2/10
to web2py-users
I have problems with local_import in the latest version of the trunk.

Jose

NetAdmin

unread,
Jul 2, 2010, 1:25:03 PM7/2/10
to web2py-users
What type of errors or messages do you get?

Jose

unread,
Jul 2, 2010, 1:58:14 PM7/2/10
to web2py-users
Sorry, I did not put what the problem. I saw in the log of changes
that had something new with Imports and thought I had to do with it.

The problem is that no matter the form directly. This started to
happen with the changes to the trunk between yesterday and today.

Jose

mdipierro

unread,
Jul 2, 2010, 6:50:31 PM7/2/10
to web2py-users
Please tell us more. I do not understand.

Jose

unread,
Jul 2, 2010, 7:26:43 PM7/2/10
to web2py-users
In the modules directory of my application I have mymodule.py

When run from the controller:
mymodule = local_import ('mymodule', reload = True)

this produces no error, but when I access the functions or classes of
the module,

myobject = mymodule.MyClass(...)

it fails:

AttributeError: 'module' object has no attribute 'MyClass'

You understand?

This worked well until yesterday, after upgrading from the trunk,
started the error.

Jose

mdipierro

unread,
Jul 2, 2010, 7:45:16 PM7/2/10
to web2py-users
I think I fixed it. Please try again. Also check whether reload works
or not.

Jose

unread,
Jul 2, 2010, 8:11:00 PM7/2/10
to web2py-users
Now works!

Thanks

Iceberg

unread,
Jul 3, 2010, 7:05:42 AM7/3/10
to web2py-users
Sorry gentlemen, I don't get it.

First of all, the new implementation, even with the latest bugfix,
does not use the "force" parameter at all, neither python reload(). I
reckon that Jose did not test the reload feature when he said "Now
works!". Actually now the reload feature is gone.

Second, I would recommend Massimo to test the new code before
committing it. Even we don't have to follow TDD (test-driven
development), but a TAD (test-after-development) should be a minimal
rule. Otherwise you actually put those enthusiastic web2py users on a
really "bleeding" edge, with unnecessary "blood", and therefore
potentially discourage them from checking out the latest trunk often.

The last, well, and the least, I would like to suggest "If It Works,
Don't Fix It". I remember local_import(...) was not an easy job. More
than 7 months ago, it experienced some back and forth adjustment,
until Massimo commented out the "old implementation" and code
stabilized since then. So, why the sophisticated local_import(...) is
being reimplemented 2 days ago, introducing all this hustle?

Jose

unread,
Jul 3, 2010, 7:34:24 AM7/3/10
to web2py-users


On 3 jul, 08:05, Iceberg <iceb...@21cn.com> wrote:
> Sorry gentlemen, I don't get it.
>
> First of all, the new implementation, even with the latest bugfix,
> does not use the "force" parameter at all, neither python reload(). I
> reckon that Jose did not test the reload feature when he said "Now
> works!". Actually now the reload feature is gone.

I tried changing the code of the module, and without stopping and
restarting web2py, the change is reflected in the application. From
this, understand that the reload = True, is working well.

mdipierro

unread,
Jul 3, 2010, 7:49:06 AM7/3/10
to web2py-users
It is true that force is ignored. That is because __import__ always
reloads. This may seem slower but actually it may be faster than the
previous solution using exec with force=False.

he reason for the change is that the new implementation is supposed to
be equivalent, cleaner and faster.
Does it work for you?

Massimo

Iceberg

unread,
Jul 4, 2010, 2:22:16 AM7/4/10
to web2py-users
Are you so sure __import__() always reloads? I don't believe so, and
that is also why there is a built-in reload(). At least __import__()
does not reload in my following simple test. Jose, would you please
also try this one?

# myapp/modules/foo.py
def bar():
return 'hello world'

# myapp/controllers/test.py
def index():
return local_import('foo', reload=True)

Visit http://localhost:8000/myapp/test and you will see "hello world".
Fine. Don't restart web2py, now change bar() as return 'something
else', refresh your browser. So far I still see "hello world" but not
"something else". Besides, the myapp/modules/foo.pyc is NOT rebuilt
according to its file create timestamp, thus another evidence that the
reload did not happen. I am using latest trunk on Windows XP, Python
2.5.4

By the way, an equivalent, cleaner and faster refactoring is
legitimate, as long as it works. I will agree on a __import__() feels
better than an exec(...), so let's first get things right.

On Jul3, 7:49pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
> It is true that force is ignored. That is because __import__ always
> reloads. This may seem slower but actually it may be faster than the
> previous solution using exec with force=False.
>
> The reason for the change is that the new implementation is supposed to

mdipierro

unread,
Jul 4, 2010, 3:36:53 AM7/4/10
to web2py-users
You are right. I fixed it in trunk and it works for me now.

Massimo

On 4 Lug, 01:22, Iceberg <iceb...@21cn.com> wrote:
> Are you so sure __import__() always reloads? I don't believe so, and
> that is also why there is a built-in reload(). At least __import__()
> does not reload in my following simple test. Jose, would you please
> also try this one?
>
> # myapp/modules/foo.py
> def bar():
>     return 'hello world'
>
> # myapp/controllers/test.py
> def index():
>     return local_import('foo', reload=True)
>
> Visithttp://localhost:8000/myapp/testand you will see "hello world".

Iceberg

unread,
Jul 4, 2010, 7:26:00 AM7/4/10
to web2py-users
Thanks for quick action! I also confirm latest trunk has reload
feature now. So we have a happy ending, for the Independent Day. :-)

On Jul4, 3:36pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
> You are right. I fixed it in trunk and it works for me now.
>
> Massimo
>
> On 4 Lug, 01:22, Iceberg <iceb...@21cn.com> wrote:
>
> > Are you so sure __import__() always reloads? I don't believe so, and
> > that is also why there is a built-in reload(). At least __import__()
> > does not reload in my following simple test. Jose, would you please
> > also try this one?
>
> > # myapp/modules/foo.py
> > def bar():
> >     return 'hello world'
>
> > # myapp/controllers/test.py
> > def index():
> >     return local_import('foo', reload=True)
>
> > Visithttp://localhost:8000/myapp/testandyou will see "hello world".

Jose

unread,
Jul 12, 2010, 1:40:14 PM7/12/10
to web2py-users
The Version 1.80.1 (12/07/2010 16:32:46) still remains the problem, if
the application is served by Cherokee. If it runs directly from the
server web2py, works well.

The error it shows is:

File "/usr/home/web2py/applications/sueldos/controllers/informes.py",
line 27, in informe_ipam
reportes = local_import('reportes', reload=True)
File "gluon/compileapp.py", line 228, in <lambda>
local_import_aux(name,reload,app)
File "gluon/compileapp.py", line 164, in local_import_aux
module = __import__(name)
ImportError: No module named applications.sueldos.modules.reportes

The trunk version works well with both Cherokee and the server itself.

Regards
Jose

mdipierro

unread,
Jul 12, 2010, 3:32:42 PM7/12/10
to web2py-users
1.80.1 is supposed to be identical to trunk. (!?)

Do you have this file: applications/sueldos/modules/reportes.py

Jose

unread,
Jul 12, 2010, 4:52:24 PM7/12/10
to web2py-users


On 12 jul, 16:32, mdipierro <mdipie...@cs.depaul.edu> wrote:
> 1.80.1 is supposed to be identical to trunk. (!?)
>
> Do you have this file: applications/sueldos/modules/reportes.py
>
No, the error does not occur due to missing module.

Now I know how to avoid it, but do not know why it happens.

The steps are:
1) Download the zipped source code (web2py_src.zip)
2) I unzip.
3) Copy the application.
4) Build the config.xml file (for Cherokee)
5) Change the owner: chown-Rh www: www web2py
6) Start cherokee

Under these conditions, the error mentioned in the above message
happens.

Well, If I run web2py (python web2py.py) and stop and try again from
the page served by Cherokee, works well.

Why is that?

mdipierro

unread,
Jul 12, 2010, 6:12:46 PM7/12/10
to web2py-users
No clue
Reply all
Reply to author
Forward
0 new messages