Plugin approach of Coily

coily is a Python script designed from the beginning to provide a plugin based platform for building Spring Python apps. Another important feature is version control of the plugins. Developers should not have to worry about installing an out-of-date plugin that was designed for an older version of Spring Python. coily allows different users on a system to have different sets of plugins installed. It also requires no administrative privileges to install a plugin.

Key functions of coily

coily is included in the standard installation of Spring Python. To see the available commands, just ask for help.

The following table elaborates these commands.

Required parts of a plugin

A coily plugin closely resembles a Python package with some slight tweaks. This doesn't mean that a plugin is meant to be installed as a Python package. It is only a description of the folder structure.

Let's look at the layout of the gen-cherrypy-app plugin as an example.

Some parts of this layout are required, and other parts are not. The top folder is the name of the plugin.

A plugin requires a __init__.py file inside the top directory.

__init__.py must include a __description__ variable. This description is shown when we run the coily --help command.

__init__.py must include a command function, which is either a create or apply function. create is used when the plugin needs one argument from the user. apply is used when no argument is needed from the user.

Let's look at how gen-cherrypy-app meets each of these requirements.

We can already see from the diagram that the top level folder has the same name as our plugin.

Inside __init__.py, we can see the following help message defined.

__description__ = "plugin to create skeleton CherryPy applications"

gen-cherrypy-app is used to create a skeleton application. It needs the user to supply the name of the application it will create. Again, looking inside __init__.py, the following method signature can be found.

def create(plugin_path, name)

plugin_path is an argument provided to gen-cherrypy-app by coily, which points at the base directory of gen-cherrypy-app. This argument is also provided for plug-ins that use the apply command function.

Creating a skeleton CherryPy app

The rest of the files listed on the diagram above form a template of an application.

Before we create our CherryPy application, we are missing something. In the earlier screenshot, this plugin wasn't listed. We need to find it and install it. First, let's see how we can look up existing plugins.

Seeing gen-cherrypy-app listed, let's install it using coily without touching a browser.

Let's use the plugin to create a CherryPy application called sample_app. Since we just installed it, the plugin now shows up on coily's help menu. With that in place, we can then run the command to create sample_app.

It replaces all instances of ${name} in each file with sample_app

It replaces all instances of ${properName} in each file with Sample_app

It renames cherrypy-app.py as sample_app.py

gen-cherrypy-app creates a directory named sample_app and copies the files listed above into it. It also does some transformations of the files, based on the argument sample_app.

To run the app, switch to the sample_app directory, and run the main script.

./sample_app.py

Now we can visit our running application at http://127.0.0.1:8080.

Let's inspect app_context.py and see some of the key features wired by gen-cherrypy-app.

This is the root object being wired. The rest of the configuration (not shown here) is mostly security configuration steps.

The security configuration with Spring Python requires many steps. gen-cherrypy-app helps out by pre-wiring most of the security parts, allowing the user to modify as needed rather than build from scratch.

From here, we can log in with the hard-wired credentials to view our expandable application.

Currently, there are no controller objects. However, it would take little effort to add such a layer.

This plugin is simple enough that most of the work spent in improving this plugin can be focused on the template files. This tactic is very useful to build other templates for other types of application.

Summary

coily was built to download, install, and utilize plugins. gen-cherrypy-app nicely creates a Spring-ified CherryPy application using a set of templates. This pattern is easy to replicate for other types of applications.

In this article, we have learned:

The basic coily commands used to install and uninstall plugins

The structure of a plug-in, including defining the description shown on coily's help screen and the functions needed to process a command

That using template files and pattern substitution makes it easy for gen-cherrypy-app to generate CherryPy applications

Alerts & Offers

Series & Level

We understand your time is important. Uniquely amongst the major publishers, we seek to develop and publish the broadest range of learning and information products on each technology. Every Packt product delivers a specific learning pathway, broadly defined by the Series type. This structured approach enables you to select the pathway which best suits your knowledge level, learning style and task objectives.

Learning

As a new user, these step-by-step tutorial guides will give you all the practical skills necessary to become competent and efficient.

Beginner's Guide

Friendly, informal tutorials that provide a practical introduction using examples, activities, and challenges.

Essentials

Fast paced, concentrated introductions showing the quickest way to put the tool to work in the real world.

Cookbook

A collection of practical self-contained recipes that all users of the technology will find useful for building more powerful and reliable systems.

Blueprints

Guides you through the most common types of project you'll encounter, giving you end-to-end guidance on how to build your specific solution quickly and reliably.

Mastering

Take your skills to the next level with advanced tutorials that will give you confidence to master the tool's most powerful features.

Starting

Accessible to readers adopting the topic, these titles get you into the tool or technology so that you can become an effective user.

Progressing

Building on core skills you already have, these titles share solutions and expertise so you become a highly productive power user.