By user12607856 on Oct 18, 2007
The Orca team is in the process of porting the code to work with pyatspi. This is a glue layer that allows Python applications to work with AT-SPI. Several other applications already use it and it will mean that future changes in this area are confined to one place, which will make maintenance and future enhancement easier.
It's a big change for Orca. We had our own wrapper methods to the AT-SPI interfaces and they were different in so many subtle ways.
To try to help find mistakes as we port the code, we've started using some lint like tools for Python. In particular:
They are all nicely in the Ubuntu network repository, so downloading and installing them is trivial and only takes a copy of minutes.
(Aside: Anybody who has kids in the U.S. has probably watched Between the Lions at some point. One of the characters on this show is Cliff Hanger. There is a little ditty that goes with this, something like:
"Cliff Hanger, hanging from a cliff. That's why he's called Cliff Hanger!"
Anyhoo, whenever I hear the word pychecker, it makes me cons up a variant of that. Lifehacker has the same affect. Senility is setting in).
Where was I? Oh yeah, Python linting. The first one we tried was pychecker. It found about 950 errors and warnings in the Orca code. We've now reduced that down to about 20 warnings. Several of these will just go away as we refactor the code for the pyatspi port. There are about 3-4 that we currently haven't a clue how to "fix".
Next was pyflakes. Even after running Orca through pychecker it found about another 100 warnings; mostly for imports of modules that weren't being used in certain source files. Why pychecker didn't flag these is anybodies guess. Each of the tools seems to have their own agenda. What was even more frustrating was a second run of pyflakes found a couple of different problems that the first run missed (and no, I didn't create these problems with my "fixes" from the first pass through).
So we fixed up all the pyflakes warnings and were onto pylint. This generated over 10000 lines of output. It also gave us a score out of 10. We have base Orca code and scripts for applications. Here were the initial scores:
Base Orca files: 3.81 out of 10.
Orca application scripts: 5.45 out of 10
With all the output it's hard to see the wheat from the chaff. We fixed up three simple kinds of "errors" first:
Line too long - by default, it doesn't like lines greater than 80 characters long. One could argue that it's only old fossils like myself that care for this kind of thing. And pylint.
Bad indentation - we use 4 space indentation. pylint was very good at finding these. pychecker and pyflaky didn't even twitch for this problem.
Operator not preceded by a space - it objected if you wrote "a=1" instead of "a = 1". Yes Virginia, there are people out there who write this sort of crud and think nothing is wrong. Hah! pylint catches those evil perpetrators.
It's easy to also suppress or adjust for lots of different coding styles as the pylint man pages show. By using some adjustments to the default regular expressions for variable names, we were able to drastically reduce the output.
After about 2-3 hours hacking away, the output is now down to 5681 lines with the following scores:
Base Orca files: 5.94 out of 10.
Orca application scripts: 7.63 out of 10
I'm sure a few more simple command line options to set some different defaults will get rid of quite a lot more. Then we will need to carefully check over what's left.