Merge lp:~sergiusens/snapcraft/meta-all-yaml into lp:~snappy-dev/snapcraft/core

Proposed by Sergio Schvezov on 2015-08-25
Status: Merged
Approved by: John Lenton on 2015-08-27
Approved revision: 143
Merged at revision: 140
Proposed branch: lp:~sergiusens/snapcraft/meta-all-yaml
Merge into: lp:~snappy-dev/snapcraft/core
Diff against target: 1292 lines (+659/-214)
51 files modified
examples/godd/meta/package.yaml (+0/-5)
examples/godd/meta/readme.md (+0/-1)
examples/godd/snapcraft.yaml (+8/-1)
examples/gopaste/meta/package.yaml (+0/-7)
examples/gopaste/meta/readme.md (+0/-1)
examples/gopaste/snapcraft.yaml (+10/-1)
examples/java-hello-world/meta/package.yaml (+0/-6)
examples/java-hello-world/meta/readme.md (+0/-1)
examples/java-hello-world/snapcraft.yaml (+9/-1)
examples/libpipeline/meta/package.yaml (+0/-5)
examples/libpipeline/meta/readme.md (+0/-1)
examples/libpipeline/snapcraft.yaml (+8/-1)
examples/py2-project/meta/package.yaml (+0/-5)
examples/py2-project/meta/readme.md (+0/-1)
examples/py2-project/snapcraft.yaml (+8/-1)
examples/py3-project/meta/package.yaml (+0/-5)
examples/py3-project/meta/readme.md (+0/-1)
examples/py3-project/snapcraft.yaml (+8/-1)
examples/qmldemo/snapcraft.yaml (+14/-2)
examples/tomcat-maven-webapp/meta/package.yaml (+0/-12)
examples/tomcat-maven-webapp/meta/readme.md (+0/-3)
examples/tomcat-maven-webapp/snapcraft.yaml (+14/-1)
examples/webcam-webui-snap/meta/package.yaml (+0/-7)
examples/webcam-webui-snap/meta/readme.md (+0/-3)
examples/webcam-webui-snap/snapcraft.yaml (+10/-1)
examples/wget-deb/meta/package.yaml (+0/-5)
examples/wget-deb/meta/readme.md (+0/-1)
examples/wget-deb/snapcraft.yaml (+8/-1)
integration-tests/data/assemble/package.yaml.after (+0/-13)
integration-tests/data/assemble/snapcraft.yaml (+15/-0)
integration-tests/data/bzr-head/snapcraft.yaml (+6/-0)
integration-tests/data/bzr-tag/snapcraft.yaml (+6/-0)
integration-tests/data/conflicts/snapcraft.yaml (+6/-0)
integration-tests/data/dependencies/snapcraft.yaml (+6/-0)
integration-tests/data/git-branch/snapcraft.yaml (+6/-0)
integration-tests/data/git-head/snapcraft.yaml (+6/-0)
integration-tests/data/git-tag/snapcraft.yaml (+6/-0)
integration-tests/data/hg-branch/snapcraft.yaml (+6/-0)
integration-tests/data/hg-head/snapcraft.yaml (+6/-0)
integration-tests/data/hg-tag/snapcraft.yaml (+6/-0)
integration-tests/data/local-plugin/snapcraft.yaml (+6/-0)
integration-tests/data/local-source/snapcraft.yaml (+6/-0)
integration-tests/data/simple-cmake/snapcraft.yaml (+6/-0)
integration-tests/data/simple-copy/snapcraft.yaml (+6/-0)
integration-tests/data/simple-make/snapcraft.yaml (+6/-0)
integration-tests/data/simple-tar/snapcraft.yaml (+6/-0)
integration-tests/units/jobs.pxu (+0/-13)
snapcraft/cmds.py (+13/-88)
snapcraft/meta.py (+180/-0)
snapcraft/tests/test_cmds.py (+0/-19)
snapcraft/tests/test_meta.py (+258/-0)
To merge this branch: bzr merge lp:~sergiusens/snapcraft/meta-all-yaml
Reviewer Review Type Date Requested Status
John Lenton Approve on 2015-08-27
Leo Arias (community) 2015-08-25 Approve on 2015-08-26
Review via email: mp+269100@code.launchpad.net

Commit message

Generate meta (package.yaml and readme.md) from snapcraft.yaml

Description of the change

This will break many of the current snapcraft implementations so before merging this it would be good to have daily builds disabled.

Additionally this raises the usefulness of assemble (maybe we can be smarter) and detect a manual 'meta' and warn about it.

Code coverage seems high, but I didn't cover one line of code from migrated code which I can do in another MP.

To post a comment you must log in.
138. By Sergio Schvezov on 2015-08-25

rogue deprecated assertEquals

139. By Sergio Schvezov on 2015-08-25

updating examples

140. By Sergio Schvezov on 2015-08-25

take into account the optional type and frameworks

Sergio Schvezov (sergiusens) wrote :

Forgot to add the examples (I had only touched the integration tests and had forgotten). I also added two rather important keys missing from the spec, type and frameworks

Leo Arias (elopio) wrote :

Cool stuff with tests :)
Some of the branches from the wrap methods are not tested. This is already big, so feel free to make a card or a bug for that.

Plenty of comments in the diff.

review: Needs Fixing
Sergio Schvezov (sergiusens) wrote :

> Cool stuff with tests :)

Thanks for the review
> Some of the branches from the wrap methods are not tested. This is already
> big, so feel free to make a card or a bug for that.

_wrap_tests is not new code, just moved, so I won't be adding tests in this MP for it and leave a TODO.

> Plenty of comments in the diff.

Thanks, I will take a look now

141. By Sergio Schvezov on 2015-08-26

First round of review fixes

Sergio Schvezov (sergiusens) wrote :

I addressed most of the review comments, please take another look.

Leo Arias (elopio) wrote :

Ok, I'm happy with this. I just proposed a branch with the patcher change and the tests passing:
https://code.launchpad.net/~elopio/snapcraft/patcher/+merge/269239

What's important is to use addCleanup instead of tearDown. From the docs: "if an exception is raised in the setUp then tearDown is not called."

Leaving my +1. Thanks Sergio!

review: Approve
142. By Sergio Schvezov on 2015-08-26

testing fixes from elopio

143. By Sergio Schvezov on 2015-08-27

Merging trunk

John Lenton (chipaca) wrote :

Can we have single-file config in snappy too?

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== removed directory 'examples/godd/meta'
2=== removed file 'examples/godd/meta/package.yaml'
3--- examples/godd/meta/package.yaml 2015-06-24 16:32:33 +0000
4+++ examples/godd/meta/package.yaml 1970-01-01 00:00:00 +0000
5@@ -1,5 +0,0 @@
6-name: godd
7-version: 1.0
8-vendor: Michael Vogt <mvo@ubuntu.com>
9-binaries:
10- - name: ./bin/godd
11
12=== removed file 'examples/godd/meta/readme.md'
13--- examples/godd/meta/readme.md 2015-06-24 16:32:33 +0000
14+++ examples/godd/meta/readme.md 1970-01-01 00:00:00 +0000
15@@ -1,1 +0,0 @@
16-Simple dd like tool
17
18=== modified file 'examples/godd/snapcraft.yaml'
19--- examples/godd/snapcraft.yaml 2015-07-31 15:12:07 +0000
20+++ examples/godd/snapcraft.yaml 2015-08-27 16:38:02 +0000
21@@ -1,5 +1,12 @@
22+name: godd
23+version: 1.0
24+vendor: Michael Vogt <mvo@ubuntu.com>
25+binaries:
26+ - name: ./bin/godd
27+summary: Simple dd like tool
28+description: written in go so it is self contained and really portable, you would need to use hw-assign to access devices.
29+
30 parts:
31 godd:
32 plugin: go-project
33 source: git://github.com/mvo5/godd
34-snappy-metadata: meta
35
36=== removed directory 'examples/gopaste/meta'
37=== removed file 'examples/gopaste/meta/package.yaml'
38--- examples/gopaste/meta/package.yaml 2015-06-25 13:22:56 +0000
39+++ examples/gopaste/meta/package.yaml 1970-01-01 00:00:00 +0000
40@@ -1,7 +0,0 @@
41-name: gopaste
42-version: 1.0
43-vendor: mterry@ubuntu.com
44-services:
45- - name: gopaste
46- description: "gopaste"
47- start: bin/gopaste
48
49=== removed file 'examples/gopaste/meta/readme.md'
50--- examples/gopaste/meta/readme.md 2015-06-25 13:22:56 +0000
51+++ examples/gopaste/meta/readme.md 1970-01-01 00:00:00 +0000
52@@ -1,1 +0,0 @@
53-Simple dd like tool
54
55=== modified file 'examples/gopaste/snapcraft.yaml'
56--- examples/gopaste/snapcraft.yaml 2015-07-31 15:12:07 +0000
57+++ examples/gopaste/snapcraft.yaml 2015-08-27 16:38:02 +0000
58@@ -1,5 +1,14 @@
59+name: gopaste
60+version: 1.0
61+vendor: Michael Terry <mterry@ubuntu.com>
62+services:
63+ - name: gopaste
64+ description: "gopaste"
65+ start: bin/gopaste
66+summary: Simple pasting tool
67+description: Runs a service that allows you to paste to and share.
68+
69 parts:
70 gopaste:
71 plugin: go-project
72 source: git://github.com/wisnij/gopaste/gopasted
73-snappy-metadata: meta
74
75=== removed directory 'examples/java-hello-world/meta'
76=== removed file 'examples/java-hello-world/meta/package.yaml'
77--- examples/java-hello-world/meta/package.yaml 2015-07-20 21:11:39 +0000
78+++ examples/java-hello-world/meta/package.yaml 1970-01-01 00:00:00 +0000
79@@ -1,6 +0,0 @@
80-name: java-hello-world
81-version: 0
82-vendor: mterry@ubuntu.com
83-binaries:
84- - name: hello
85- exec: bin/wrapper
86
87=== removed file 'examples/java-hello-world/meta/readme.md'
88--- examples/java-hello-world/meta/readme.md 2015-07-20 21:11:39 +0000
89+++ examples/java-hello-world/meta/readme.md 1970-01-01 00:00:00 +0000
90@@ -1,1 +0,0 @@
91-An example
92
93=== modified file 'examples/java-hello-world/snapcraft.yaml'
94--- examples/java-hello-world/snapcraft.yaml 2015-07-22 17:57:42 +0000
95+++ examples/java-hello-world/snapcraft.yaml 2015-08-27 16:38:02 +0000
96@@ -1,3 +1,12 @@
97+name: java-hello-world
98+version: 0
99+vendor: Michael Terry <mterry@ubuntu.com>
100+binaries:
101+ - name: hello
102+ exec: bin/wrapper
103+summary: A java exmaple
104+description: this is not much more than an example
105+
106 parts:
107 local:
108 plugin: ant-project
109@@ -5,4 +14,3 @@
110 wrapper:
111 plugin: make-project
112 source: .
113-snappy-metadata: meta
114
115=== removed directory 'examples/libpipeline/meta'
116=== removed file 'examples/libpipeline/meta/package.yaml'
117--- examples/libpipeline/meta/package.yaml 2015-06-24 17:00:33 +0000
118+++ examples/libpipeline/meta/package.yaml 1970-01-01 00:00:00 +0000
119@@ -1,5 +0,0 @@
120-name: pipelinetest
121-version: 1.0
122-vendor: Mike Terry
123-binaries:
124- - name: ./bin/pipelinetest
125
126=== removed file 'examples/libpipeline/meta/readme.md'
127--- examples/libpipeline/meta/readme.md 2015-06-24 17:00:33 +0000
128+++ examples/libpipeline/meta/readme.md 1970-01-01 00:00:00 +0000
129@@ -1,1 +0,0 @@
130-Libpipeline example
131
132=== modified file 'examples/libpipeline/snapcraft.yaml'
133--- examples/libpipeline/snapcraft.yaml 2015-07-15 16:26:06 +0000
134+++ examples/libpipeline/snapcraft.yaml 2015-08-27 16:38:02 +0000
135@@ -1,3 +1,11 @@
136+name: pipelinetest
137+version: 1.0
138+vendor: Mike Terry <mterry@ubuntu.com>
139+binaries:
140+ - name: ./bin/pipelinetest
141+summary: Libpipeline example
142+description: this is an example package of an autotools project built with snapcraft using
143+
144 parts:
145 pipelinetest:
146 plugin: make-project
147@@ -7,4 +15,3 @@
148 libpipeline:
149 plugin: autotools-project
150 source: lp:~mterry/libpipeline/printf
151-snappy-metadata: meta
152
153=== removed directory 'examples/py2-project/meta'
154=== removed file 'examples/py2-project/meta/package.yaml'
155--- examples/py2-project/meta/package.yaml 2015-07-17 14:44:45 +0000
156+++ examples/py2-project/meta/package.yaml 1970-01-01 00:00:00 +0000
157@@ -1,5 +0,0 @@
158-name: spongeshaker
159-version: 0
160-vendor: michael.vogt@ubuntu.com
161-binaries:
162- - name: ./bin/sha3sum
163
164=== removed file 'examples/py2-project/meta/readme.md'
165--- examples/py2-project/meta/readme.md 2015-07-17 14:44:45 +0000
166+++ examples/py2-project/meta/readme.md 1970-01-01 00:00:00 +0000
167@@ -1,1 +0,0 @@
168-A python sha3 implementation
169
170=== modified file 'examples/py2-project/snapcraft.yaml'
171--- examples/py2-project/snapcraft.yaml 2015-08-04 21:54:52 +0000
172+++ examples/py2-project/snapcraft.yaml 2015-08-27 16:38:02 +0000
173@@ -1,7 +1,14 @@
174+name: spongeshaker
175+version: 0
176+vendor: Michael Vogt <michael.vogt@ubuntu.com>
177+binaries:
178+ - name: ./bin/sha3sum
179+summary: A python sha3 implementation
180+description: A python2 project using snapcraft
181+
182 parts:
183 spongeshaker:
184 plugin: python2-project
185 source: git://github.com/markokr/spongeshaker.git
186 make-project:
187 source: .
188-snappy-metadata: meta
189
190=== removed directory 'examples/py3-project/meta'
191=== removed file 'examples/py3-project/meta/package.yaml'
192--- examples/py3-project/meta/package.yaml 2015-07-15 10:32:45 +0000
193+++ examples/py3-project/meta/package.yaml 1970-01-01 00:00:00 +0000
194@@ -1,5 +0,0 @@
195-name: spongeshaker
196-version: 0
197-vendor: michael.vogt@ubuntu.com
198-binaries:
199- - name: bin/sha3sum
200
201=== removed file 'examples/py3-project/meta/readme.md'
202--- examples/py3-project/meta/readme.md 2015-07-13 08:28:40 +0000
203+++ examples/py3-project/meta/readme.md 1970-01-01 00:00:00 +0000
204@@ -1,1 +0,0 @@
205-A python sha3 implementation
206
207=== modified file 'examples/py3-project/snapcraft.yaml'
208--- examples/py3-project/snapcraft.yaml 2015-07-22 21:16:59 +0000
209+++ examples/py3-project/snapcraft.yaml 2015-08-27 16:38:02 +0000
210@@ -1,3 +1,11 @@
211+name: spongeshaker
212+version: 0
213+vendor: Michael Vogt <michael.vogt@ubuntu.com>
214+binaries:
215+ - name: bin/sha3sum
216+summary: A python sha3 implementation
217+description: A python2 project using snapcraft
218+
219 parts:
220 spongeshaker:
221 plugin: python3-project
222@@ -6,4 +14,3 @@
223 plugin: copy
224 files:
225 sha3sum.py: bin/sha3sum
226-snappy-metadata: meta
227
228=== modified file 'examples/qmldemo/snapcraft.yaml'
229--- examples/qmldemo/snapcraft.yaml 2015-07-22 14:35:51 +0000
230+++ examples/qmldemo/snapcraft.yaml 2015-08-27 16:38:02 +0000
231@@ -1,8 +1,20 @@
232+name: qmldemo
233+version: 1
234+vendor: Ted Gould <ted@canonical.com>
235+frameworks:
236+ - mir
237+binaries:
238+ - name: qmldemo
239+ exec: qmlscene demo.qml --
240+ caps:
241+ - mir_client
242+ - network-client
243+summary: qml demo
244+description: An example of shipping a usable QML file in a snap using the QML plugin.
245+
246 parts:
247 qml:
248 plugin: qml
249 qmldemo:
250 plugin: copy
251 files:
252- demo.qml: demo.qml
253-snappy-metadata: meta
254
255=== removed directory 'examples/tomcat-maven-webapp/meta'
256=== removed file 'examples/tomcat-maven-webapp/meta/package.yaml'
257--- examples/tomcat-maven-webapp/meta/package.yaml 2015-08-19 17:42:25 +0000
258+++ examples/tomcat-maven-webapp/meta/package.yaml 1970-01-01 00:00:00 +0000
259@@ -1,12 +0,0 @@
260-name: tomcat-webapp-demo
261-vendor: Loïc Minier <loic.minier@ubuntu.com>
262-version: 1.0
263-architectures:
264- - amd64
265-services:
266- - name: tomcat
267- start: bin/wrapper
268- caps:
269- - networking
270- - network-service
271-
272
273=== removed file 'examples/tomcat-maven-webapp/meta/readme.md'
274--- examples/tomcat-maven-webapp/meta/readme.md 2015-07-24 01:59:59 +0000
275+++ examples/tomcat-maven-webapp/meta/readme.md 1970-01-01 00:00:00 +0000
276@@ -1,3 +0,0 @@
277-Demo of Tomcat-hosted Webapp
278-
279-This is a demo snap of a Tomcat-hosted webapp produced by snapcraft with maven.
280
281=== modified file 'examples/tomcat-maven-webapp/snapcraft.yaml'
282--- examples/tomcat-maven-webapp/snapcraft.yaml 2015-07-24 03:32:54 +0000
283+++ examples/tomcat-maven-webapp/snapcraft.yaml 2015-08-27 16:38:02 +0000
284@@ -1,3 +1,17 @@
285+name: tomcat-webapp-demo
286+vendor: Loïc Minier <loic.minier@ubuntu.com>
287+version: 1.0
288+architectures:
289+ - amd64
290+services:
291+ - name: tomcat
292+ start: bin/wrapper
293+ caps:
294+ - networking
295+ - network-service
296+summary: Demo of Tomcat-hosted Webapp
297+description: This is a demo snap of a Tomcat-hosted webapp produced by snapcraft with maven.
298+
299 parts:
300 webapp:
301 plugin: maven-project
302@@ -8,4 +22,3 @@
303 local-files:
304 plugin: make-project
305 source: .
306-snappy-metadata: meta
307
308=== removed directory 'examples/webcam-webui-snap/meta'
309=== removed file 'examples/webcam-webui-snap/meta/package.yaml'
310--- examples/webcam-webui-snap/meta/package.yaml 2015-06-25 13:22:56 +0000
311+++ examples/webcam-webui-snap/meta/package.yaml 1970-01-01 00:00:00 +0000
312@@ -1,7 +0,0 @@
313-name: webcam-webui
314-version: 1.0.0
315-vendor: Loïc Minier <loic.minier@ubuntu.com>
316-services:
317- - name: webcam-webui
318- start: bin/webcam-webui
319- security-template: unconfined
320
321=== removed file 'examples/webcam-webui-snap/meta/readme.md'
322--- examples/webcam-webui-snap/meta/readme.md 2015-06-25 13:22:56 +0000
323+++ examples/webcam-webui-snap/meta/readme.md 1970-01-01 00:00:00 +0000
324@@ -1,3 +0,0 @@
325-Webcam web UI
326-
327-Exposes your webcam over a web UI
328
329=== modified file 'examples/webcam-webui-snap/snapcraft.yaml'
330--- examples/webcam-webui-snap/snapcraft.yaml 2015-08-06 14:59:07 +0000
331+++ examples/webcam-webui-snap/snapcraft.yaml 2015-08-27 16:38:02 +0000
332@@ -1,3 +1,13 @@
333+name: webcam-webui
334+version: 1.0.0
335+vendor: Loïc Minier <loic.minier@ubuntu.com>
336+services:
337+ - name: webcam-webui
338+ start: bin/webcam-webui
339+ security-template: unconfined
340+summary: Webcam web UI
341+description: Exposes your webcam over a web UI
342+
343 parts:
344 golang-static-http:
345 plugin: go-project
346@@ -8,4 +18,3 @@
347 plugin: copy
348 files:
349 webcam-webui: bin/webcam-webui
350-snappy-metadata: meta
351
352=== removed directory 'examples/wget-deb/meta'
353=== removed file 'examples/wget-deb/meta/package.yaml'
354--- examples/wget-deb/meta/package.yaml 2015-06-24 18:51:27 +0000
355+++ examples/wget-deb/meta/package.yaml 1970-01-01 00:00:00 +0000
356@@ -1,5 +0,0 @@
357-name: wget
358-version: 0
359-vendor: mterry@ubuntu.com
360-binaries:
361- - name: usr/bin/wget
362
363=== removed file 'examples/wget-deb/meta/readme.md'
364--- examples/wget-deb/meta/readme.md 2015-06-24 18:51:27 +0000
365+++ examples/wget-deb/meta/readme.md 1970-01-01 00:00:00 +0000
366@@ -1,1 +0,0 @@
367-wget
368
369=== modified file 'examples/wget-deb/snapcraft.yaml'
370--- examples/wget-deb/snapcraft.yaml 2015-08-05 18:40:06 +0000
371+++ examples/wget-deb/snapcraft.yaml 2015-08-27 16:38:02 +0000
372@@ -1,4 +1,11 @@
373+name: wget
374+version: 0
375+vendor: Michael Terry <mterry@ubuntu.com>
376+binaries:
377+ - name: usr/bin/wget
378+summary: wget for snappy
379+description: a basic example from ubuntu packages
380+
381 parts:
382 wget:
383 plugin: ubuntu
384-snappy-metadata: meta
385
386=== removed file 'integration-tests/data/assemble/package.yaml.after'
387--- integration-tests/data/assemble/package.yaml.after 2015-08-03 14:46:32 +0000
388+++ integration-tests/data/assemble/package.yaml.after 1970-01-01 00:00:00 +0000
389@@ -1,13 +0,0 @@
390-architecture: @ARCH@
391-binaries:
392-- exec: binary1.wrapper
393- name: assemble-bin
394-- exec: subdir/binary2.wrapper
395- name: binary2
396-name: assemble
397-services:
398-- name: assemble-service
399- start: service-start.wrapper
400- stop: service-stop.wrapper with args
401-vendor: mterry@ubuntu.com
402-version: 1.0
403
404=== modified file 'integration-tests/data/assemble/snapcraft.yaml'
405--- integration-tests/data/assemble/snapcraft.yaml 2015-07-15 16:26:06 +0000
406+++ integration-tests/data/assemble/snapcraft.yaml 2015-08-27 16:38:02 +0000
407@@ -1,3 +1,18 @@
408+name: assemble
409+version: 1.0
410+vendor: Sergio Schvezov <sergio.schvezov@canonical.com>
411+summary: one line summary
412+description: a longer description
413+binaries:
414+ - exec: binary1
415+ name: assemble-bin
416+ - exec: subdir/binary2
417+ name: binary2
418+services:
419+ - name: assemble-service
420+ start: service-start
421+ stop: service-stop with args
422+
423 parts:
424 make-project:
425 source: .
426
427=== modified file 'integration-tests/data/bzr-head/snapcraft.yaml'
428--- integration-tests/data/bzr-head/snapcraft.yaml 2015-07-14 21:15:07 +0000
429+++ integration-tests/data/bzr-head/snapcraft.yaml 2015-08-27 16:38:02 +0000
430@@ -1,3 +1,9 @@
431+name: test-package
432+version: 0.1
433+vendor: Sergio Schvezov <sergio.schvezov@canonical.com>
434+summary: one line summary
435+description: a longer description
436+
437 parts:
438 bzr:
439 plugin: make-project
440
441=== modified file 'integration-tests/data/bzr-tag/snapcraft.yaml'
442--- integration-tests/data/bzr-tag/snapcraft.yaml 2015-07-14 21:15:07 +0000
443+++ integration-tests/data/bzr-tag/snapcraft.yaml 2015-08-27 16:38:02 +0000
444@@ -1,3 +1,9 @@
445+name: test-package
446+version: 0.1
447+vendor: Sergio Schvezov <sergio.schvezov@canonical.com>
448+summary: one line summary
449+description: a longer description
450+
451 parts:
452 bzr:
453 plugin: make-project
454
455=== modified file 'integration-tests/data/conflicts/snapcraft.yaml'
456--- integration-tests/data/conflicts/snapcraft.yaml 2015-07-08 20:45:52 +0000
457+++ integration-tests/data/conflicts/snapcraft.yaml 2015-08-27 16:38:02 +0000
458@@ -1,3 +1,9 @@
459+name: test-package
460+version: 0.1
461+vendor: Sergio Schvezov <sergio.schvezov@canonical.com>
462+summary: one line summary
463+description: a longer description
464+
465 parts:
466 p1:
467 plugin: make-project
468
469=== modified file 'integration-tests/data/dependencies/snapcraft.yaml'
470--- integration-tests/data/dependencies/snapcraft.yaml 2015-07-08 20:45:52 +0000
471+++ integration-tests/data/dependencies/snapcraft.yaml 2015-08-27 16:38:02 +0000
472@@ -1,3 +1,9 @@
473+name: test-package
474+version: 0.1
475+vendor: Sergio Schvezov <sergio.schvezov@canonical.com>
476+summary: one line summary
477+description: a longer description
478+
479 parts:
480 p1:
481 plugin: make-project
482
483=== modified file 'integration-tests/data/git-branch/snapcraft.yaml'
484--- integration-tests/data/git-branch/snapcraft.yaml 2015-07-14 21:15:07 +0000
485+++ integration-tests/data/git-branch/snapcraft.yaml 2015-08-27 16:38:02 +0000
486@@ -1,3 +1,9 @@
487+name: test-package
488+version: 0.1
489+vendor: Sergio Schvezov <sergio.schvezov@canonical.com>
490+summary: one line summary
491+description: a longer description
492+
493 parts:
494 git:
495 plugin: make-project
496
497=== modified file 'integration-tests/data/git-head/snapcraft.yaml'
498--- integration-tests/data/git-head/snapcraft.yaml 2015-07-14 21:15:07 +0000
499+++ integration-tests/data/git-head/snapcraft.yaml 2015-08-27 16:38:02 +0000
500@@ -1,3 +1,9 @@
501+name: test-package
502+version: 0.1
503+vendor: Sergio Schvezov <sergio.schvezov@canonical.com>
504+summary: one line summary
505+description: a longer description
506+
507 parts:
508 git:
509 plugin: make-project
510
511=== modified file 'integration-tests/data/git-tag/snapcraft.yaml'
512--- integration-tests/data/git-tag/snapcraft.yaml 2015-07-14 21:15:07 +0000
513+++ integration-tests/data/git-tag/snapcraft.yaml 2015-08-27 16:38:02 +0000
514@@ -1,3 +1,9 @@
515+name: test-package
516+version: 0.1
517+vendor: Sergio Schvezov <sergio.schvezov@canonical.com>
518+summary: one line summary
519+description: a longer description
520+
521 parts:
522 git:
523 plugin: make-project
524
525=== modified file 'integration-tests/data/hg-branch/snapcraft.yaml'
526--- integration-tests/data/hg-branch/snapcraft.yaml 2015-08-05 23:04:22 +0000
527+++ integration-tests/data/hg-branch/snapcraft.yaml 2015-08-27 16:38:02 +0000
528@@ -1,3 +1,9 @@
529+name: test-package
530+version: 0.1
531+vendor: Sergio Schvezov <sergio.schvezov@canonical.com>
532+summary: one line summary
533+description: a longer description
534+
535 parts:
536 mercurial:
537 plugin: make-project
538
539=== modified file 'integration-tests/data/hg-head/snapcraft.yaml'
540--- integration-tests/data/hg-head/snapcraft.yaml 2015-08-05 23:04:22 +0000
541+++ integration-tests/data/hg-head/snapcraft.yaml 2015-08-27 16:38:02 +0000
542@@ -1,3 +1,9 @@
543+name: test-package
544+version: 0.1
545+vendor: Sergio Schvezov <sergio.schvezov@canonical.com>
546+summary: one line summary
547+description: a longer description
548+
549 parts:
550 mercurial:
551 plugin: make-project
552
553=== modified file 'integration-tests/data/hg-tag/snapcraft.yaml'
554--- integration-tests/data/hg-tag/snapcraft.yaml 2015-08-05 23:04:22 +0000
555+++ integration-tests/data/hg-tag/snapcraft.yaml 2015-08-27 16:38:02 +0000
556@@ -1,3 +1,9 @@
557+name: test-package
558+version: 0.1
559+vendor: Sergio Schvezov <sergio.schvezov@canonical.com>
560+summary: one line summary
561+description: a longer description
562+
563 parts:
564 mercurial:
565 plugin: make-project
566
567=== modified file 'integration-tests/data/local-plugin/snapcraft.yaml'
568--- integration-tests/data/local-plugin/snapcraft.yaml 2015-07-21 18:18:10 +0000
569+++ integration-tests/data/local-plugin/snapcraft.yaml 2015-08-27 16:38:02 +0000
570@@ -1,2 +1,8 @@
571+name: test-package
572+version: 0.1
573+vendor: Sergio Schvezov <sergio.schvezov@canonical.com>
574+summary: one line summary
575+description: a longer description
576+
577 parts:
578 x-local-plugin:
579
580=== modified file 'integration-tests/data/local-source/snapcraft.yaml'
581--- integration-tests/data/local-source/snapcraft.yaml 2015-07-02 20:30:03 +0000
582+++ integration-tests/data/local-source/snapcraft.yaml 2015-08-27 16:38:02 +0000
583@@ -1,3 +1,9 @@
584+name: test-package
585+version: 0.1
586+vendor: Sergio Schvezov <sergio.schvezov@canonical.com>
587+summary: one line summary
588+description: a longer description
589+
590 parts:
591 make-project:
592 source: .
593
594=== modified file 'integration-tests/data/simple-cmake/snapcraft.yaml'
595--- integration-tests/data/simple-cmake/snapcraft.yaml 2015-07-09 13:32:43 +0000
596+++ integration-tests/data/simple-cmake/snapcraft.yaml 2015-08-27 16:38:02 +0000
597@@ -1,3 +1,9 @@
598+name: test-package
599+version: 0.1
600+vendor: Sergio Schvezov <sergio.schvezov@canonical.com>
601+summary: one line summary
602+description: a longer description
603+
604 parts:
605 cmake-project:
606 source: .
607
608=== modified file 'integration-tests/data/simple-copy/snapcraft.yaml'
609--- integration-tests/data/simple-copy/snapcraft.yaml 2015-07-14 12:29:17 +0000
610+++ integration-tests/data/simple-copy/snapcraft.yaml 2015-08-27 16:38:02 +0000
611@@ -1,3 +1,9 @@
612+name: test-package
613+version: 0.1
614+vendor: Sergio Schvezov <sergio.schvezov@canonical.com>
615+summary: one line summary
616+description: a longer description
617+
618 parts:
619 copy-example:
620 plugin: copy
621
622=== modified file 'integration-tests/data/simple-make/snapcraft.yaml'
623--- integration-tests/data/simple-make/snapcraft.yaml 2015-07-06 13:18:53 +0000
624+++ integration-tests/data/simple-make/snapcraft.yaml 2015-08-27 16:38:02 +0000
625@@ -1,3 +1,9 @@
626+name: test-package
627+version: 0.1
628+vendor: Sergio Schvezov <sergio.schvezov@canonical.com>
629+summary: one line summary
630+description: a longer description
631+
632 parts:
633 make-project:
634 source: .
635
636=== modified file 'integration-tests/data/simple-tar/snapcraft.yaml'
637--- integration-tests/data/simple-tar/snapcraft.yaml 2015-07-24 01:23:44 +0000
638+++ integration-tests/data/simple-tar/snapcraft.yaml 2015-08-27 16:38:02 +0000
639@@ -1,3 +1,9 @@
640+name: test-package
641+version: 0.1
642+vendor: Sergio Schvezov <sergio.schvezov@canonical.com>
643+summary: one line summary
644+description: a longer description
645+
646 parts:
647 oneflat:
648 plugin: tar-content
649
650=== modified file 'integration-tests/units/jobs.pxu'
651--- integration-tests/units/jobs.pxu 2015-08-06 00:31:23 +0000
652+++ integration-tests/units/jobs.pxu 2015-08-27 16:38:02 +0000
653@@ -7,16 +7,6 @@
654 test $? = 1 || exit 1
655 echo $OUTPUT | grep "Could not find snapcraft\.yaml\."
656
657-id: snapcraft/normal/assemble-no-meta
658-plugin: shell
659-estimated_duration: 0.3
660-command:
661- set -x
662- cp -rT $PLAINBOX_PROVIDER_DATA/assemble .
663- OUTPUT=$(${SNAPCRAFT} assemble 2>&1)
664- test $? = 1 || exit 1
665- echo $OUTPUT | grep "Missing snappy metadata file"
666-
667 id: snapcraft/normal/assemble-meta-externally
668 plugin: shell
669 estimated_duration: 0.3
670@@ -34,11 +24,8 @@
671 command:
672 set -ex
673 cp -rT $PLAINBOX_PROVIDER_DATA/assemble .
674- echo "snappy-metadata: snappy" >> snapcraft.yaml
675 ${SNAPCRAFT} assemble
676 test -e "assemble_1.0_$(dpkg-architecture -qDEB_BUILD_ARCH).snap"
677- sed -i "s/@ARCH@/$(dpkg-architecture -qDEB_BUILD_ARCH)/g" package.yaml.after
678- diff -u package.yaml.after snap/meta/package.yaml
679 sed -i "s/@MULTIARCH@/$(dpkg-architecture -qDEB_BUILD_MULTIARCH)/g" binary1.after
680 diff -u binary1.after snap/binary1.wrapper
681 export SNAP_APP_PATH=`pwd`/snap
682
683=== modified file 'snapcraft/cmds.py'
684--- snapcraft/cmds.py 2015-08-26 12:33:12 +0000
685+++ snapcraft/cmds.py 2015-08-27 16:38:02 +0000
686@@ -23,12 +23,10 @@
687 import tempfile
688 import time
689
690-import yaml
691-
692 import snapcraft.plugin
693 import snapcraft.yaml
694 from snapcraft import common
695-
696+from snapcraft import meta
697
698 logger = logging.getLogger(__name__)
699
700@@ -62,98 +60,25 @@
701 common.run(userCommand)
702
703
704-def wrap_exe(relexepath):
705- snapdir = common.get_snapdir()
706- exepath = os.path.join(snapdir, relexepath)
707- wrappath = exepath + '.wrapper'
708-
709- try:
710- os.remove(wrappath)
711- except Exception:
712- pass
713-
714- wrapexec = '$SNAP_APP_PATH/{}'.format(relexepath)
715- if not os.path.exists(exepath) and '/' not in relexepath:
716- # If it doesn't exist it might be in the path
717- logger.info('Checking to see if "{}" is in the $PATH'.format(relexepath))
718- with tempfile.NamedTemporaryFile('w+') as tempf:
719- script = ('#!/bin/sh\n' +
720- '{}\n'.format(snapcraft.common.assemble_env()) +
721- 'which "{}"\n'.format(relexepath))
722- tempf.write(script)
723- tempf.flush()
724- if snapcraft.common.run(['/bin/sh', tempf.name], cwd=snapdir):
725- wrapexec = relexepath
726- else:
727- logger.warning('Warning: unable to find "{}" in the path'.format(relexepath))
728-
729- assembled_env = common.assemble_env().replace(snapdir, '$SNAP_APP_PATH')
730- script = ('#!/bin/sh\n' +
731- '{}\n'.format(assembled_env) +
732- 'exec "{}" $*\n'.format(wrapexec))
733-
734- with open(wrappath, 'w+') as f:
735- f.write(script)
736-
737- os.chmod(wrappath, 0o755)
738-
739- return os.path.relpath(wrappath, snapdir)
740-
741-
742 def snap(args):
743 cmd(args)
744
745- # Ensure the snappy metadata files are correct
746- config = snapcraft.yaml.Config()
747-
748- if 'snappy-metadata' in config.data:
749- common.run(
750- ['cp', '-arvT', config.data['snappy-metadata'], common.get_snapdir() + '/meta'])
751- if not os.path.exists('snap/meta/package.yaml'):
752- logger.error("Missing snappy metadata file 'meta/package.yaml'. Try specifying 'snappy-metadata' in snapcraft.yaml, pointing to a meta directory in your source tree.")
753- sys.exit(1)
754-
755- # wrap all included commands
756- with open("snap/meta/package.yaml", 'r') as f:
757- package = yaml.load(f)
758-
759- common.env = config.snap_env()
760-
761- def replace_cmd(execparts, cmd):
762- newparts = [cmd] + execparts[1:]
763- return ' '.join([shlex.quote(x) for x in newparts])
764-
765- for binary in package.get('binaries', []):
766- execparts = shlex.split(binary.get('exec', binary['name']))
767- execwrap = wrap_exe(execparts[0])
768- if 'exec' in binary:
769- binary['exec'] = replace_cmd(execparts, execwrap)
770- else:
771- binary['name'] = os.path.basename(binary['name'])
772- binary['exec'] = replace_cmd(execparts, execwrap)
773-
774- for binary in package.get('services', []):
775- startpath = binary.get('start')
776- if startpath:
777- startparts = shlex.split(startpath)
778- startwrap = wrap_exe(startparts[0])
779- binary['start'] = replace_cmd(startparts, startwrap)
780- stoppath = binary.get('stop')
781- if stoppath:
782- stopparts = shlex.split(stoppath)
783- stopwrap = wrap_exe(stopparts[0])
784- binary['stop'] = replace_cmd(stopparts, stopwrap)
785-
786- # Set architecture if none provided
787- if 'architecture' not in package and 'architectures' not in package:
788- package['architecture'] = snapcraft.common.get_arch()
789-
790- with open("snap/meta/package.yaml", 'w') as f:
791- yaml.dump(package, f, default_flow_style=False)
792+ # This check is to support manual assembly.
793+ if not os.path.exists(os.path.join(common.get_snapdir(), "meta")):
794+ arches = [snapcraft.common.get_arch(), ]
795+
796+ config = snapcraft.yaml.Config()
797+
798+ # FIXME this should be done in a more contained manner
799+ common.env = config.snap_env()
800+
801+ meta.create(config.data, arches)
802
803
804 def assemble(args):
805 args.cmd = 'snap'
806+ # With all the data in snapcraft.yaml, maybe it's not a good idea to call
807+ # snap(args) and just do a snappy build if assemble was explicitly called.
808 snap(args)
809 common.run(['snappy', 'build', common.get_snapdir()])
810
811
812=== added file 'snapcraft/meta.py'
813--- snapcraft/meta.py 1970-01-01 00:00:00 +0000
814+++ snapcraft/meta.py 2015-08-27 16:38:02 +0000
815@@ -0,0 +1,180 @@
816+# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
817+#
818+# Copyright (C) 2015 Canonical Ltd
819+#
820+# This program is free software: you can redistribute it and/or modify
821+# it under the terms of the GNU General Public License version 3 as
822+# published by the Free Software Foundation.
823+#
824+# This program is distributed in the hope that it will be useful,
825+# but WITHOUT ANY WARRANTY; without even the implied warranty of
826+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
827+# GNU General Public License for more details.
828+#
829+# You should have received a copy of the GNU General Public License
830+# along with this program. If not, see <http://www.gnu.org/licenses/>.
831+
832+import os
833+import logging
834+import shlex
835+import tempfile
836+import yaml
837+
838+from snapcraft import common
839+
840+logger = logging.getLogger(__name__)
841+
842+
843+_MANDATORY_PACKAGE_KEYS = [
844+ 'name',
845+ 'version',
846+ 'vendor',
847+]
848+
849+_OPTIONAL_PACKAGE_KEYS = [
850+ 'frameworks',
851+ 'type',
852+]
853+
854+
855+def create(config_data, arches=None):
856+ '''
857+ Create the meta directory and provision it with package.yaml and readme.md
858+ in the snap dir using information from config_data and arches.
859+ If provided arches, is a list of arches.
860+
861+ Returns meta_dir.
862+ '''
863+ # TODO keys for using apparmor, setting an icon missing.
864+
865+ meta_dir = os.path.join(common.get_snapdir(), 'meta')
866+ os.makedirs(meta_dir, exist_ok=True)
867+
868+ _write_package_yaml(meta_dir, config_data, arches)
869+ _write_readme_md(meta_dir, config_data)
870+
871+ return meta_dir
872+
873+
874+def _write_package_yaml(meta_dir, config_data, arches):
875+ package_yaml_path = os.path.join(meta_dir, 'package.yaml')
876+ package_yaml = _compose_package_yaml(config_data, arches)
877+
878+ with open(package_yaml_path, 'w') as f:
879+ yaml.dump(package_yaml, stream=f, default_flow_style=False)
880+
881+
882+def _write_readme_md(meta_dir, config_data):
883+ readme_md_path = os.path.join(meta_dir, 'readme.md')
884+ readme_md = _compose_readme(config_data)
885+
886+ with open(readme_md_path, 'w') as f:
887+ f.write(readme_md)
888+
889+
890+def _compose_package_yaml(config_data, arches):
891+ '''
892+ Creates a dictionary that can be used to yaml.dump a package.yaml using
893+ config_data.
894+ If provided arches, is a list of arches.
895+
896+ Missing key exceptions will be raised if config_data does not hold
897+ MANDATORY_KEYS, config_data can be validated against the snapcraft schema.
898+ '''
899+ package_yaml = {}
900+
901+ for key_name in _MANDATORY_PACKAGE_KEYS:
902+ package_yaml[key_name] = config_data[key_name]
903+
904+ for key_name in _OPTIONAL_PACKAGE_KEYS:
905+ if key_name in config_data:
906+ package_yaml[key_name] = config_data[key_name]
907+
908+ if arches:
909+ package_yaml['architectures'] = arches
910+
911+ if 'binaries' in config_data:
912+ package_yaml['binaries'] = _wrap_binaries(config_data['binaries'])
913+
914+ if 'services' in config_data:
915+ package_yaml['services'] = _wrap_services(config_data['services'])
916+
917+ return package_yaml
918+
919+
920+def _compose_readme(config_data):
921+ return '{config[summary]}\n{config[description]}\n'.format(config=config_data)
922+
923+
924+def _replace_cmd(execparts, cmd):
925+ newparts = [cmd] + execparts[1:]
926+ return ' '.join([shlex.quote(x) for x in newparts])
927+
928+
929+def _wrap_exe(relexepath):
930+ snap_dir = common.get_snapdir()
931+ exepath = os.path.join(snap_dir, relexepath)
932+ wrappath = exepath + '.wrapper'
933+
934+ # TODO talk to original author if the exception to be captured here is
935+ # FileNotFoundError, the original code was a general catch all
936+ try:
937+ os.remove(wrappath)
938+ except FileNotFoundError:
939+ pass
940+
941+ wrapexec = '$SNAP_APP_PATH/{}'.format(relexepath)
942+ if not os.path.exists(exepath) and '/' not in relexepath:
943+ # If it doesn't exist it might be in the path
944+ logger.debug('Checking to see if "{}" is in the $PATH'.format(relexepath))
945+ with tempfile.NamedTemporaryFile('w+') as tempf:
946+ script = ('#!/bin/sh\n' +
947+ '{}\n'.format(common.assemble_env()) +
948+ 'which "{}"\n'.format(relexepath))
949+ tempf.write(script)
950+ tempf.flush()
951+ if common.run(['/bin/sh', tempf.name], cwd=snap_dir):
952+ wrapexec = relexepath
953+ else:
954+ logger.warning('Warning: unable to find "{}" in the path'.format(relexepath))
955+
956+ assembled_env = common.assemble_env().replace(snap_dir, '$SNAP_APP_PATH')
957+ script = ('#!/bin/sh\n' +
958+ '{}\n'.format(assembled_env) +
959+ 'exec "{}" $*\n'.format(wrapexec))
960+
961+ with open(wrappath, 'w+') as f:
962+ f.write(script)
963+
964+ os.chmod(wrappath, 0o755)
965+
966+ return os.path.relpath(wrappath, snap_dir)
967+
968+
969+def _wrap_binaries(binaries):
970+ for binary in binaries:
971+ execparts = shlex.split(binary.get('exec', binary['name']))
972+ execwrap = _wrap_exe(execparts[0])
973+ if 'exec' in binary:
974+ binary['exec'] = _replace_cmd(execparts, execwrap)
975+ else:
976+ binary['name'] = os.path.basename(binary['name'])
977+ binary['exec'] = _replace_cmd(execparts, execwrap)
978+
979+ return binaries
980+
981+
982+def _wrap_services(services):
983+ for binary in services:
984+ startpath = binary.get('start')
985+ if startpath:
986+ startparts = shlex.split(startpath)
987+ startwrap = _wrap_exe(startparts[0])
988+ binary['start'] = _replace_cmd(startparts, startwrap)
989+ stoppath = binary.get('stop')
990+ if stoppath:
991+ stopparts = shlex.split(stoppath)
992+ stopwrap = _wrap_exe(stopparts[0])
993+ binary['stop'] = _replace_cmd(stopparts, stopwrap)
994+
995+ return services
996
997=== modified file 'snapcraft/tests/test_cmds.py'
998--- snapcraft/tests/test_cmds.py 2015-08-05 15:39:18 +0000
999+++ snapcraft/tests/test_cmds.py 2015-08-27 16:38:02 +0000
1000@@ -23,7 +23,6 @@
1001
1002 from snapcraft import (
1003 cmds,
1004- common,
1005 tests
1006 )
1007
1008@@ -97,21 +96,3 @@
1009 self.assertEqual(
1010 'Wrote the following as snapcraft.yaml.\n',
1011 fake_logger.output)
1012-
1013-
1014-class WrapExeTestCase(tests.TestCase):
1015-
1016- def test_wrap_exe_must_write_wrapper(self):
1017- snapdir = common.get_snapdir()
1018- os.mkdir(snapdir)
1019- relative_exe_path = 'test_relexepath'
1020- relative_wrapper_path = cmds.wrap_exe(relative_exe_path)
1021- wrapper_path = os.path.join(snapdir, relative_wrapper_path)
1022-
1023- expected = ('#!/bin/sh\n'
1024- '\n'
1025- 'exec "$SNAP_APP_PATH/test_relexepath" $*\n')
1026- with open(wrapper_path, 'r') as wrapper_file:
1027- wrapper_contents = wrapper_file.read()
1028-
1029- self.assertEqual(expected, wrapper_contents)
1030
1031=== added file 'snapcraft/tests/test_meta.py'
1032--- snapcraft/tests/test_meta.py 1970-01-01 00:00:00 +0000
1033+++ snapcraft/tests/test_meta.py 2015-08-27 16:38:02 +0000
1034@@ -0,0 +1,258 @@
1035+# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
1036+#
1037+# Copyright (C) 2015 Canonical Ltd
1038+#
1039+# This program is free software: you can redistribute it and/or modify
1040+# it under the terms of the GNU General Public License version 3 as
1041+# published by the Free Software Foundation.
1042+#
1043+# This program is distributed in the hope that it will be useful,
1044+# but WITHOUT ANY WARRANTY; without even the implied warranty of
1045+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1046+# GNU General Public License for more details.
1047+#
1048+# You should have received a copy of the GNU General Public License
1049+# along with this program. If not, see <http://www.gnu.org/licenses/>.
1050+
1051+import os
1052+from unittest.mock import (
1053+ Mock,
1054+ call,
1055+ mock_open,
1056+ patch,
1057+)
1058+
1059+from snapcraft import (
1060+ common,
1061+ meta,
1062+ tests
1063+)
1064+
1065+
1066+class ComposeTestCase(tests.TestCase):
1067+
1068+ def setUp(self):
1069+ super().setUp()
1070+ patcher = patch('snapcraft.meta._wrap_exe')
1071+ mock_wrap_exe = patcher.start()
1072+ mock_wrap_exe.return_value = 'binary.wrapped'
1073+ self.addCleanup(patcher.stop)
1074+
1075+ self.config_data = {
1076+ 'name': 'my-package',
1077+ 'version': '1.0',
1078+ 'vendor': 'Sergio Schvezov <sergio.schvezov@canonical.com>',
1079+ }
1080+
1081+ def test_plain_no_binaries_or_services(self):
1082+
1083+ y = meta._compose_package_yaml(self.config_data, ['armhf', 'amd64'])
1084+
1085+ expected = {
1086+ 'name': 'my-package',
1087+ 'version': '1.0',
1088+ 'vendor': 'Sergio Schvezov <sergio.schvezov@canonical.com>',
1089+ 'architectures': ['armhf', 'amd64'],
1090+ }
1091+
1092+ self.assertEqual(y, expected)
1093+
1094+ def test_plain_no_binaries_or_services_or_arches(self):
1095+
1096+ y = meta._compose_package_yaml(self.config_data, None)
1097+
1098+ expected = {
1099+ 'name': 'my-package',
1100+ 'version': '1.0',
1101+ 'vendor': 'Sergio Schvezov <sergio.schvezov@canonical.com>',
1102+ }
1103+
1104+ self.assertEqual(y, expected)
1105+
1106+ def test_with_binaries(self):
1107+ self.config_data['binaries'] = [
1108+ {
1109+ 'name': 'binary1',
1110+ 'exec': 'binary1.sh go',
1111+ },
1112+ {
1113+ 'name': 'binary2',
1114+ },
1115+ ]
1116+
1117+ y = meta._compose_package_yaml(self.config_data, ['armhf', 'amd64'])
1118+
1119+ expected = {
1120+ 'name': 'my-package',
1121+ 'version': '1.0',
1122+ 'vendor': 'Sergio Schvezov <sergio.schvezov@canonical.com>',
1123+ 'architectures': ['armhf', 'amd64'],
1124+ 'binaries': [
1125+ {
1126+ 'name': 'binary1',
1127+ 'exec': 'binary.wrapped go',
1128+ },
1129+ {
1130+ 'name': 'binary2',
1131+ 'exec': 'binary.wrapped',
1132+ },
1133+ ],
1134+ }
1135+
1136+ self.assertEqual(y, expected)
1137+
1138+ def test_with_services(self):
1139+ self.config_data['services'] = [
1140+ {
1141+ 'name': 'service1',
1142+ 'start': 'binary1',
1143+ },
1144+ {
1145+ 'name': 'service2',
1146+ 'start': 'binary2 --start',
1147+ 'stop': 'binary2 --stop',
1148+ },
1149+ {
1150+ 'name': 'service3',
1151+ },
1152+ ]
1153+
1154+ y = meta._compose_package_yaml(self.config_data, ['armhf', 'amd64'])
1155+
1156+ expected = {
1157+ 'name': 'my-package',
1158+ 'version': '1.0',
1159+ 'vendor': 'Sergio Schvezov <sergio.schvezov@canonical.com>',
1160+ 'architectures': ['armhf', 'amd64'],
1161+ 'services': [
1162+ {
1163+ 'name': 'service1',
1164+ 'start': 'binary.wrapped',
1165+ },
1166+ {
1167+ 'name': 'service2',
1168+ 'start': 'binary.wrapped --start',
1169+ 'stop': 'binary.wrapped --stop',
1170+ },
1171+ {
1172+ 'name': 'service3',
1173+ }
1174+ ],
1175+ }
1176+
1177+ self.assertEqual(y, expected)
1178+
1179+ def test_plain_no_binaries_or_services_with_optionals(self):
1180+ self.config_data['frameworks'] = ['mir', ]
1181+
1182+ y = meta._compose_package_yaml(self.config_data, ['armhf', 'amd64'])
1183+
1184+ expected = {
1185+ 'name': 'my-package',
1186+ 'version': '1.0',
1187+ 'vendor': 'Sergio Schvezov <sergio.schvezov@canonical.com>',
1188+ 'architectures': ['armhf', 'amd64'],
1189+ 'frameworks': ['mir', ],
1190+ }
1191+
1192+ self.assertEqual(y, expected)
1193+
1194+ def test_compose_readme(self):
1195+ self.config_data['summary'] = 'one line summary'
1196+ self.config_data['description'] = 'the description\nwhich can be longer'
1197+
1198+ readme_text = '''one line summary
1199+the description
1200+which can be longer
1201+'''
1202+
1203+ self.assertEqual(meta._compose_readme(self.config_data), readme_text)
1204+
1205+
1206+class Create(tests.TestCase):
1207+
1208+ def setUp(self):
1209+ super().setUp()
1210+ self.orig_os_makedirs = os.makedirs
1211+
1212+ self.config_data = {
1213+ 'name': 'my-package',
1214+ 'version': '1.0',
1215+ 'vendor': 'Sergio Schvezov <sergio.schvezov@canonical.com>',
1216+ 'description': 'my description',
1217+ 'summary': 'my summary',
1218+ }
1219+
1220+ def tearDown(self):
1221+ super().tearDown()
1222+ os.makedirs = self.orig_os_makedirs
1223+
1224+ def test_create_meta(self):
1225+ os.makedirs = Mock()
1226+ mock_the_open = mock_open()
1227+
1228+ with patch('snapcraft.meta.open', mock_the_open, create=True):
1229+ meta.create(self.config_data, ['amd64'])
1230+
1231+ meta_dir = os.path.join(os.path.abspath(os.curdir), 'snap', 'meta')
1232+
1233+ os.makedirs.assert_called_once_with(meta_dir, exist_ok=True)
1234+
1235+ mock_the_open.assert_has_calls([
1236+ call(os.path.join(meta_dir, 'package.yaml'), 'w'),
1237+ call().__enter__(),
1238+ call().write('architectures'),
1239+ call().write(':'),
1240+ call().write('\n'),
1241+ call().write('-'),
1242+ call().write(' '),
1243+ call().write('amd64'),
1244+ call().write('\n'),
1245+ call().write('name'),
1246+ call().write(':'),
1247+ call().write(' '),
1248+ call().write('my-package'),
1249+ call().write('\n'),
1250+ call().write('vendor'),
1251+ call().write(':'),
1252+ call().write(' '),
1253+ call().write('Sergio'),
1254+ call().write(' '),
1255+ call().write('Schvezov'),
1256+ call().write(' '),
1257+ call().write('<sergio.schvezov@canonical.com>'),
1258+ call().write('\n'),
1259+ call().write('version'),
1260+ call().write(':'),
1261+ call().write(" '"),
1262+ call().write('1.0'),
1263+ call().write("'"),
1264+ call().write('\n'),
1265+ call().flush(),
1266+ call().flush(),
1267+ call().__exit__(None, None, None),
1268+ call(os.path.join(meta_dir, 'readme.md'), 'w'),
1269+ call().__enter__(),
1270+ call().write('my summary\nmy description\n'),
1271+ call().__exit__(None, None, None),
1272+ ]
1273+ )
1274+
1275+
1276+# TODO this needs more tests.
1277+class WrapExeTestCase(tests.TestCase):
1278+
1279+ def test_wrap_exe_must_write_wrapper(self):
1280+ snapdir = common.get_snapdir()
1281+ os.mkdir(snapdir)
1282+ relative_exe_path = 'test_relexepath'
1283+ relative_wrapper_path = meta._wrap_exe(relative_exe_path)
1284+ wrapper_path = os.path.join(snapdir, relative_wrapper_path)
1285+
1286+ expected = ('#!/bin/sh\n'
1287+ '\n'
1288+ 'exec "$SNAP_APP_PATH/test_relexepath" $*\n')
1289+ with open(wrapper_path) as wrapper_file:
1290+ wrapper_contents = wrapper_file.read()
1291+
1292+ self.assertEqual(expected, wrapper_contents)

Subscribers

People subscribed via source and target branches