@@ -5,8 +5,8 @@ Create your backend
5
5
.. include :: ../_github.rst
6
6
7
7
Every backend is based on the common ground of some elements provided by the
8
- netjsonconfig library. The `BaseBackend `, `BaseConverter `, `BaseParser ` and
9
- `BaseRenderer ` are a battle proven set of tools that can be extended when
8
+ netjsonconfig library. The `` BaseBackend `` , `` BaseConverter `` , `` BaseParser ` ` and
9
+ `` BaseRenderer ` ` are a battle proven set of tools that can be extended when
10
10
creating you backend.
11
11
12
12
But the netjsonconfig package is not a playground to experiment, your contributions
@@ -21,13 +21,14 @@ project root directory.
21
21
22
22
.. code-block :: python
23
23
24
- # setup.py
24
+ # example_backend/ setup.py
25
25
from setuptools import setup, find_packages
26
26
27
27
setup(
28
28
name = ' example_backend' ,
29
29
version = ' 0.0.0' ,
30
30
description = ' an example to illustrate a netjsonconfig backend as an external module' ,
31
+ install_requires = [' netjsonconfig>=0.6.3' ],
31
32
packages = find_packages(),
32
33
entry_points = {
33
34
' netjsonconfig.backends' : [
@@ -42,7 +43,7 @@ in the python ecosystem. You can find more information about Python packaging
42
43
and `at the hitchhikers guide to packaging <https://the-hitchhikers-guide-to-packaging.readthedocs.io/en/latest/ >`_.
43
44
44
45
The most important part is to give your package a good name, a well thought description and
45
- to add the `entry_points ` keyword argument with the following code
46
+ to add the `` entry_points ` ` keyword argument with the following code
46
47
47
48
.. code-block :: python
48
49
@@ -57,16 +58,16 @@ to add the `entry_points` keyword argument with the following code
57
58
Now your package will be in the list of backends that netjsonconfig can use!
58
59
59
60
But we still have to give us a name to be unique! Netjsonconfig already
60
- defined the names `openwisp `, `openwrt ` and `openvpn ` but you can choose
61
+ defined the names `` openwisp `` , `` openwrt `` and `` openvpn ` ` but you can choose
61
62
whatever you like most.
62
63
63
- The name `netjsonconfig.backends ` will be associated with a list of classes
64
+ The name `` netjsonconfig.backends ` ` will be associated with a list of classes
64
65
from your package that will be presented to netjconfig at runtime. To specify
65
- which classes you want to expose write the triple `name `, `path ` and `class_name `
66
- using the format `name=path:class_name ` as in the example below.
66
+ which classes you want to expose write the triple `` name `` , `` path `` and `` class_name ` `
67
+ using the format `` name=path:class_name ` ` as in the example below.
67
68
68
- The `path ` part is simply the path to the file that contains the class
69
- you want to expose and the `class_name ` is the name of the class.
69
+ The `` path ` ` part is simply the path to the file that contains the class
70
+ you want to expose and the `` class_name ` ` is the name of the class.
70
71
71
72
.. code-block :: python
72
73
@@ -81,7 +82,7 @@ The previous example can be used with the following class definition
81
82
82
83
.. code-block :: python
83
84
84
- # example_backend/__init__.py
85
+ # example_backend/example_backend/ __init__.py
85
86
from netjsonconfig.backends.base.backend import BaseBackend
86
87
from netjsonconfig.backends.base.renderer import BaseRenderer
87
88
from netjsonconfig.backends.base.parser import BaseParser
@@ -93,3 +94,41 @@ The previous example can be used with the following class definition
93
94
converter = []
94
95
parser = BaseParser
95
96
renderer = BaseRenderer
97
+
98
+ Once you have your python package configured with the correct entry points
99
+ you should have a directory tree that looks like this.
100
+
101
+ .. code-block :: bash
102
+
103
+ $ tree example_backend
104
+ example_backend
105
+ ├── example_backend
106
+ │ └── __init__.py
107
+ └── setup.py
108
+
109
+ And now you can install your package using ``pip install -e ./example_backend ``
110
+ or ``python setup.py install ``.
111
+
112
+ As ``netjsonconfig `` is a dependency for ``example_backend `` you can use your backend
113
+ directly from the command line, e.g.
114
+
115
+ .. code-block :: bash
116
+
117
+ $ netjsonconfig
118
+ usage: netjsonconfig [-h] [--config CONFIG]
119
+ [--templates [TEMPLATES [TEMPLATES ...]]]
120
+ [--native NATIVE] --backend
121
+ {openwrt,openwisp,openvpn,example} --method
122
+ {render,generate,write,validate,json}
123
+ [--args [ARGS [ARGS ...]]] [--verbose] [--version]
124
+ netjsonconfig: error: the following arguments are required: --backend/-b, --method/-m
125
+
126
+ Notice the * example* in ` ` {openwrt,openwisp,openvpn,example}` ` ? That' s your backend!
127
+
128
+ The name exposed is the one chosen in the *name*, *path*, *class* triple
129
+ from before
130
+
131
+ .. code-block:: python
132
+
133
+ # name=path:class
134
+ ' example= example_backend.__init__:ExampleBackend' ,
0 commit comments