Work Summary

Karan Sharma
7 min readNov 4, 2016

--

This blog post is about my work done during the GSoC coding period (May 23 — Aug 15). Doing GSoC has been one of the most amazing experience in my life. Thanks to PSF and coala for giving me this opportunity to work on an amazing open source project. Also a big thanks to Google for running GSoC and cultivating the culture of contributing to Open Source. I have learnt so many things over a span of short three months that would definitely help me grow as a developer.

Work Summary for GSoC’16 with coala(PSF).

That’s a +2411/-495 change over the span of three months 😲

A coala-bears template generator

coala-bears-create is a tool which lets you create Bears easily, by asking you questions and filling a standard config file. The files generated can then be quickly used by filling additional details to get your Bear up and running in no time. The CLI is implemented with the help of Python Prompt Toolkit which helped me plug in features like dropdown list, status bar and prompt method for asking questions to the user.

The templates are present in scaffolding-templates directory. The user is asked to enter the directory where she wants to create the Bear and after the user finishes answering all questions, the data is taken from scaffolding templates, the user’s answers are filled in the templates and a new folder is created for the user with Bear and BearTest files.

Advantage/Motivation:

The advantage of this little application is that, since previously the task of creation of bear meant you need to type/copy some of the standard variable, like certain imports or linter variables which are shared across all Bears. But using this application you just need to specify the value and you have a Bear ready almost instantly without any extra effort required.

coala-bears-create in action!

Syntax Highlighting in coala

Presently coala displays results like this:

Syntax highlighting in the results

The task of this project was to implement Syntax Highlighting for the affected code which brings in some visual enhancement for the user. This task wasn’t as trivial as we didn’t have the information of the language of the file being analyzed, as well as for the fact that we needed dual highlighting (foreground & background colors)

The aim of the task was to highlight the part which is in sourcerange and provide syntax highlighting for the rest of it, since highlighting a text and providing colors on top of it doesn’t work well. I also had to figure out a way where I can still print spaces and tabs in unicode like in the previous version. I began to search for a library for syntax highlighting as # 1 rule in software development is to use what’s existing already. I finally found Pygments library to be ideal for this task.

I used getlexerforfilename and fed sourcerange.file to this, to get the appropriate lexer based on the language of the file. If however there’s no suitable lexer found, an exception is raised which I catch and make TextLexer (plain-text lexer) as the default one. I used highlight method from Pygments library to get a str object which are basically ANSI escape sequences wrapped to my string. I used TerminalTrueColorFormatter to print my results in a terminal. There was another formatter TerminalFormatter but after some hair pulling(read debugging) I realized I couldn’t use it for background highlighting.

Till now, I was able to colorize the results but one important task which was missing was that there were no spaces/tabs markers in the strings. In the old source code, there was a custom function which iterated over the string and if a space or tab is found, it was replaced by the unicode character which seems like a bullet mark in the terminal for space and double right arrows for tabs. I couldn’t do this because the str object I had now was also wrapped with ANSI code escape sequences and I spent almost half a day trying to search a workaround for this.

Not satisfied with whatever method I used, I searched around Pygments docs in hope for finding something. And voila, I was delighted to see that there’s a filter VisibleWhiteSpace which can be provided to the formatter. It worked as expected and this also helped me remove an entire function from the original source code, with an elegant one line solution. I also asked the maintainers of the original code and they seemed to be fine with this new change. I also highlighted the result.message using the same method.

I changed the tests so that they can work with Pygments highlighting and refactored the code a bit, which reduced the duplication of long highlight methods.

Syntax Highlighting in coala!

Bear Documentation Website

The task was to create a website for all coala-bears documentation. I was initially clueless on which stack to choose but after some discussion with Tushar Gautam and Lasse Schuirmann, I decided to go with the awesome AngularJS(https://angular.io/) because of it’s highly customizable filters. I used coala — show-bears json to get a JSON output of all the details/configs of bears present. I parsed this data and used Materiallize to display them in a list of cards, where the user could Read More about the bear in next page or could see some of the important details in the card-reveal option present.

You can take a look at the website here.

This site will be deployed alongside coala-website which is Tushar’s project.

Some coala-bears I made

I enjoy creating new bears for coala, as I religiously use them alongside my side projects. During my GSoC period, I created some bears. Some of them are completed and merged, while some of them are still open and I will continue to work on them after my GSoC is over.

A list of them is available on top of the post.

What I couldn’t do

I have been able to complete most of my proposal tasks and I had to face some difficulties as the project progressed, but nonetheless most of the crucial work has been completed and merged. However, I couldn’t complete Navigation of Results and Embedded Source Code Linting which was mentioned in my project. I hope to continue working on them after my project is over, as the philosophy of GSoC is to imbibe the culture of contributing continuously to Open Source and not be done with it in 3 months.

The task of Navigation of Results was the idea, where the user could go back and forth but the current architecture or design in which coala presents the results made it very difficult to achieve this task and I couldn’t come up with a good clean approach for this.

The problem with Embedded Source Code Linting was, there was no good approach for finding out what the language is being currently analyzed. I did open an issue for a task related to this in which the user would be presented with an error message if she tries to use a wrong linter, but the status of the PR was changed to not happening/wont fix. This is because there is no one single accurate approach for getting the language, even MIME data fails most of the time. Due to these reasons and obstacles, these tasks weren’t done, but I am sure we can come up with some better alternatives to achieve these things by setting a more achievable target.

Other cool stuff I did

I wanted to add ASCIINEMA urls in the bear documentation website, but there wasn’t one single point where I could access them, as they were all tweeted out. I wrote a script to grab all the tweets and filter out the ones which had asciinema url in them.

For fun purposes, I also wrote a script which counts how many times you have been mentioned by @coala-analyzer

They are all located in Twitter Scripts repository in my branch.

Credits

A BIG shout-out to the tools which helped me achieve my tasks

Also thanks to my mentor ManoranjanP, co mentor Lasse, Mischa, AbdealiJK and rest of amazing coala community for helping me throughout the project and providing amazing and helpful reviews on all my PRs. I plan to stay in touch with coala community after GSoC ends, so that we can kick some ass again.

Happy Coding!

--

--

Karan Sharma

Developer| GSoC’16 student @coala_analyzer | Chicken, Beer, Floyd