Documentation Displayer

What do you get when you mix file hosting APIs, Github APIs, PDF converters, and directory comparisons?

A documentation displayer bot of course! 

The Parts Required

In this release I created another bot for the keras repository, this time for documentation. I began with using the skeleton of Gabriel’s existing bot, and changing the functionalities that were unnecessary for the documentation checks. There were four main components of this release, and they were:

Anonymous File Hosting

PyGitHub

PDFKit

Filecmp

All of these were needed in order to accomplish a bot that would detect changes to the documentation in a pull request, and create a link to a file hosting service with a pdf of the built documentation.

Building The Bot

PyGithub was the first place to start as it gave me access to usernames, pull requests, and repository information. Using PyGithub I was able to clone the user’s pull request into a local directory, as well as clone the master branch of keras, and compare the docs folder.

Filecmp was needed in order to compare the directories in both structure, as well as file contents, to ensure the documentation has been changed. Using Filecmp I was able to get both the unchanged files, as well as the changed files to be used in the Github comment. After determining if the documentation had been changed, the next step was to build the documentation using mkdocs, which would generate an .html file to then be converted into a PDF.

After using mkdocs to build the documentation, I used PDFKit to convert html from a local file into a pdf. This solution works well, but not amazing, as some of the original html goes missing due to libraries loaded in such as bootstrap. Nonetheless this still works well, and converts the file appropriately.

Lastly it was time to host the file temporarily, so that the document can be linked within the Github comment. Anonymous Files was a perfect solution for this, and allowed me to POST and GET using python requests libraries.

End Results

Files have officially made their way into the docDisplayer bot comments, thanks to the components mentioned above. The bot will only be used if a change in the documentation is seen, otherwise it will not run. This was an interesting issue to work on that took several turns and had me carefully select the tools needed to accomplish this pull request.

Keras botting has been a wild ride.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s