Welcome | Get started | Dive | Contribute | Topics | Reference | Changes | More

When Lino starts up

site startup

The things that happen at the beginning of a Lino process.

Life cycle of a Lino process

Here is what happens when a Lino process wakes up.

Lino process

A Python process on a given Lino site. This is either some django-admin command, or a WSGI or ASGI process inside a web server.

Step by step:

There are four major phases in the life of a Lino process:

application definition

The first phase of the site startup when Django settings are being loaded. We see this as a separate phase because Lino does some magics there.

data definition

The second phase of the site startup when Django models are being loaded.

site analysis

The third phase of the site startup when Django models have been loaded, and Lino analyzes them to fill its own data structures.

runtime

When the site startup has finished and the actual process does what it is designed to do.

There are three modules in lino.api named after these phases:

The Site startup phase

The application definition phase:

The Site class gets instantiated within the settings.py file. This instantiation does the following:

  • Modify Django’s django.utils.log.DEFAULT_LOGGING dict.

  • Call Site.get_plugin_configs()

  • Read the lino.ini if it exists.

  • Call Site.get_plugin_modifiers() and Site.get_installed_plugins() to build the list of plugins.

  • Import each plugin (just the __init__.py of the package).

  • Set the INSTALLED_APPS setting and the Site.installed_plugins site attribute. The list of installed plugins is now known and won’t change any more. INSTALLED_APPS is basically the same as Site.installed_plugins, except that the former is a list of module names while the latter is a list of Plugin instances.

  • Call each plugin’s on_plugins_loaded method.

Note that all the above-mentioned steps happen while the settings.py is still being loaded. This means for example that you cannot access the settings module in your get_plugin_configs or on_plugins_loaded methods.

When Django has finished loading the settings.py file, it starts importing the models.py module of each plugin. We call this the data definition phase.

When Django has fully populated its models registry (imported all models.py modules), it finds lino.AppConfig and runs its ready() method, which does nothing more and nothing less than run Site.startup().

The data definition phase is done, we enter the site analysis phase. Which does the following: