Skip to content

Commit db6776a

Browse files
committed
fix quickstart guide
1 parent 52aca98 commit db6776a

2 files changed

Lines changed: 53 additions & 24 deletions

File tree

docs/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
Plux - Dynamic Code Loading Framework
77
=====================================
88

9-
Plux is the dynamic code loading framework used in `LocalStack <https://github.com/localstack/localstack>`_. It builds a higher-level plugin mechanism around `Python's entry point mechanism <https://packaging.python.org/specifications/entry-points/>`_.
9+
Plux is a plugin system for Python, and the dynamic code loading framework used in `LocalStack <https://github.com/localstack/localstack>`_. It builds a higher-level plugin mechanism around `Python's entry point mechanism <https://packaging.python.org/specifications/entry-points/>`_.
1010

11-
Plux provides tools to load plugins from entry points at run time, and to discover entry points from plugins at build time (so you don't have to declare entry points statically in your ``setup.cfg`` or ``pyproject.toml``).
11+
Plux provides tools to load plugins from Python entry points at run time, and to discover entry points from plugins at build time (so you don't have to declare entry points statically in your ``setup.cfg`` or ``pyproject.toml``).
1212

1313
.. image:: plux-architecture.png
1414
:alt: Plux Architecture

docs/user_guide/quickstart.rst

Lines changed: 51 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,13 @@ Core Concepts
1717

1818
Before diving into the code, let's understand the core concepts of plux:
1919

20-
* **Plugin**: An object that exposes ``should_load`` and ``load`` methods
21-
* **PluginSpec**: Describes a plugin with a namespace, name, and factory
22-
* **PluginManager**: Manages the runtime lifecycle of plugins
23-
* **PluginFinder**: Finds plugins at build time or runtime
20+
* **Plugin**: An object that has a namespace a name and exposes ``should_load`` and ``load`` methods
21+
* **PluginManager**: Manages the runtime lifecycle of plugins in a specific namespace
2422

2523
Simple Plugin Example
2624
---------------------
2725

28-
Let's create a simple plugin and load it using the PluginManager.
26+
Let's create a simple plugin and load it using a ``PluginManager`` instance.
2927

3028
1. Define a Plugin
3129
~~~~~~~~~~~~~~~~~~
@@ -37,11 +35,14 @@ First, create a plugin by subclassing the ``Plugin`` class:
3735
from plux import Plugin
3836
3937
class GreetingPlugin(Plugin):
40-
namespace = "my.plugins.greetings"
41-
name = "hello"
38+
namespace = "my.plugins.greetings" # <- groups plugins together
39+
name = "hello" # <- has to be unique within the namespace
4240
4341
def load(self):
44-
return "Hello, World!"
42+
print("loading the plugin ...")
43+
44+
def greet(self):
45+
return "Hello World!"
4546
4647
2. Load the Plugin
4748
~~~~~~~~~~~~~~~~~~
@@ -56,10 +57,13 @@ Now, let's use the ``PluginManager`` to load our plugin:
5657
manager = PluginManager("my.plugins.greetings")
5758
5859
# Load the plugin by name
59-
plugin = manager.load("hello")
60+
plugin: GreetingPlugin = manager.load("hello")
6061
6162
# The result is the return value of the plugin's load method
62-
print(plugin) # Output: Hello, World!
63+
print(plugin.greet()) # Output: Hello, World!
64+
65+
66+
What's special about this is that the ``GreetingPlugin`` and the ``PluginManager`` can live in two separate python distributions.
6367

6468
Function Plugin Example
6569
-----------------------
@@ -69,29 +73,54 @@ You can also create plugins from functions using the ``@plugin`` decorator:
6973
.. code-block:: python
7074
7175
from plux import plugin
72-
73-
@plugin(namespace="my.plugins.greetings")
74-
def say_goodbye():
75-
return "Goodbye, World!"
76-
76+
77+
@plugin(namespace="my.greeters")
78+
def say_hallo():
79+
print("hallo")
80+
81+
@plugin(namespace="my.greeters")
82+
def say_hello():
83+
print("hello")
84+
85+
86+
This defines two function plugins in the namespace ``my.greeters``, that can be loaded individually by their name, or in bulk.
87+
88+
.. code-block:: python
89+
7790
# Load the function plugin
78-
manager = PluginManager("my.plugins.greetings")
79-
goodbye_plugin = manager.load("say_goodbye")
80-
81-
# Call the function plugin
82-
print(goodbye_plugin()) # Output: Goodbye, World!
91+
manager = PluginManager("my.configurators")
92+
93+
doc = dict()
94+
95+
# load a single plugin
96+
greeter = manager.load("say_hello")
97+
greeter() # prints "hello"
98+
99+
# load all of them
100+
for greeter in manager.load_all():
101+
greeter()
102+
103+
83104
84105
Building and Discovering Plugins
85106
--------------------------------
86107

87-
For plux to discover your plugins at runtime, you need to build entry points. The simplest way is to use the plux CLI:
108+
For plux to discover your plugins at runtime, you need to build entry points.
109+
The simplest way is to use the plux CLI:
88110

89111
.. code-block:: bash
90112
91113
# Generate entry points for your project
92114
python -m plux entrypoints
93115
94116
This will scan your project for plugins and generate the necessary entry points.
117+
Then, when you run
118+
119+
.. code-block:: bash
120+
121+
python -m build
122+
123+
to build your distribution, it will contain the generated plugins.
95124

96125
Next Steps
97126
----------
@@ -100,4 +129,4 @@ This quickstart guide covered the basics of defining and loading plugins with pl
100129

101130
* :doc:`defining_loading_plugins` - Learn more about different ways to define plugins
102131
* :doc:`plugin_manager` - Explore the PluginManager API in depth
103-
* :doc:`build_integration` - Understand how to integrate plux with your build system
132+
* :doc:`build_integration` - Understand how to integrate plux with your build system

0 commit comments

Comments
 (0)