Jul 26, 2014

GSoC 2014 - End of week 10 update

"It is faster to make a four-inch mirror and then a six-inch mirror than to make a six-inch mirror." -- Bill McKeenan

A quote which I recently came across, is proven true by my recent GSoC endeavors.

1.  IDLE Linenumbering project

During the weekly IRC meet, it was suggested to try an alternative approach to linenumbering in IDLE.
The first approach, which involved using a Canvas based approach to display linenumbering can be seen here. The drawback was that it had a small, but continuous processor footprint, due to constant redrawing(and related calculations). My mentor suggested that I try to implement it using a Text widget, where we can obtain the same redrawing for "free"(earlier, there were two layers of calcuations - first we calculate to tell Tk where to place an object, and Tk then has to do its own internal calculations).
Now, we use a Tk Text widget, wherein the intermediate calculation step is skipped.

While the linenumbering is complete(at this time), I am working on integrating breakpoints to IDLE. What surprised me was, I was aware of all the corner cases to be checked, what to test, where to put the config files etc. The fact that I was able to complete the linenumbering implementation in 3 days in the second attempt, compared to the earlier attempt, which took a week, proves the quote at the top of this page. 
In development version of IDLE Linenumbering using Text widget approach

2. 3rd Party Checker integration

Continuing from the previous week, I succeeded in implementing a Popen based approach for checking files from within IDLE. The trick was to execute the subprocess in the directory that the file is located. This approach solved problems on Window's when executing files like
"pyflakes C:\Python\Lib\turtle.py"
Any guesses?

Yes! It is that "\t" in there. After trying out many combinations, I came to the conclusion that, it was too cumbersome to deal to with it in a OS independent way. So I forced Popen to change its cwd(current working directory) to that of the file.
This got us to the issue of Popen blocking the GUI when the subprocess was executing. While not noticeable for small files, it made the GUI unresponsive on large files and/or elaborate checkers.  I spent a couple of days trying to understand the asyncio module along with the Twisted package(this was the first time I tried asynchronous programming.) To ensure compatibility with the 2.7 branch(which does not have the asyncio module), I later concentrated on a tkinter only approach, using callbacks. I derived a CheckerWindow class from OutputWindow class. The Popen was made to write to a temporary file description instead of using a PIPE object. The new CheckerWindow class then polls the temporary file descriptor for changes. This approach worked, with the result that checking is now non-blocking and totally asynchronous.

I worked on two different subprojects in the past two weeks. The first part was unplanned, but I am really glad that I did, as implementing the same project in two different ways was a great learning experience for me. 

No comments:

Post a Comment