14.2.1. Components and environment
NGW uses components for modularity. One python-пакет can contain
one or several components. Each component inherits class Component
,
to load packages setuptools entry points are used.
def pkginfo():
return dict(components=dict(
somecomp='somepackage.somecomp'))
setup(
name = 'somepackage',
entry_points = {'nextgisweb.packages':
'somepackage = somepackage:somemod:pkginfo'}
)
Each component has an ID (somecomp
in an example above). The same ID
is used in a class attribute identity
.
This ID must be unique among all packages of NGW.
To join components together instance of Env
class is used,
created at init. Initialization runs like this:
Component instances are created
initialize()
is called for each componentconfigure()
is called for each component
14.2.1.1. Dependencies between components
Method calls for initialize()
and
configure()
happen in accordance
with dependencies, which can be set using decorator require()
.
So, is you need to call initialize()
of component B
after
A
do this:
from nextgisweb.component import Component, require
class A(Component):
identity = 'A'
def initialize(self):
pass
class B(Component):
identity = 'B'
@require('A')
def initialize(self):
pass