Yeap, sometimes developing in Eclipse can become hard... especially when things don't go your way ;-)
The major problem for doing the Package Explorer in Pydev is that the CNF (Common Navigator Framework) that is provided in Eclipse has some deficiencies when it commes to providing the default actions that are provided to the default resources (IFile, IFolder) for objects that are not really implementations of those interfaces, but should be able to adapt to that interface.
The first stop in the way was that you have to provide a factory to the adapt protocol, whereas it is common in Eclipse to just make your object IAdaptable and have it working... after having that solved, it appears that the default actions only work on actual implementations, and not objects that adapt to that interface... maybe a sign that the CNF is still not completely ready (still has lots of rough edges)...
Anyway, I hope to have a first working version in the next release -- there are already some things that may deserve a release, such as some significant changes in the debugger and some niceties provided by Gergely Kis to save the project pythonpath in a file to be added to the repository and having a 'default interpreter' in the combo for selecting which interpreter to use for a run.
Monday, October 23, 2006
Sunday, October 08, 2006
Package Explorer for Pydev
Ok, I've been thinkering about the next thing to do in pydev, and after taking a look at several options, creating a package explorer (instead of just using the regular navigator) seemed like a nice addition -- that's actually an old request but only when Eclipse 3.2 was added, a 'default' way of doing it was provided, so, here we go...
After searching the net for some time, the best resources to help in this implementation were:
After passing the first and second tutorial in the blog, it became clear how to actually add content to make the outline of the python files in the custom navigator... I've already checked in a version that has a basic outline for python classes, but there are still some points to play with, such as making the sort of the tokens from files and making the flat/hierarchical view.
The working sets will not be available right now, as this 'common navigator framework' still does not support it (but it appears that Eclipse 3.2.1 will support it).
After searching the net for some time, the best resources to help in this implementation were:
- http://scribbledideas.blogspot.com/2006/05/building-common-navigator-based-viewer.html
- http://scribbledideas.blogspot.com/2006/06/what-does-common-navigator-framework.html
- http://scribbledideas.blogspot.com/2006/05/building-common-navigator-based-viewer_22.html
- http://wiki.eclipse.org/index.php/Common_Navigator_Framework
After passing the first and second tutorial in the blog, it became clear how to actually add content to make the outline of the python files in the custom navigator... I've already checked in a version that has a basic outline for python classes, but there are still some points to play with, such as making the sort of the tokens from files and making the flat/hierarchical view.
The working sets will not be available right now, as this 'common navigator framework' still does not support it (but it appears that Eclipse 3.2.1 will support it).
Friday, September 29, 2006
Configuring pydev to work with django
Update: Pydev now has a new Django integration. See: http://pydev.org/manual_adv_django.html
Ok, some time ago I've covered how to configure pydev to work with Turbogears, and since them, I've been having some requests to do the same for Django, so... here we go ;-)
As with Turbogears, I still don't have any previous experience working with Django, so, it may be good to see how easy it is to get started with it for others!
First step: get Django. Obvious place (after searching for it): http://www.djangoproject.com/
I started by reading the overview, and it seems to be straightforward... now on to something real: downloading it... it says it only needs python, but I didn't find information on which is the preferred version. I googled for it and it appears that it is still not working well with python 2.5, so, I'll go with python 2.4.
Second step: install
[C:\bin\Python24]python e:\Install\Dev.Python\Django-0.95\setup.py install
>> The required version of setuptools (>=0.6c1) is not available, and can't be installed while this script is running. Please install a more recent version first.
The tutorial says that it will attempt to grab setuptools if setuptools is not there, but unfortunatelly it seems it does not upgrade if a version is already there.
So, after googling a little, I found http://peak.telecommunity.com/DevCenter/EasyInstall#installing-easy-install and discovered that I had to download an ez_setup.py script and execute it. It appears to work without any problems, so, on to trying to install django again...
[C:\bin\Python24]python e:\Install\Dev.Python\Django-0.95\setup.py install
still gives me problems, because it requires me to be in the same folder where setup.py is...
[E:\Install\Dev.Python\Django-0.95]c:\bin\Python24\python.exe setup.py install
seems to solve it... smoke test: python -c "import django" seems to work ok
It also requires a database (as I'm just testing, pysqlite seems a good option -- I'm using version 2.3.0)
Now, on to re-configure the pydev interpreter to add those new paths... I'm kind of lazy, so, usually I just remove the interpreter and add it again, instead of figuring out just the new paths (I also thinks it's safer, as it gets all the folders it finds in the pythonpath automatically). More info on that at http://www.fabioz.com/pydev/manual_101_interpreter.html
Now, on to the actually doing something
To create a base project it provides a script, so let's do it:
django-admin.py startproject mysite
It created a 'mysite' folder with some files... still in the command line (inside the mysite folder), it says to start django with:
python manage.py runserver
And voila... it's running. Now, on to do that from inside Eclipse.
Eclipse requires your code to be under a project, so, the 'new pydev project' wizard should be used, pointing the project contents to the 'mysite' folder or to a parent folder. As there is usually much more than just code in a project -- like folders for python, c++, docs... and as in this example we surely won't have a c++ folder, the initial project structure became:
/mysite
/docs
/src <-- this is the folder that should be added to the project pythonpath (in the project properties)
/mysite <-- I moved the initial files to this folder (so that we can make "import mysite" as the src is added to the pythonpath)
-- for more details on creating a project and setting the project pythonpath, check: http://www.fabioz.com/pydev/manual_101_project_conf.html
Now, on to starting the server from within pydev:
If you just run the manage.py file (just open it and press F9), it will show you a message with its usage, so, run it once and then go to the menu: Run > Run... and select the 'mysite manage.py' run and put in the program arguments runserver.
Now, running it like that leaves us without any prompt inside of the Eclipse console. Taking a closer look in the django code, it appears to have an autoreloader structure (I guess that's something common to web-servers), so, as it is actually run in another process, we won't have any output. To fix this in the testing environment (after killing the process inside of Eclipse and the other process that is still running in the computer), we can just add another argument, so, now as arguments we have runserver --noreload
Note that the Eclipse console currently does not have a Ctrl+Break, so, you have to actually kill it in the red button in the console, and to re-run the last run, just use Ctrl+F11.
Now, on to set the sqlite parameters and create the actual database -- according to the tutorial, just set the engine and file to be used for sqlite and the on to:
python manage.py syncdb
-- I usually do that stuff on a separate prompt, as it is nice to run things inside of Eclipse, but having to change the argument for each different run is not all that nice (so, an open shell is always welcome)
and created a superuser... if you configured the auto-refresh for Eclipse as in http://www.fabioz.com/pydev/manual_101_eclipse.html, a new file should be appearing in the database file for sqlite -- if you pointed it to some file inside of your project (if you still haven't the auto-refresh configure, I really advise doing it, as it can be a pain having to F5 for it to refresh the folders when some external change is done to the filesystem)
Now, keeping on with the tutorial:
python manage.py startapp polls
and copied the example from the homepage. Defining the model seems straightforward, and code-completion / code-analysis should be already working ;-)
Making the syncdb again updates my sql with the new structure (pretty nice).
Now, adding the admin interface seems pretty straightforward, and without the auto-reload, the regular debugger works pretty well -- test it by putting a breakpoint after creating the __str__ function for the Poll class in the example and pressing F11 (used to debug the last run). If you want to keep the auto-reloader and still debug, you'll have to use the remote debugger that comes with the extensions to debug, as it does not rely on having the process started from Eclipse. Check http://www.fabioz.com/pydev/manual_adv_remote_debugger.html for more details.
And I guess that's it for the pydev configuration... code-completion, code-analysis, debugger, etc. should all be working.
You can now enjoy working with django inside of pydev!
Cheers,
Fabio
Ok, some time ago I've covered how to configure pydev to work with Turbogears, and since them, I've been having some requests to do the same for Django, so... here we go ;-)
As with Turbogears, I still don't have any previous experience working with Django, so, it may be good to see how easy it is to get started with it for others!
First step: get Django. Obvious place (after searching for it): http://www.djangoproject.com/
I started by reading the overview, and it seems to be straightforward... now on to something real: downloading it... it says it only needs python, but I didn't find information on which is the preferred version. I googled for it and it appears that it is still not working well with python 2.5, so, I'll go with python 2.4.
Second step: install
[C:\bin\Python24]python e:\Install\Dev.Python\Django-0.95\setup.py install
>> The required version of setuptools (>=0.6c1) is not available, and can't be installed while this script is running. Please install a more recent version first.
The tutorial says that it will attempt to grab setuptools if setuptools is not there, but unfortunatelly it seems it does not upgrade if a version is already there.
So, after googling a little, I found http://peak.telecommunity.com/DevCenter/EasyInstall#installing-easy-install and discovered that I had to download an ez_setup.py script and execute it. It appears to work without any problems, so, on to trying to install django again...
[C:\bin\Python24]python e:\Install\Dev.Python\Django-0.95\setup.py install
still gives me problems, because it requires me to be in the same folder where setup.py is...
[E:\Install\Dev.Python\Django-0.95]c:\bin\Python24\python.exe setup.py install
seems to solve it... smoke test: python -c "import django" seems to work ok
It also requires a database (as I'm just testing, pysqlite seems a good option -- I'm using version 2.3.0)
Now, on to re-configure the pydev interpreter to add those new paths... I'm kind of lazy, so, usually I just remove the interpreter and add it again, instead of figuring out just the new paths (I also thinks it's safer, as it gets all the folders it finds in the pythonpath automatically). More info on that at http://www.fabioz.com/pydev/manual_101_interpreter.html
Now, on to the actually doing something
To create a base project it provides a script, so let's do it:
django-admin.py startproject mysite
It created a 'mysite' folder with some files... still in the command line (inside the mysite folder), it says to start django with:
python manage.py runserver
And voila... it's running. Now, on to do that from inside Eclipse.
Eclipse requires your code to be under a project, so, the 'new pydev project' wizard should be used, pointing the project contents to the 'mysite' folder or to a parent folder. As there is usually much more than just code in a project -- like folders for python, c++, docs... and as in this example we surely won't have a c++ folder, the initial project structure became:
/mysite
/docs
/src <-- this is the folder that should be added to the project pythonpath (in the project properties)
/mysite <-- I moved the initial files to this folder (so that we can make "import mysite" as the src is added to the pythonpath)
-- for more details on creating a project and setting the project pythonpath, check: http://www.fabioz.com/pydev/manual_101_project_conf.html
Now, on to starting the server from within pydev:
If you just run the manage.py file (just open it and press F9), it will show you a message with its usage, so, run it once and then go to the menu: Run > Run... and select the 'mysite manage.py' run and put in the program arguments runserver.
Now, running it like that leaves us without any prompt inside of the Eclipse console. Taking a closer look in the django code, it appears to have an autoreloader structure (I guess that's something common to web-servers), so, as it is actually run in another process, we won't have any output. To fix this in the testing environment (after killing the process inside of Eclipse and the other process that is still running in the computer), we can just add another argument, so, now as arguments we have runserver --noreload
Note that the Eclipse console currently does not have a Ctrl+Break, so, you have to actually kill it in the red button in the console, and to re-run the last run, just use Ctrl+F11.
Now, on to set the sqlite parameters and create the actual database -- according to the tutorial, just set the engine and file to be used for sqlite and the on to:
python manage.py syncdb
-- I usually do that stuff on a separate prompt, as it is nice to run things inside of Eclipse, but having to change the argument for each different run is not all that nice (so, an open shell is always welcome)
and created a superuser... if you configured the auto-refresh for Eclipse as in http://www.fabioz.com/pydev/manual_101_eclipse.html, a new file should be appearing in the database file for sqlite -- if you pointed it to some file inside of your project (if you still haven't the auto-refresh configure, I really advise doing it, as it can be a pain having to F5 for it to refresh the folders when some external change is done to the filesystem)
Now, keeping on with the tutorial:
python manage.py startapp polls
and copied the example from the homepage. Defining the model seems straightforward, and code-completion / code-analysis should be already working ;-)
Making the syncdb again updates my sql with the new structure (pretty nice).
Now, adding the admin interface seems pretty straightforward, and without the auto-reload, the regular debugger works pretty well -- test it by putting a breakpoint after creating the __str__ function for the Poll class in the example and pressing F11 (used to debug the last run). If you want to keep the auto-reloader and still debug, you'll have to use the remote debugger that comes with the extensions to debug, as it does not rely on having the process started from Eclipse. Check http://www.fabioz.com/pydev/manual_adv_remote_debugger.html for more details.
And I guess that's it for the pydev configuration... code-completion, code-analysis, debugger, etc. should all be working.
You can now enjoy working with django inside of pydev!
Cheers,
Fabio
Tuesday, September 26, 2006
Pydev 1.2.4 released
This release fixes a number of minor things from the last release and adds some new features... I'm not sure if it was the alignment on the planets, but after only 5 days a considerable amount of stuff was done, so I think that a release was a good option (even without any outstanding bugs in the previous release)
Some noteworthy things:
- A long-open debugger bug was fixed with a patch from Kovan (on linux, sometimes it would not show variables after a step-over)
- Yield is correctly treated as an expression now for python 2.5
- Code-completion for parameters: in the open-source version it will get the completions for the tokens that are previously defined in a context and offer them as completions. In the extensions it will bring suggestions with all the tokens available for class methods/attributes for the project. Currently it shows all, but I intend to filter those later, to base it on previous tokens already declared in the context.
- Code-analysis: now won't give you errors if it finds:
Hope you enjoy!
Grab the extensions at:http://www.fabioz.com/pydev/
And the open-source at:http://pydev.sourceforge.net/
Some noteworthy things:
- A long-open debugger bug was fixed with a patch from Kovan (on linux, sometimes it would not show variables after a step-over)
- Yield is correctly treated as an expression now for python 2.5
- Code-completion for parameters: in the open-source version it will get the completions for the tokens that are previously defined in a context and offer them as completions. In the extensions it will bring suggestions with all the tokens available for class methods/attributes for the project. Currently it shows all, but I intend to filter those later, to base it on previous tokens already declared in the context.
- Code-analysis: now won't give you errors if it finds:
- classes that have __getattribute__ or __getattr__ overriden
- assigns that are initially None
- assigns to a function call and not a class definition
Hope you enjoy!
Grab the extensions at:http://www.fabioz.com/pydev/
And the open-source at:http://pydev.sourceforge.net/
Tuesday, September 19, 2006
Pydev 1.2.3 released
Nice numbering hum?
It's out -- support for 2.5 right on time with the python 2.5 release... I didn't really plan for it like this, but I think it's a nice touch ;-)
In case you want the details for the release, check:
Pydev Extensions: http://www.fabioz.com/pydev
Pydev: http://pydev.sf.net
And I've covered most details on my previous posts, so, I'll leave this one short.
It's out -- support for 2.5 right on time with the python 2.5 release... I didn't really plan for it like this, but I think it's a nice touch ;-)
In case you want the details for the release, check:
Pydev Extensions: http://www.fabioz.com/pydev
Pydev: http://pydev.sf.net
And I've covered most details on my previous posts, so, I'll leave this one short.
Subscribe to:
Posts (Atom)