TLJH Plugins — The Littlest JupyterHub V0.1 Documentation

Writing a simple plugins#

We shall try to write a simple plugin that installs a few libraries, and use it to explain how the plugin mechanism works. We shall call this plugin tljh-simple.

Plugin directory layout#

We recommend creating a new git repo for your plugin. Plugins are normal python packages - however, since they are usually simpler, we recommend they live in one file.

For tljh-simple, the repository’s structure should look like:

tljh_simple: - tljh_simple.py - setup.py - README.md - LICENSE

The README.md (or README.rst file) contains human readable information about what your plugin does for your users. LICENSE specifies the license used by your plugin - we recommend the 3-Clause BSD License, since that is what is used by TLJH itself.

setup.py - metadata & registration#

setup.py marks this as a python package, and contains metadata about the package itself. It should look something like:

fromsetuptoolsimport setup setup( name="tljh-simple", author="YuviPanda", version="0.1", license="3-clause BSD", url='https://github.com/yuvipanda/tljh-simple', entry_points={"tljh": ["simple = tljh_simple"]}, py_modules=["tljh_simple"], )

This is a mostly standard setup.py file. entry_points={"tljh": ["simple = tljh_simple]} ‘registers’ the module tljh_simple (in file tljh_simple.py) with TLJH as a plugin.

tljh_simple.py - implementation#

In tljh_simple.py, you provide implementations for whichever hooks you want to extend.

A hook implementation is a function that has the following characteristics:

  1. Has same name as the hook

  2. Accepts some or all of the parameters defined for the hook

  3. Is decorated with the hookimpl decorator function, imported from tljh.hooks.

The current list of available hooks and when they are called can be seen in tljh/hooks.py in the source repository. Example implementations of each hook can be referenced from integration-tests/plugins/simplest/tljh_simplest.py.

This example provides an implementation for the tljh_extra_user_conda_packages hook, which can return a list of conda packages that’ll be installed in users’ environment from conda-forge.

fromtljh.hooksimport hookimpl @hookimpl deftljh_extra_user_conda_packages(): return [ 'xarray', 'iris', 'dask', ]

Từ khóa » Tljh Github