Tuesday, November 20, 2012

Debugging SQL in Django (with PyDev)

I'm working on a Django project recently and one of the things that came up was debugging SQL statements a bit to see what was actually going on.

After researching a bit, I found: http://pypi.python.org/pypi/django-debug-toolbar, which when installed wraps around the calls that Django does to the DB and prints the actual SQL statements used.

I didn't really install it as a debug toolbar as it recommends, but I use it in the interactive console shell to see how things happen when I'm experimenting.

To do this, after installing it and adding 'debug_toolbar' to your INSTALLED_APPS in Django, one can start the interactive console shell with Django support (if you're in a Python editor just do: Ctrl+2 dj shell) and add write the import:

from debug_toolbar.management.commands import debugsqlshell


Now, when you do some operation that does an SQL operation, it'll be printed to the console, while having all the PyDev niceties on the console (such as code-completion). Pretty nice.

Tuesday, August 14, 2012

PyDev & Eclipse 4.2 (i.e.: stick with Eclipse 3.8)

Ok, I've been giving a whirl on supporting Eclipse 4.2 on PyDev and everything seems to work as expected, but unfortunately, I still can't recommend the Eclipse 4.x series over the 3.x series because performance-wise Eclipse 4 is still not on par with Eclipse 3 (and for me the only gain was that floating docks are now better -- as for skinning, I don't really think it's much better for final users unless someone else already got to the point of doing a skin exactly as you'd want -- so I think that for now, Aptana Studio 3 skinning (themeing) is a better solution -- and targeted at Eclipse 3.x).

I have hopes that those issues will be addressed in a newer release of Eclipse 4, but the truth is that right now Eclipse 4 feels sluggish when compared to Eclipse 3 (even changing configurations on the Eclipse appearance preferences for having some performance gains).

So, if by any chance you've just gotten into PyDev and it doesn't seem as speedy as you'd like, please make sure you check it with Eclipse 3.8 (in the downloads page: http://download.eclipse.org/eclipse/downloads/ there's a link to Eclipse 3.x downloads available: http://download.eclipse.org/eclipse/downloads/eclipse3x.html).

Also, make sure that you have the latest version of java as it may make a difference.

Or, if you've gotten the Aptana Studio 3 download directly, you're already good to go -- as it's already based on Eclipse 3.x and has PyDev preinstalled (see http://pydev.org/download.html for links).

Monday, July 02, 2012

Git (multiple repos)

Improving my Git workflow has been one of my current targets lately... Especially when working with multiple projects.

So, although I'm working all the time inside Eclipse, I still like to use the command line for many things (so, even with the Aptana Studio 3 Git integration and EGit having improved, I still use the command line a lot on common operations, resorting to other options mostly when investigating the history of a repository or some other thing which may be suboptimal in the command line).

To improve that situation, I ended up creating a tool... Yes, I know there are probably many other command line tools that try to accomplish that, but I did a good amount of research and didn't find anything that worked as I wanted -- and not nearly as fun (but I appreciate suggestions in this realm).

The tool I did is hosted at GitHub: https://github.com/fabioz/mu-repo, and it's freely available (GPL 3).

It's a Python program which interfaces with the git binary to execute whatever is needed. Also, for diffing operations it currently relies on WinMerge (meaning this part of the tool is Windows only for now, but if there's interest, it should be straightforward having it support other diff tools such as KDiff3).

My basic workflow is now:

cd /workspace (which has many .git subrepos)

Note: all the "mu" operations below will actually be applied to all the git subdirs (must be previously registered), so, a single command line is enough for dealing with all repositories at once -- yes, I know about git submodules, but I don't really like how it works -- and it's one of the main reasons this tool exists :)

To get changes:

mu up (fetches origin for the current branch updating the origin/current_branch reference -- I found it weird that trying to do "git fetch origin current_branch" ended up updating FETCH_HEAD instead of origin/current_branch -- also, this and most other operations work only in the current branch, leaving other branches or references untouched).

mu dd origin/current_branch (preview incoming changes: compare current branch HEAD to origin/current_branch).

mu rebase origin/current_branch (rebase incoming changes -- could also be: mu merge origin/current_branch).

To submit changes:

mu st (check status of changed files -- indexed or not)
mu dd (diff working copy with winmerge while editing changes and keeping the working dir updated even if no symlink support is available)
mu acp "message" (add all working copy changes, commit, push)

To start working on a feature:

mu co -b branch_name (create branch for all repos)
mu ac "message"  (add / commit changes on that branch)
mu co main_branch (go back to main branch)
mu rebase branch_name (get the changes from the branch into the main branch)
mu branch -D branch_name (remove that local branch)



Note that for my workflow I work mostly without taking "advantage" of the git index -- usually I review things with "mu dd" and on "mu ac" I add all the changes to the index and commit in a single operation (before that I was almost always doing "git add -A" and "git commit -m "message"" anyways).

I also still configure many things as I posted previously: http://pydev.blogspot.com.br/2011/02/git-on-command-line.html, but a bunch of things are now better integrated with this tool :)

Also, the tool works for a directory that has a '.git' repository, so, operations such as the diff with WinMerge can be used even when working with a single git repository.

p.s.: The tool is still in beta, so, although I'm using it all the time, it's possible that some things are not working as they should -- but on the good side, I still haven't been able to corrupt any of my git repos :)

Thursday, June 28, 2012

PyDev 2.6.0 released

PyDev 2.6.0 is just out of the door.

Main in this release were changes in the interactive console -- and mostly by external contributors, so, it seems this feature has really picked up some traction :)

Hussain Bohra made it possible to have an interactive console bound to a debugger frame and James Blackburn did a bunch of fixes in it.

Aside from that, the default PyUnit runner has new options to include/exclude files from the test loading process and Jython has an annoying fix done (print can be used as a dotted notation) along with many other fixes (see: http://pydev.org for more details).

Also, the PyDev official issue tracker is now the same tracker used in Aptana Studio 3: https://jira.appcelerator.org/browse/APSTUD/ (there's a component related to PyDev there).

The issues currently on Sourceforge will be migrated to that tracker, but there's no way to make the current Sourceforge trackers read-only, so, I'm just redirecting people to the new tracker and asking not to post on the old one -- hope that works :)

It's interesting to note that now the official Eclipse release is focused on Eclipse 4.x (and not on 3.x)... the integration has already been tested, but not as much as the 3.x series, so, please report any issues found in the way.

Tuesday, April 10, 2012

PyDev 2.5.0 released

Major things in the PyDev 2.5.0 release include:

  • Proper support for Django 1.4 (as it's layout changed, the project creation wizard wasn't working properly).
  • Better patching of Django 1.4 for the debugger and auto-reload (details at the end of the page: http://pydev.org/manual_adv_django.html). Note: there is an issue when using it on Linux, which is already fixed in the nightly build, so, if you are on Linux and want to experiment with it, please update to the current nightly build.
  • The interactive console can now be attached to the variables/expressions view (the preference at: window > preferences > PyDev > Interactive Console and check 'Connect console to Variables Debug View?' must be enabled). Also, there's drag and drop support for it now.

Aside from those, many bugs were fixed and minor improvements were done. More details can be seen at: http://pydev.org/