Skip to content

Commit

Permalink
[qa/ci/misc] Maintenance
Browse files Browse the repository at this point in the history
- Reformatted code & docs
- Updated CI settings
- Updated setup.py
  • Loading branch information
nemesifier committed Aug 1, 2024
1 parent 562f46c commit 02148f9
Show file tree
Hide file tree
Showing 23 changed files with 2,327 additions and 2,113 deletions.
6 changes: 0 additions & 6 deletions .coveragerc

This file was deleted.

11 changes: 5 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,21 @@ on:
push:
branches:
- master
- gsoc23
pull_request:
branches:
- master
- gsoc23

jobs:
build:
name: Python==${{ matrix.python-version }}
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04

strategy:
fail-fast: false
matrix:
python-version:
- 3.8
- 3.9
- "3.8"
- "3.9"
- "3.10"

steps:
Expand All @@ -47,7 +45,8 @@ jobs:
- name: Tests
if: ${{ !cancelled() && steps.deps.conclusion == 'success' }}
run: |
coverage run -a --source=netjsonconfig runtests.py
coverage run runtests.py
coverage combine
coverage xml
- name: Upload Coverage
Expand Down
537 changes: 324 additions & 213 deletions CHANGES.rst

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion CONTRIBUTING.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Contributing
============

Please read our `Contributing guidelines <http://netjsonconfig.openwisp.org/en/latest/general/contributing.html>`_
Please read our `Contributing guidelines
<http://netjsonconfig.openwisp.org/en/latest/general/contributing.html>`_
on the documentation.
80 changes: 43 additions & 37 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,66 @@ netjsonconfig
=============

.. image:: https://github.com/openwisp/netjsonconfig/workflows/Netjsonconfig%20CI%20Build/badge.svg?branch=master
:target: https://github.com/openwisp/netjsonconfig/actions?query=workflow%3A%22Netjsonconfig+CI+Build%22
:target: https://github.com/openwisp/netjsonconfig/actions?query=workflow%3A%22Netjsonconfig+CI+Build%22

.. image:: https://coveralls.io/repos/openwisp/netjsonconfig/badge.svg
:target: https://coveralls.io/r/openwisp/netjsonconfig
:target: https://coveralls.io/r/openwisp/netjsonconfig

.. image:: https://img.shields.io/librariesio/release/github/openwisp/netjsonconfig
:target: https://libraries.io/github/openwisp/netjsonconfig#repository_dependencies
:alt: Dependency monitoring
:target: https://libraries.io/github/openwisp/netjsonconfig#repository_dependencies
:alt: Dependency monitoring

.. image:: https://img.shields.io/gitter/room/nwjs/nw.js.svg?style=flat-square
:target: https://gitter.im/openwisp/general
:target: https://gitter.im/openwisp/general

.. image:: https://badge.fury.io/py/netjsonconfig.svg
:target: http://badge.fury.io/py/netjsonconfig
:target: http://badge.fury.io/py/netjsonconfig

.. image:: https://pepy.tech/badge/netjsonconfig
:target: https://pepy.tech/project/netjsonconfig
:alt: downloads
:target: https://pepy.tech/project/netjsonconfig
:alt: downloads

.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
:target: https://pypi.org/project/black/
:alt: code style: black
:target: https://pypi.org/project/black/
:alt: code style: black

------------
----

Netjsonconfig is a part of the `OpenWISP project <http://openwisp.org>`_ and it's the official
configuration engine of `OpenWISP 2 <https://github.com/openwisp/ansible-openwisp2>`_.
Netjsonconfig is a part of the `OpenWISP project <http://openwisp.org>`_
and it's the official configuration engine of `OpenWISP 2
<https://github.com/openwisp/ansible-openwisp2>`_.

.. image:: http://netjsonconfig.openwisp.org/en/latest/_images/openwisp.org.svg
:target: http://openwisp.org
:target: http://openwisp.org

**netjsonconfig** is a python library that converts `NetJSON <http://netjson.org>`_
*DeviceConfiguration* objects into real router configurations that can be installed
on systems like `OpenWRT <http://openwrt.org>`_,
or `OpenWisp Firmware <https://github.com/openwisp/OpenWISP-Firmware>`_.
**netjsonconfig** is a python library that converts `NetJSON
<http://netjson.org>`_ *DeviceConfiguration* objects into real router
configurations that can be installed on systems like `OpenWRT
<http://openwrt.org>`_, or `OpenWisp Firmware
<https://github.com/openwisp/OpenWISP-Firmware>`_.

Its main features are listed below for your reference:

* `OpenWRT <http://openwrt.org>`_ / `LEDE <https://www.lede-project.org/>`_ support
* `OpenWisp Firmware <https://github.com/openwisp/OpenWISP-Firmware>`_ support
* `OpenVPN <https://openvpn.net>`_ support
* `WireGuard <https://www.wireguard.com/>`_ support
* `ZeroTier <https://www.zerotier.com/>`_ support
* Possibility to support more firmwares via custom backends
* Based on the `NetJSON RFC <http://netjson.org/rfc.html>`_
* **Validation** based on `JSON-Schema <http://json-schema.org/>`_
* **Templates**: store common configurations in templates
* **Multiple template inheritance**: reduce repetition to the minimum
* **File inclusion**: easy inclusion of arbitrary files in configuration packages
* **Variables**: reference variables in the configuration
* **Command line utility**: easy to use from shell scripts or from other programming languages

`Documentation <http://netjsonconfig.openwisp.org/>`_ |
`Change log <https://github.com/openwisp/netjsonconfig/blob/master/CHANGES.rst>`_ |
`Support channels <http://openwisp.org/support.html>`_ |
`Issue Tracker <https://github.com/openwisp/netjsonconfig/issues>`_ |
`License <https://github.com/openwisp/netjsonconfig/blob/master/LICENSE>`_
- `OpenWRT <http://openwrt.org>`_ / `LEDE
<https://www.lede-project.org/>`_ support
- `OpenWisp Firmware <https://github.com/openwisp/OpenWISP-Firmware>`_
support
- `OpenVPN <https://openvpn.net>`_ support
- `WireGuard <https://www.wireguard.com/>`_ support
- `ZeroTier <https://www.zerotier.com/>`_ support
- Possibility to support more firmwares via custom backends
- Based on the `NetJSON RFC <http://netjson.org/rfc.html>`_
- **Validation** based on `JSON-Schema <http://json-schema.org/>`_
- **Templates**: store common configurations in templates
- **Multiple template inheritance**: reduce repetition to the minimum
- **File inclusion**: easy inclusion of arbitrary files in configuration
packages
- **Variables**: reference variables in the configuration
- **Command line utility**: easy to use from shell scripts or from other
programming languages

`Documentation <http://netjsonconfig.openwisp.org/>`_ | `Change log
<https://github.com/openwisp/netjsonconfig/blob/master/CHANGES.rst>`_ |
`Support channels <http://openwisp.org/support.html>`_ | `Issue Tracker
<https://github.com/openwisp/netjsonconfig/issues>`_ | `License
<https://github.com/openwisp/netjsonconfig/blob/master/LICENSE>`_
133 changes: 69 additions & 64 deletions docs/source/backends/create_your_backend.rst
Original file line number Diff line number Diff line change
@@ -1,97 +1,101 @@
===================
Create your backend
===================

Every backend is based on the common ground of some elements provided by the
netjsonconfig library. The ``BaseBackend``, ``BaseConverter``, ``BaseParser`` and
``BaseRenderer`` are a battle proven set of tools that can be extended when
creating you backend.
Every backend is based on the common ground of some elements provided by
the netjsonconfig library. The ``BaseBackend``, ``BaseConverter``,
``BaseParser`` and ``BaseRenderer`` are a battle proven set of tools that
can be extended when creating you backend.

But the netjsonconfig package is not a playground to experiment, your contributions
to a new backend should start elsewhere, a different package, where you are in control
and can make errors and experiment more.
But the netjsonconfig package is not a playground to experiment, your
contributions to a new backend should start elsewhere, a different
package, where you are in control and can make errors and experiment more.

Netjsonconfig can now discover packages that provides a custom backend using
a feature available in the Python packaging ecosystem which is called `entry_points`.
Netjsonconfig can now discover packages that provides a custom backend
using a feature available in the Python packaging ecosystem which is
called `entry_points`.

To create a new backend start from scratch with a new folder and add this file to your
project root directory.
To create a new backend start from scratch with a new folder and add this
file to your project root directory.

.. code-block:: python
# example_backend/setup.py
from setuptools import setup, find_packages
setup(
name='example_backend',
version='0.0.0',
description='an example to illustrate a netjsonconfig backend as an external module',
install_requires=['netjsonconfig>=0.6.3'],
name="example_backend",
version="0.0.0",
description="an example to illustrate a netjsonconfig backend as an external module",
install_requires=["netjsonconfig>=0.6.3"],
packages=find_packages(),
entry_points={
'netjsonconfig.backends': [
'example=example_backend.__init__:ExampleBackend',
"netjsonconfig.backends": [
"example=example_backend.__init__:ExampleBackend",
]
}
},
)
this file can be used to create a package that can be installed using pip or other tools
in the python ecosystem. You can find more information about Python packaging
`at packaging.python.org <https://packaging.python.org/>`_
and `at the hitchhikers guide to packaging <https://the-hitchhikers-guide-to-packaging.readthedocs.io/en/latest/>`_.
this file can be used to create a package that can be installed using pip
or other tools in the python ecosystem. You can find more information
about Python packaging `at packaging.python.org
<https://packaging.python.org/>`_ and `at the hitchhikers guide to
packaging
<https://the-hitchhikers-guide-to-packaging.readthedocs.io/en/latest/>`_.

The most important part is to give your package a good name, a well thought description and
to add the ``entry_points`` keyword argument with the following code
The most important part is to give your package a good name, a well
thought description and to add the ``entry_points`` keyword argument with
the following code

.. code-block:: python
.. code-block:: python
{
# this is used by netjsonconfig
# to find your backend
'netjsonconfig.backends': [
...
]
}
{
# this is used by netjsonconfig
# to find your backend
"netjsonconfig.backends": [...]
}
Now your package will be in the list of backends that netjsonconfig can use!
Now your package will be in the list of backends that netjsonconfig can
use!

But we still have to give us a name to be unique! Netjsonconfig already
defined the names ``openwisp``, ``openwrt`` and ``openvpn`` but you can choose
whatever you like most.
defined the names ``openwisp``, ``openwrt`` and ``openvpn`` but you can
choose whatever you like most.

The name ``netjsonconfig.backends`` will be associated with a list of classes
from your package that will be presented to netjconfig at runtime. To specify
which classes you want to expose write the triple ``name``, ``path`` and ``class_name``
using the format ``name=path:class_name`` as in the example below.
The name ``netjsonconfig.backends`` will be associated with a list of
classes from your package that will be presented to netjconfig at runtime.
To specify which classes you want to expose write the triple ``name``,
``path`` and ``class_name`` using the format ``name=path:class_name`` as
in the example below.

The ``path`` part is simply the path to the file that contains the class
you want to expose and the ``class_name`` is the name of the class.

.. code-block:: python
.. code-block:: python
{
'netjsonconfig.backends': [
# name=path:class_name
'example=example_backend.__init__:ExampleBackend',
]
}
{
"netjsonconfig.backends": [
# name=path:class_name
"example=example_backend.__init__:ExampleBackend",
]
}
The previous example can be used with the following class definition

.. code-block:: python
# example_backend/example_backend/__init__.py
from netjsonconfig.backends.base.backend import BaseBackend
from netjsonconfig.backends.base.renderer import BaseRenderer
from netjsonconfig.backends.base.parser import BaseParser
# example_backend/example_backend/__init__.py
from netjsonconfig.backends.base.backend import BaseBackend
from netjsonconfig.backends.base.renderer import BaseRenderer
from netjsonconfig.backends.base.parser import BaseParser
from netjsonconfig.schema import schema as default_schema
from netjsonconfig.schema import schema as default_schema
class ExampleBackend(BaseBackend):
schema = default_schema
converter = []
parser = BaseParser
renderer = BaseRenderer
class ExampleBackend(BaseBackend):
schema = default_schema
converter = []
parser = BaseParser
renderer = BaseRenderer
Once you have your python package configured with the correct entry points
you should have a directory tree that looks like this.
Expand All @@ -104,11 +108,11 @@ you should have a directory tree that looks like this.
│   └── __init__.py
└── setup.py
And now you can install your package using ``pip install -e ./example_backend``
or ``python setup.py install``.
And now you can install your package using ``pip install -e
./example_backend`` or ``python setup.py install``.

As ``netjsonconfig`` is a dependency for ``example_backend`` you can use your backend
directly from the command line, e.g.
As ``netjsonconfig`` is a dependency for ``example_backend`` you can use
your backend directly from the command line, e.g.

.. code-block:: bash
Expand All @@ -121,12 +125,13 @@ directly from the command line, e.g.
[--args [ARGS [ARGS ...]]] [--verbose] [--version]
netjsonconfig: error: the following arguments are required: --backend/-b, --method/-m
Notice the *example* in ``{openwrt,openwisp,openvpn,example}``? That's your backend!
Notice the *example* in ``{openwrt,openwisp,openvpn,example}``? That's
your backend!
The name exposed is the one chosen in the *name*, *path*, *class* triple
from before
.. code-block:: python
# name=path:class
'example=example_backend.__init__:ExampleBackend',
# name=path:class
"example=example_backend.__init__:ExampleBackend",
Loading

0 comments on commit 02148f9

Please sign in to comment.