Re: pychecker catches IndexError exception while importing /django/db/models/base.py

2009-01-23 Thread ivan

Thanks for the suggestion. My app is named 'control' and my django
project name is 'geni'. Running pychecker on the app dir raises a
problem in pychecker itself -- it seemed to be that it was unable to
open one of the sources files:

$ pychecker control/
Processing control/...
  Caught exception importing module control/:
File "/var/lib/python-support/python2.5/pychecker/checker.py",
line 620, in setupMainCode()
  self._setupMainCode(file, filename, module)
File "/var/lib/python-support/python2.5/pychecker/checker.py",
line 625, in _setupMainCode()
  self.main_code = function.create_from_file(file, filename,
module)
File "/var/lib/python-support/python2.5/pychecker/function.py",
line 128, in create_from_file()
  file.seek(0)
  AttributeError: 'NoneType' object has no attribute 'seek'

However, digging more into the pychecker code I found out that
pychecker was attempting to open the 'control' dir as a file. Then I
checked my pychecker version and discovered that I'm running version
0.8.17 while the latest version is 0.8.18. I upgraded to 0.8.18 and
ran again:

$ pychecker control
Processing module control (control)...

Warnings...

None

However, this last run leaves me skeptical. It does not seem that it
actually imported any modules and I'm getting no prints of
model_module.__name__ so its not importing any of the django models.
Finally I tried running:

$ pychecker control/*py
Processing module admin (control/admin.py)...
model_module.__name__ :  django.contrib.contenttypes.models
model_module.__name__ :  django.contrib.auth.models
model_module.__name__ :  django.contrib.auth.models
model_module.__name__ :  django.contrib.auth.models
model_module.__name__ :  django.contrib.auth.models
model_module.__name__ :  geni.control.models
model_module.__name__ :  geni.control.models
model_module.__name__ :  geni.control.models
model_module.__name__ :  geni.control.models
model_module.__name__ :  geni.control.models
model_module.__name__ :  geni.control.models
model_module.__name__ :  django.contrib.sessions.models
model_module.__name__ :  django.contrib.sites.models
model_module.__name__ :  django.contrib.admin.models
Processing module forms (control/forms.py)...
Processing module __init__ (control/__init__.py)...
Processing module models (control/models.py)...
model_module.__name__ :  models
  Caught exception importing module models:
File "/usr/lib/python2.5/site-packages/pychecker/checker.py", line
698, in setupMainCode()
File "models.py", line 539, in ()
File "/usr/lib/python2.5/site-packages/django/db/models/base.py",
line 52, in __new__()
  IndexError: list index out of range
Processing module urls (control/urls.py)...
  Caught exception importing module urls:
File "/usr/lib/python2.5/site-packages/pychecker/checker.py", line
698, in setupMainCode()
File "control/urls.py", line 39, in ()
File "/usr/lib/python2.5/site-packages/django/contrib/admin/
__init__.py", line 40, in autodiscover()
File "control/admin.py", line 108, in ()
File "/usr/lib/python2.5/site-packages/django/contrib/admin/
sites.py", line 64, in register()
  AlreadyRegistered: The model Donation is already registered
Processing module views (control/views.py)...


So its hiccuping on the same issue when importing models, and has a
problem in re-registering a specific model class used in the control
app called 'Donation'. For the last issue, I'm importing Donation in
admin.py using: from geni.control.models import Donation, and I don't
have Donation registered anywhere else. So I'm not sure how to fix
this problem either, except that I don't really care much about
debugging the admin portion of the site so I might just comment out
the register calls.

The original problem remains though.

thanks,
ivan.

On Jan 23, 4:02 am, zvoase  wrote:
> I think I might be able to spot where the problem is. Try running
> pychecker on your app folder, rather than models.py.
>
> Let's assume your app is called myapp, so you have a directory
> structure something like this:
>
> myapp/
> -- __init__.py
> -- models.py
> -- views.py
> -- tests.py
> (et cetera)
>
> If pychecker were doing 'import myapp', then the models module would
> be accessible from 'myapp.models'. Therefore, models_module's __name__
> attribute would be 'myapp.models', and the code would run fine;
> 'myapp.models'.split('.') would return ['myapp', 'models'], and the
> [-2] index of that list would be 'myapp'.
>
> However, because you're running pychecker directly on the models.py
> file, its __name__ attribute is just 'models', which raises an error
> in the Django code because 'models'.split('.') returns ['models'] --
> this has no [-2] index, hence the exception.
>
> Just try running pychecker on the 'myapp/' folder (if possible), and
> see if that fixes the problem.
>
> On Jan 22, 10:22 pm, ivan  wrote:
>
> > Hi all,
>
> > I'm attempting to run pychecker on my django code (an application's
> > 

Re: pychecker catches IndexError exception while importing /django/db/models/base.py

2009-01-23 Thread zvoase

I think I might be able to spot where the problem is. Try running
pychecker on your app folder, rather than models.py.

Let's assume your app is called myapp, so you have a directory
structure something like this:

myapp/
-- __init__.py
-- models.py
-- views.py
-- tests.py
(et cetera)

If pychecker were doing 'import myapp', then the models module would
be accessible from 'myapp.models'. Therefore, models_module's __name__
attribute would be 'myapp.models', and the code would run fine;
'myapp.models'.split('.') would return ['myapp', 'models'], and the
[-2] index of that list would be 'myapp'.

However, because you're running pychecker directly on the models.py
file, its __name__ attribute is just 'models', which raises an error
in the Django code because 'models'.split('.') returns ['models'] --
this has no [-2] index, hence the exception.

Just try running pychecker on the 'myapp/' folder (if possible), and
see if that fixes the problem.

On Jan 22, 10:22 pm, ivan  wrote:
> Hi all,
>
> I'm attempting to run pychecker on my django code (an application's
> models.py file) and get the following output:
>
> $ pychecker models.py
> Processing models...
>  Caught exception importing module models:
>    File "/var/lib/python-support/python2.5/pychecker/checker.py",
> line 619, in setupMainCode()
>    File "models.py", line 538, in ()
>    File "/usr/lib/python2.5/site-packages/django/db/models/base.py",
> line 51, in __new__()
>  IndexError: list index out of range
>
> Warnings...
>
> models:1: NOT PROCESSED UNABLE TO IMPORT
>
> My django version is '1.0.2 final'.
>
> The IndexError happens on the final line of code extract below:
>
> # Figure out the app_label by looking one level up.
> # For 'django.contrib.sites.models', this would be 'sites'.
> model_module = sys.modules[new_class.__module__]
> kwargs = {"app_label": model_module.__name__.split('.')[-2]}
>
> I added a 'print model_module.__name__' above this line and I get the
> following output before the exception:
> django.contrib.contenttypes.models
> django.contrib.auth.models
> django.contrib.auth.models
> django.contrib.auth.models
> django.contrib.auth.models
> models
>
> Not sure if the last models that triggers the exception is the models
> file I ran pychecker on or another file? I have all my django env
> variables set up correctly and can do runserver, dbshell ,etc.
>
> Any ideas as to why pychecker on my models file would throw this
> exception in the base django models file?
>
> thanks,
> ivan.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en
-~--~~~~--~~--~--~---



pychecker catches IndexError exception while importing /django/db/models/base.py

2009-01-22 Thread ivan

Hi all,

I'm attempting to run pychecker on my django code (an application's
models.py file) and get the following output:

$ pychecker models.py
Processing models...
 Caught exception importing module models:
   File "/var/lib/python-support/python2.5/pychecker/checker.py",
line 619, in setupMainCode()
   File "models.py", line 538, in ()
   File "/usr/lib/python2.5/site-packages/django/db/models/base.py",
line 51, in __new__()
 IndexError: list index out of range

Warnings...

models:1: NOT PROCESSED UNABLE TO IMPORT

My django version is '1.0.2 final'.

The IndexError happens on the final line of code extract below:

# Figure out the app_label by looking one level up.
# For 'django.contrib.sites.models', this would be 'sites'.
model_module = sys.modules[new_class.__module__]
kwargs = {"app_label": model_module.__name__.split('.')[-2]}

I added a 'print model_module.__name__' above this line and I get the
following output before the exception:
django.contrib.contenttypes.models
django.contrib.auth.models
django.contrib.auth.models
django.contrib.auth.models
django.contrib.auth.models
models

Not sure if the last models that triggers the exception is the models
file I ran pychecker on or another file? I have all my django env
variables set up correctly and can do runserver, dbshell ,etc.

Any ideas as to why pychecker on my models file would throw this
exception in the base django models file?


thanks,
ivan.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en
-~--~~~~--~~--~--~---