Merge ~jugmac00/lpci:create-documentation-for-plugin-system into lpci:main

Proposed by Jürgen Gmach
Status: Merged
Merged at revision: 6180c03364fe04faf28dd1f7ddbeb49ab793ed65
Proposed branch: ~jugmac00/lpci:create-documentation-for-plugin-system
Merge into: lpci:main
Diff against target: 190 lines (+81/-9)
8 files modified
docs/conf.py (+1/-1)
docs/configuration.rst (+3/-0)
docs/plugins.rst (+48/-3)
lpcraft/plugin/__init__.py (+7/-1)
lpcraft/plugin/hookspecs.py (+10/-1)
lpcraft/plugin/manager.py (+2/-2)
lpcraft/plugins/__init__.py (+1/-1)
lpcraft/plugins/plugins.py (+9/-0)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+413668@code.launchpad.net

Commit message

Create documentation for the plugin system

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) :
review: Approve
Revision history for this message
Jürgen Gmach (jugmac00) wrote :

Thanks - I moved the `__all__` declarations in between the from future and the regular imports.

Unfortunately, I have not found a flake8 plugin to enforce this behavior.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/docs/conf.py b/docs/conf.py
2index 7943bc6..4bb3580 100644
3--- a/docs/conf.py
4+++ b/docs/conf.py
5@@ -26,7 +26,7 @@ copyright = "2021, Canonical Ltd"
6 # Add any Sphinx extension module names here, as strings. They can be
7 # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
8 # ones.
9-extensions = []
10+extensions = ["sphinx.ext.autodoc"]
11
12 # Add any paths that contain templates here, relative to this directory.
13 templates_path = ["_templates"]
14diff --git a/docs/configuration.rst b/docs/configuration.rst
15index eb8e5c3..a350f7e 100644
16--- a/docs/configuration.rst
17+++ b/docs/configuration.rst
18@@ -57,6 +57,9 @@ Job definitions
19 A mapping of environment variable names to values, to be set while
20 running the job.
21
22+``plugin`` (optional)
23+ A plugin which will be used for this job. See :doc:`../plugins`
24+
25 ``run`` (optional)
26 A string (possibly multi-line) containing shell commands to run for this
27 job.
28diff --git a/docs/plugins.rst b/docs/plugins.rst
29index ca26449..f150687 100644
30--- a/docs/plugins.rst
31+++ b/docs/plugins.rst
32@@ -19,9 +19,54 @@ Plugin discovery
33 ----------------
34
35 As currently only builtin plugins are supported,
36-you need to define a plugin in ``lpcraft/plugins/<plugin>``.
37+you need to define a plugin in ``lpcraft/plugins/<plugin>``
38+and import the module in ``lpcraft/plugins/__init__.py``.
39
40+Plugin implementation
41+---------------------
42
43-.. comments
44+Please consult the `pluggy <https://pluggy.readthedocs.io/>`_ documentation,
45+and have a look at the ``lpcraft/plugins`` directory for inspiration.
46
47- XXX jugmac00 2021-12-17: render all available hooks via plugin
48+Name of the hook
49+****************
50+
51+.. automodule:: lpcraft.plugin
52+ :members:
53+ :exclude-members: hookimpl
54+
55+Implementation marker
56+*********************
57+
58+.. autodata:: lpcraft.plugin.hookimpl
59+ :no-value:
60+
61+Available hooks
62+***************
63+
64+.. automodule:: lpcraft.plugin.hookspecs
65+ :members:
66+
67+
68+Builtin plugins
69+---------------
70+
71+.. automodule:: lpcraft.plugins.plugins
72+ :members:
73+
74+Using a builtin plugin
75+----------------------
76+
77+In order to use a plugin,
78+it has to be specified via the ``plugin`` key in the job definition.
79+
80+.. code-block:: yaml
81+
82+ pipeline:
83+ - test
84+
85+ jobs:
86+ test:
87+ series: focal
88+ architectures: amd64
89+ plugin: tox
90diff --git a/lpcraft/plugin/__init__.py b/lpcraft/plugin/__init__.py
91index d514ac6..1a01a6c 100644
92--- a/lpcraft/plugin/__init__.py
93+++ b/lpcraft/plugin/__init__.py
94@@ -1,6 +1,12 @@
95 # Copyright 2021 Canonical Ltd. This software is licensed under the
96 # GNU General Public License version 3 (see the file LICENSE).
97
98+__all__ = ["NAME", "hookimpl"]
99+
100 import pluggy
101
102-hookimpl = pluggy.HookimplMarker("lpcraft")
103+NAME = "lpcraft" #: name of the hook
104+
105+hookimpl = pluggy.HookimplMarker(
106+ NAME
107+) #: decorator to mark lpcraft plugin hooks
108diff --git a/lpcraft/plugin/hookspecs.py b/lpcraft/plugin/hookspecs.py
109index e1232f4..cef7971 100644
110--- a/lpcraft/plugin/hookspecs.py
111+++ b/lpcraft/plugin/hookspecs.py
112@@ -3,9 +3,18 @@
113
114 from __future__ import annotations
115
116+__all__ = [
117+ "lpcraft_install_packages",
118+ "lpcraft_install_snaps",
119+ "lpcraft_execute_run",
120+ "lpcraft_set_environment",
121+]
122+
123 import pluggy
124
125-hookspec = pluggy.HookspecMarker("lpcraft")
126+from lpcraft.plugin import NAME
127+
128+hookspec = pluggy.HookspecMarker(NAME)
129
130
131 @hookspec # type: ignore
132diff --git a/lpcraft/plugin/manager.py b/lpcraft/plugin/manager.py
133index f2cf7b9..d78f306 100644
134--- a/lpcraft/plugin/manager.py
135+++ b/lpcraft/plugin/manager.py
136@@ -2,13 +2,13 @@ import pluggy
137
138 from lpcraft.config import Job
139 from lpcraft.errors import ConfigurationError
140-from lpcraft.plugin import hookspecs
141+from lpcraft.plugin import NAME, hookspecs
142 from lpcraft.plugin.lib import InternalPlugins
143 from lpcraft.plugins import PLUGINS
144
145
146 def get_plugin_manager(job: Job) -> pluggy.PluginManager:
147- pm = pluggy.PluginManager("lpcraft")
148+ pm = pluggy.PluginManager(NAME)
149 pm.add_hookspecs(hookspecs)
150
151 # register internal plugins
152diff --git a/lpcraft/plugins/__init__.py b/lpcraft/plugins/__init__.py
153index 0c44aa5..205d284 100644
154--- a/lpcraft/plugins/__init__.py
155+++ b/lpcraft/plugins/__init__.py
156@@ -1,6 +1,6 @@
157 from typing import Any, Callable, Type, TypeVar
158
159-PLUGINS = dict()
160+PLUGINS = dict() #: Collection of builtin plugins
161
162
163 TypeT = TypeVar("TypeT", bound=Type[Any])
164diff --git a/lpcraft/plugins/plugins.py b/lpcraft/plugins/plugins.py
165index 9aa7a4f..032cf8e 100644
166--- a/lpcraft/plugins/plugins.py
167+++ b/lpcraft/plugins/plugins.py
168@@ -3,6 +3,8 @@
169
170 from __future__ import annotations
171
172+__all__ = ["ToxPlugin"]
173+
174 from lpcraft.config import Job
175 from lpcraft.plugin import hookimpl
176 from lpcraft.plugins import register
177@@ -10,6 +12,13 @@ from lpcraft.plugins import register
178
179 @register(name="tox")
180 class ToxPlugin:
181+ """Installs `tox` and executes the configured environments.
182+
183+ Usage:
184+ In `.launchpad.yaml` create a key/value pair with `plugin` and `tox`
185+ within the job definition.
186+ """
187+
188 # XXX jugmac00 2021-12-16: this plugin is not yet fully implemented
189 def __init__(self, config: Job) -> None:
190 self.config = config

Subscribers

People subscribed via source and target branches