Merge lp:~mterry/snapcraft/local-plugins into lp:~snappy-dev/snapcraft/core

Proposed by Michael Terry on 2015-07-09
Status: Merged
Approved by: Ricardo Salveti on 2015-07-10
Approved revision: 78
Merged at revision: 75
Proposed branch: lp:~mterry/snapcraft/local-plugins
Merge into: lp:~snappy-dev/snapcraft/core
Prerequisite: lp:~mterry/snapcraft/lifecycle-fixes2
Diff against target: 161 lines (+73/-9)
7 files modified
.bzrignore (+6/-3)
snapcraft/plugin.py (+25/-5)
snapcraft/yaml.py (+8/-1)
tests/plainbox/data/local-plugin/parts/plugins/local-plugin.yaml (+1/-0)
tests/plainbox/data/local-plugin/parts/plugins/local_plugin.py (+22/-0)
tests/plainbox/data/local-plugin/snapcraft.yaml (+2/-0)
tests/plainbox/units/jobs.pxu (+9/-0)
To merge this branch: bzr merge lp:~mterry/snapcraft/local-plugins
Reviewer Review Type Date Requested Status
Ricardo Salveti (community) 2015-07-09 Approve on 2015-07-10
Review via email: mp+264305@code.launchpad.net

Commit Message

Add support for local plugins in parts/plugins.

Description of the Change

Add support for local plugins in parts/plugins.

We discussed being able to specify a separate local plugin path in the Isle of Man, but that isn't implemented yet.

To post a comment you must log in.
lp:~mterry/snapcraft/local-plugins updated on 2015-07-09
77. By Michael Terry on 2015-07-09

Drop errant ls

Ricardo Salveti (rsalveti) wrote :

Looks good, one minor question inline, feel free to merge it.

review: Approve
lp:~mterry/snapcraft/local-plugins updated on 2015-07-10
78. By Michael Terry on 2015-07-10

Add notice when using a local plugin

Michael Terry (mterry) wrote :

OK, I added an extra log notice.

Ricardo Salveti (rsalveti) wrote :

Looks good, thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.bzrignore'
2--- .bzrignore 2015-07-06 16:48:22 +0000
3+++ .bzrignore 2015-07-10 18:35:54 +0000
4@@ -1,6 +1,9 @@
5-**/parts/
6-**/snap/
7-**/stage/
8+examples/*/parts/
9+examples/*/snap/
10+examples/*/stage/
11+tests/unit/parts/
12+tests/unit/snap/
13+tests/unit/stage/
14 build
15 dist
16 *.egg-info
17
18=== modified file 'snapcraft/plugin.py'
19--- snapcraft/plugin.py 2015-07-08 20:45:52 +0000
20+++ snapcraft/plugin.py 2015-07-10 18:35:54 +0000
21@@ -31,6 +31,8 @@
22 self.config = None
23 self.partNames = []
24 self.deps = []
25+ self.pluginName = name
26+ self.isLocalPlugin = False
27
28 self.sourcedir = os.path.join(os.getcwd(), "parts", partName, "src")
29 self.builddir = os.path.join(os.getcwd(), "parts", partName, "build")
30@@ -40,10 +42,17 @@
31 self.statefile = os.path.join(os.getcwd(), "parts", partName, "state")
32
33 if loadConfig:
34- configPath = os.path.join(snapcraft.common.plugindir, name + ".yaml")
35- if not os.path.exists(configPath):
36- snapcraft.common.log("Missing config for part %s" % (name), file=sys.stderr)
37- return
38+ # First look in local path
39+ localPluginDir = os.path.abspath(os.path.join('parts', 'plugins'))
40+ configPath = os.path.join(localPluginDir, name + ".yaml")
41+ if os.path.exists(configPath):
42+ self.isLocalPlugin = True
43+ else:
44+ # OK, now look at snapcraft's plugins
45+ configPath = os.path.join(snapcraft.common.plugindir, name + ".yaml")
46+ if not os.path.exists(configPath):
47+ snapcraft.common.log("Unknown plugin %s" % name, file=sys.stderr)
48+ return
49 self.config = yaml.load(open(configPath, 'r')) or {}
50
51 if loadCode:
52@@ -64,7 +73,18 @@
53 options = optionsOverride
54
55 moduleName = self.config.get('module', name)
56- module = importlib.import_module("snapcraft.plugins." + moduleName)
57+
58+ # Load code from local plugin dir if it is there
59+ if self.isLocalPlugin:
60+ sys.path = [localPluginDir] + sys.path
61+ else:
62+ moduleName = 'snapcraft.plugins.' + moduleName
63+
64+ module = importlib.import_module(moduleName)
65+
66+ if self.isLocalPlugin:
67+ sys.path.pop(0)
68+
69 for propName in dir(module):
70 prop = getattr(module, propName)
71 if issubclass(prop, snapcraft.BasePlugin):
72
73=== modified file 'snapcraft/yaml.py'
74--- snapcraft/yaml.py 2015-07-08 20:45:52 +0000
75+++ snapcraft/yaml.py 2015-07-10 18:35:54 +0000
76@@ -35,7 +35,7 @@
77 self.systemPackages = self.data.get('systemPackages', [])
78
79 for partName in self.data.get("parts", []):
80- properties = self.data["parts"][partName]
81+ properties = self.data["parts"][partName] or {}
82
83 pluginName = properties.get("plugin", partName)
84 if "plugin" in properties:
85@@ -49,6 +49,13 @@
86
87 self.loadPlugin(partName, pluginName, properties)
88
89+ localPlugins = set()
90+ for part in self.allParts:
91+ if part.isLocalPlugin:
92+ localPlugins.add(part.pluginName)
93+ for localPlugin in localPlugins:
94+ snapcraft.common.log("Using local plugin %s" % localPlugin)
95+
96 # Grab all required dependencies, if not already specified
97 newParts = self.allParts.copy()
98 while newParts:
99
100=== added directory 'tests/plainbox/data/local-plugin'
101=== added directory 'tests/plainbox/data/local-plugin/parts'
102=== added directory 'tests/plainbox/data/local-plugin/parts/plugins'
103=== added file 'tests/plainbox/data/local-plugin/parts/plugins/local-plugin.yaml'
104--- tests/plainbox/data/local-plugin/parts/plugins/local-plugin.yaml 1970-01-01 00:00:00 +0000
105+++ tests/plainbox/data/local-plugin/parts/plugins/local-plugin.yaml 2015-07-10 18:35:54 +0000
106@@ -0,0 +1,1 @@
107+module: local_plugin
108
109=== added file 'tests/plainbox/data/local-plugin/parts/plugins/local_plugin.py'
110--- tests/plainbox/data/local-plugin/parts/plugins/local_plugin.py 1970-01-01 00:00:00 +0000
111+++ tests/plainbox/data/local-plugin/parts/plugins/local_plugin.py 2015-07-10 18:35:54 +0000
112@@ -0,0 +1,22 @@
113+# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
114+#
115+# Copyright (C) 2015 Canonical Ltd
116+#
117+# This program is free software: you can redistribute it and/or modify
118+# it under the terms of the GNU General Public License version 3 as
119+# published by the Free Software Foundation.
120+#
121+# This program is distributed in the hope that it will be useful,
122+# but WITHOUT ANY WARRANTY; without even the implied warranty of
123+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
124+# GNU General Public License for more details.
125+#
126+# You should have received a copy of the GNU General Public License
127+# along with this program. If not, see <http://www.gnu.org/licenses/>.
128+
129+import snapcraft
130+
131+
132+class LocalPlugin(snapcraft.BasePlugin):
133+ def build(self):
134+ return self.run('touch build-stamp', self.installdir)
135
136=== added file 'tests/plainbox/data/local-plugin/snapcraft.yaml'
137--- tests/plainbox/data/local-plugin/snapcraft.yaml 1970-01-01 00:00:00 +0000
138+++ tests/plainbox/data/local-plugin/snapcraft.yaml 2015-07-10 18:35:54 +0000
139@@ -0,0 +1,2 @@
140+parts:
141+ local-plugin:
142
143=== modified file 'tests/plainbox/units/jobs.pxu'
144--- tests/plainbox/units/jobs.pxu 2015-07-09 13:32:43 +0000
145+++ tests/plainbox/units/jobs.pxu 2015-07-10 18:35:54 +0000
146@@ -19,6 +19,15 @@
147 snapcraft stage
148 test -e stamp-install
149
150+id: snapcraft/normal/local-plugin
151+plugin: shell
152+estimated_duration: 0.3
153+command:
154+ set -ex
155+ cp -rT $PLAINBOX_PROVIDER_DATA/local-plugin .
156+ snapcraft snap
157+ test -e snap/build-stamp
158+
159 id: snapcraft/normal/simple-make
160 plugin: shell
161 estimated_duration: 0.3

Subscribers

People subscribed via source and target branches