summaryrefslogtreecommitdiff
path: root/src/buildstream/_pluginfactory/pluginoriginlocal.py
blob: 34fba09e6f6a8fbb101bfaf731b36d2f941cea07 (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
#
#  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/>.
#
import os

from .pluginorigin import PluginOrigin, PluginOriginType


# PluginOriginLocal
#
# PluginOrigin for local plugins
#
class PluginOriginLocal(PluginOrigin):
    def __init__(self):
        super().__init__(PluginOriginType.LOCAL)

        # Project relative path to where plugins from this origin are found
        self._path = None

    def get_plugin_paths(self, kind, plugin_type):
        path = os.path.join(self.project.directory, self._path)
        defaults = os.path.join(path, "{}.yaml".format(kind))
        if not os.path.exists(defaults):
            defaults = None

        return path, defaults, "project directory: {}".format(self._path)

    def load_config(self, origin_node):

        origin_node.validate_keys(["path", *PluginOrigin._COMMON_CONFIG_KEYS])

        path_node = origin_node.get_scalar("path")
        self._path = self.project.get_path_from_node(path_node, check_is_dir=True)