Quickly setup a minimal Python CI system using Jenkins and GitHub

written by Andrew Shay on 2018-09-27

This article discusses how to quickly and easily setup a Python CI system using GitHub and Jenkins.

This is useful for anyone who does not have a dedicated CI tool (Travis CI, TeamCity etc.) and just want to get something up and running with minimal effort.

When a GitHub Pull Request is "Opened", "Reopened", or a commit is made, a webhook will be sent to the Jenkins job. The Jenkins job will create a virtual environment, install several tools for running tests and linters, then run those tools against the code base. The output of the tools will be gathered and posted as a comment to the Pull Request via the GitHub API.

This was created to offer Python projects a simple and easy CI system without having to install and maintain dedicated CI software.

Requirements: Jenkins with Python 3.6, GitHub

Read Full Post

Simple Strap - New theme for lektor

written by Andrew Shay on 2018-09-19

Simple Strap is a clean, simple, black and white theme for lektor based on Bootstrap 4.

View on GitHub
Checkout the demo site

How to create a gauge / speedometer graphic with Python

written by Andrew Shay on 2018-06-30

This article discusses how to easily create a speedometer / gauge image in Python with only the Pillow library.

View source code and images on GitHub: python-gauge

I needed to create a gauge graphic in Python but I found many libraries did not have the graphic I needed or required that the gauge be rendered in a browser since the underlying library used was JavaScript. This script only requires the Pillow library since it is generated using two png images.

The gauge graphic is separated into two images. The first image is the needle that points to a number on the gauge. The second image is the gauge without the needle. The final gauge image is generated by rotating the needle image then pasting it on the gauge.

The script is simple. The gauge is half a circle therefore the needle needs to rotate between 0 and 180 degrees. The gauge goes from 0 to 100. So if you want the gauge to point to 20, the script just takes 20% of 180 degrees to rotate the needle.


Copyright (C) 2018 FireEye, Inc., created by Andrew Shay. All Rights Reserved.

import PIL

from PIL import Image

percent = 20  # Percent for gauge
output_file_name = 'new_gauge.png'

# X and Y coordinates of the center bottom of the needle starting from the top left corner
#   of the image
x = 825
y = 825
loc = (x, y)

percent = percent / 100
rotation = 180 * percent  # 180 degrees because the gauge is half a circle
rotation = 90 - rotation  # Factor in the needle graphic pointing to 50 (90 degrees)

dial = Image.open('needle.png')
dial = dial.rotate(rotation, resample=PIL.Image.BICUBIC, center=loc)  # Rotate needle

gauge = Image.open('gauge.png')
gauge.paste(dial, mask=dial)  # Paste needle onto gauge

To modify the gauge image, modify gauge.psd. gauge.png should be the gauge without the needle (hide the needle layer). needle.png should only be the needle on a transparent background and should point at 50 (hide all layers except needle).

How to create a lektor plugin and debug it in PyCharm

written by Andrew Shay on 2018-05-16

I recently created by my first Lektor Plugin, read-full-post, and wanted to create a getting starting guide for creating a plugin and debugging it in PyCharm.

In this article we will pull the lektor project, create a plugin that modifies the body of every blog post, debug the plugin in PyCharm and look at some of the data in the debugger.

Read Full Post

lektor plugin: read full post

written by Andrew Shay on 2018-05-11

I have created a lektor plugin, read full post.
It allows blog listing posts to be shortened with a link to the full post.