summaryrefslogtreecommitdiff
path: root/src/buildstream/_pluginfactory/__init__.py
blob: cd417239257e8dca136abc4a62bb4dffb4babd4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#
#  Copyright (C) 2020 Codethink Limited
#
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU Lesser General Public
#  License as published by the Free Software Foundation; either
#  version 2 of the License, or (at your option) any later version.
#
#  This library is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
#  Lesser General Public License for more details.
#
#  You should have received a copy of the GNU Lesser General Public
#  License along with this library. If not, see <http://www.gnu.org/licenses/>.
#

from .pluginorigin import PluginOrigin, PluginOriginType, PluginType
from .pluginoriginlocal import PluginOriginLocal
from .pluginoriginpip import PluginOriginPip
from .pluginoriginjunction import PluginOriginJunction
from .sourcefactory import SourceFactory
from .elementfactory import ElementFactory


# load_plugin_origin()
#
# Load a PluginOrigin from the YAML in project.conf
#
# Args:
#    project (Project): The project from whence this origin is loaded
#    origin_node (MappingNode): The node defining this origin
#
# Returns:
#    (PluginOrigin): The newly created PluginOrigin
#
def load_plugin_origin(project, origin_node):

    origin_type = origin_node.get_enum("origin", PluginOriginType)

    if origin_type == PluginOriginType.LOCAL:
        origin = PluginOriginLocal()
    elif origin_type == PluginOriginType.PIP:
        origin = PluginOriginPip()
    elif origin_type == PluginOriginType.JUNCTION:
        origin = PluginOriginJunction()

    origin.initialize(project, origin_node)

    return origin