Merge lp:~sergiusens/snapcraft/mapnames into lp:~snappy-dev/snapcraft/core

Proposed by Sergio Schvezov
Status: Merged
Approved by: Sergio Schvezov
Approved revision: 185
Merged at revision: 185
Proposed branch: lp:~sergiusens/snapcraft/mapnames
Merge into: lp:~snappy-dev/snapcraft/core
Diff against target: 517 lines (+97/-142)
15 files modified
examples/downloader-with-wiki-parts/snapcraft.yaml (+2/-1)
examples/godd/snapcraft.yaml (+2/-1)
examples/gopaste/snapcraft.yaml (+1/-1)
examples/java-hello-world/snapcraft.yaml (+1/-1)
examples/libpipeline/snapcraft.yaml (+2/-1)
examples/py2-project/snapcraft.yaml (+2/-1)
examples/py3-project/snapcraft.yaml (+2/-1)
examples/qmldemo/snapcraft.yaml (+1/-1)
examples/tomcat-maven-webapp/snapcraft.yaml (+1/-1)
examples/webcam-webui/snapcraft.yaml (+1/-1)
integration-tests/data/assemble/snapcraft.yaml (+5/-5)
schema/snapcraft.yaml (+13/-16)
snapcraft/meta.py (+22/-16)
snapcraft/tests/test_meta.py (+24/-66)
snapcraft/tests/test_yaml.py (+18/-29)
To merge this branch: bzr merge lp:~sergiusens/snapcraft/mapnames
Reviewer Review Type Date Requested Status
Sergio Schvezov Approve
Daniel Holbach Pending
Michael Vogt Pending
Review via email: mp+271799@code.launchpad.net

This proposal supersedes a proposal from 2015-09-21.

Commit message

Using a map instead of list for binaries and services as defined by the spec

To post a comment you must log in.
Revision history for this message
Daniel Holbach (dholbach) wrote : Posted in a previous version of this proposal

Looks good.

review: Approve
Revision history for this message
Michael Vogt (mvo) wrote : Posted in a previous version of this proposal

Looks good.

review: Approve
Revision history for this message
Snappy Tarmac (snappydevtarmac) wrote : Posted in a previous version of this proposal

More than one proposal found for merge of https://code.launchpad.net/~sergiusens/snapcraft/config into https://code.launchpad.net/~snappy-dev/snapcraft/core, which is not Superseded.

Revision history for this message
Snappy Tarmac (snappydevtarmac) wrote : Posted in a previous version of this proposal

More than one proposal found for merge of https://code.launchpad.net/~sergiusens/snapcraft/config into https://code.launchpad.net/~snappy-dev/snapcraft/core, which is not Superseded.

Revision history for this message
Sergio Schvezov (sergiusens) wrote :

I resubmitted to get rid of the tarmac issue

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'examples/downloader-with-wiki-parts/snapcraft.yaml'
2--- examples/downloader-with-wiki-parts/snapcraft.yaml 2015-09-15 15:20:24 +0000
3+++ examples/downloader-with-wiki-parts/snapcraft.yaml 2015-09-21 11:41:30 +0000
4@@ -5,7 +5,8 @@
5 description: this is an example package
6 icon: icon.png
7 binaries:
8- - name: bin/test
9+ test:
10+ exec: bin/test
11
12 parts:
13 main:
14
15=== modified file 'examples/godd/snapcraft.yaml'
16--- examples/godd/snapcraft.yaml 2015-09-18 14:53:03 +0000
17+++ examples/godd/snapcraft.yaml 2015-09-21 11:41:30 +0000
18@@ -2,7 +2,8 @@
19 version: 1.0
20 vendor: Michael Vogt <mvo@ubuntu.com>
21 binaries:
22- - name: ./bin/godd
23+ godd:
24+ exec: ./bin/godd
25 summary: Simple dd like tool
26 description: written in go so it is self contained and really portable, you would need to use hw-assign to access devices.
27 icon: icon.png
28
29=== modified file 'examples/gopaste/snapcraft.yaml'
30--- examples/gopaste/snapcraft.yaml 2015-09-08 21:06:47 +0000
31+++ examples/gopaste/snapcraft.yaml 2015-09-21 11:41:30 +0000
32@@ -2,7 +2,7 @@
33 version: 1.0
34 vendor: Michael Terry <mterry@ubuntu.com>
35 services:
36- - name: gopaste
37+ gopaste:
38 description: "gopaste"
39 start: bin/gopasted
40 summary: Simple pasting tool
41
42=== modified file 'examples/java-hello-world/snapcraft.yaml'
43--- examples/java-hello-world/snapcraft.yaml 2015-09-15 09:43:13 +0000
44+++ examples/java-hello-world/snapcraft.yaml 2015-09-21 11:41:30 +0000
45@@ -2,7 +2,7 @@
46 version: 0
47 vendor: Michael Terry <mterry@ubuntu.com>
48 binaries:
49- - name: hello
50+ hello:
51 exec: bin/wrapper
52 summary: A java example
53 description: this is not much more than an example
54
55=== modified file 'examples/libpipeline/snapcraft.yaml'
56--- examples/libpipeline/snapcraft.yaml 2015-09-08 11:48:30 +0000
57+++ examples/libpipeline/snapcraft.yaml 2015-09-21 11:41:30 +0000
58@@ -2,7 +2,8 @@
59 version: 1.0
60 vendor: Mike Terry <mterry@ubuntu.com>
61 binaries:
62- - name: ./bin/pipelinetest
63+ pipelinetest:
64+ exec: ./bin/pipelinetest
65 summary: Libpipeline example
66 description: this is an example package of an autotools project built with snapcraft using
67 icon: icon.png
68
69=== modified file 'examples/py2-project/snapcraft.yaml'
70--- examples/py2-project/snapcraft.yaml 2015-09-08 11:48:30 +0000
71+++ examples/py2-project/snapcraft.yaml 2015-09-21 11:41:30 +0000
72@@ -2,7 +2,8 @@
73 version: 0
74 vendor: Michael Vogt <michael.vogt@ubuntu.com>
75 binaries:
76- - name: ./bin/sha3sum
77+ sha3sum:
78+ exec: ./bin/sha3sum
79 summary: A python sha3 implementation
80 description: A python2 project using snapcraft
81 icon: icon.png
82
83=== modified file 'examples/py3-project/snapcraft.yaml'
84--- examples/py3-project/snapcraft.yaml 2015-09-08 11:48:30 +0000
85+++ examples/py3-project/snapcraft.yaml 2015-09-21 11:41:30 +0000
86@@ -2,7 +2,8 @@
87 version: 0
88 vendor: Michael Vogt <michael.vogt@ubuntu.com>
89 binaries:
90- - name: bin/sha3sum
91+ sha3sum:
92+ exec: bin/sha3sum
93 summary: A python sha3 implementation
94 description: A python2 project using snapcraft
95 icon: icon.png
96
97=== modified file 'examples/qmldemo/snapcraft.yaml'
98--- examples/qmldemo/snapcraft.yaml 2015-09-08 11:50:21 +0000
99+++ examples/qmldemo/snapcraft.yaml 2015-09-21 11:41:30 +0000
100@@ -4,7 +4,7 @@
101 frameworks:
102 - mir
103 binaries:
104- - name: qmldemo
105+ qmldemo:
106 exec: qmlscene demo.qml --
107 caps:
108 - mir_client
109
110=== modified file 'examples/tomcat-maven-webapp/snapcraft.yaml'
111--- examples/tomcat-maven-webapp/snapcraft.yaml 2015-09-08 11:50:21 +0000
112+++ examples/tomcat-maven-webapp/snapcraft.yaml 2015-09-21 11:41:30 +0000
113@@ -4,7 +4,7 @@
114 architectures:
115 - amd64
116 services:
117- - name: tomcat
118+ tomcat:
119 start: bin/wrapper
120 caps:
121 - networking
122
123=== modified file 'examples/webcam-webui/snapcraft.yaml'
124--- examples/webcam-webui/snapcraft.yaml 2015-09-20 14:34:08 +0000
125+++ examples/webcam-webui/snapcraft.yaml 2015-09-21 11:41:30 +0000
126@@ -5,7 +5,7 @@
127 description: Exposes your webcam over a web UI
128 icon: icon.png
129 services:
130- - name: webcam-webui
131+ webcam-webui:
132 start: bin/webcam-webui
133 config: usr/bin/config.py
134
135
136=== modified file 'integration-tests/data/assemble/snapcraft.yaml'
137--- integration-tests/data/assemble/snapcraft.yaml 2015-09-01 19:04:49 +0000
138+++ integration-tests/data/assemble/snapcraft.yaml 2015-09-21 11:41:30 +0000
139@@ -5,12 +5,12 @@
140 description: a longer description
141 icon: icon.png
142 binaries:
143- - exec: binary1
144- name: assemble-bin
145- - exec: subdir/binary2
146- name: binary2
147+ assemble-bin:
148+ exec: binary1
149+ binary2:
150+ exec: subdir/binary2
151 services:
152- - name: assemble-service
153+ assemble-service:
154 start: service-start
155 stop: service-stop with args
156
157
158=== modified file 'schema/snapcraft.yaml'
159--- schema/snapcraft.yaml 2015-09-16 19:31:05 +0000
160+++ schema/snapcraft.yaml 2015-09-21 11:41:30 +0000
161@@ -56,16 +56,14 @@
162 type: string
163 description: path to a configure hook to expose configuration for the package
164 services:
165- type: array
166- items:
167- - type: object
168+ type: object
169+ additionalProperties: false
170+ patternProperties:
171+ "^[A-Za-z0-9:-]*$":
172+ type: object
173 required:
174- - name
175 - start
176 properties:
177- name:
178- type: string
179- pattern: "^[A-Za-z0-9/.:-]*$"
180 start:
181 type: string
182 description: command executed to start the service
183@@ -77,18 +75,17 @@
184 security-override:
185 $ref: "#definitions/security"
186 binaries:
187- type: array
188- items:
189- - type: object
190+ type: object
191+ additionalProperties: false
192+ patternProperties:
193+ "^[A-Za-z0-9:-]*$":
194+ type: object
195 required:
196- - name
197+ - exec
198 properties:
199- name:
200- type: string
201- pattern: "^[A-Za-z0-9/.:-]*$"
202 exec:
203 type: string
204- description: command executed to start the service
205+ description: command executed to run the binary
206 security-policy:
207 $ref: "#definitions/security"
208 security-override:
209@@ -96,6 +93,7 @@
210 parts:
211 type: object
212 minProperties: 1
213+ additionalProperties: false
214 patternProperties:
215 ^[a-z0-9][a-z0-9+-]*$:
216 type: object
217@@ -116,7 +114,6 @@
218 # required:
219 # - plugin
220 # - source
221- addtionalProperties: false
222 required:
223 - name
224 - version
225
226=== modified file 'snapcraft/meta.py'
227--- snapcraft/meta.py 2015-09-16 19:31:05 +0000
228+++ snapcraft/meta.py 2015-09-21 11:41:30 +0000
229@@ -130,16 +130,26 @@
230 package_yaml['architectures'] = arches
231
232 if 'binaries' in config_data:
233- package_yaml['binaries'] = _wrap_binaries(config_data['binaries'])
234- package_yaml['binaries'] = _copy_security_profiles(meta_dir, config_data['binaries'])
235+ binaries = config_data['binaries']
236+ binaries = _wrap_binaries(binaries)
237+ package_yaml['binaries'] = _copy_security_profiles(meta_dir, _repack_names(binaries))
238
239 if 'services' in config_data:
240- package_yaml['services'] = _wrap_services(config_data['services'])
241- package_yaml['services'] = _copy_security_profiles(meta_dir, config_data['services'])
242+ services = config_data['services']
243+ services = _wrap_services(services)
244+ package_yaml['services'] = _copy_security_profiles(meta_dir, _repack_names(services))
245
246 return package_yaml
247
248
249+def _repack_names(names):
250+ repack = []
251+ for name in names:
252+ names[name].update({'name': name})
253+ repack.append(names[name])
254+ return repack
255+
256+
257 def _compose_readme(config_data):
258 return '{config[summary]}\n{config[description]}\n'.format(config=config_data)
259
260@@ -199,29 +209,25 @@
261
262
263 def _wrap_binaries(binaries):
264- for binary in binaries:
265- execparts = shlex.split(binary.get('exec', binary['name']))
266+ for name in binaries:
267+ execparts = shlex.split(binaries[name]['exec'])
268 execwrap = _wrap_exe(execparts[0])
269- if 'exec' in binary:
270- binary['exec'] = _replace_cmd(execparts, execwrap)
271- else:
272- binary['name'] = os.path.basename(binary['name'])
273- binary['exec'] = _replace_cmd(execparts, execwrap)
274+ binaries[name]['exec'] = _replace_cmd(execparts, execwrap)
275
276 return binaries
277
278
279 def _wrap_services(services):
280- for binary in services:
281- startpath = binary.get('start')
282+ for name in services:
283+ startpath = services[name].get('start')
284 if startpath:
285 startparts = shlex.split(startpath)
286 startwrap = _wrap_exe(startparts[0])
287- binary['start'] = _replace_cmd(startparts, startwrap)
288- stoppath = binary.get('stop')
289+ services[name]['start'] = _replace_cmd(startparts, startwrap)
290+ stoppath = services[name].get('stop')
291 if stoppath:
292 stopparts = shlex.split(stoppath)
293 stopwrap = _wrap_exe(stopparts[0])
294- binary['stop'] = _replace_cmd(stopparts, stopwrap)
295+ services[name]['stop'] = _replace_cmd(stopparts, stopwrap)
296
297 return services
298
299=== modified file 'snapcraft/tests/test_meta.py'
300--- snapcraft/tests/test_meta.py 2015-09-16 19:31:05 +0000
301+++ snapcraft/tests/test_meta.py 2015-09-21 11:41:30 +0000
302@@ -69,79 +69,38 @@
303 self.assertEqual(y, expected)
304
305 def test_with_binaries(self):
306- self.config_data['binaries'] = [
307- {
308- 'name': 'binary1',
309- 'exec': 'binary1.sh go',
310- },
311- {
312- 'name': 'binary2',
313- },
314- ]
315+ self.config_data['binaries'] = {
316+ 'binary1': {'exec': 'binary1.sh go'},
317+ 'binary2': {'exec': 'binary2.sh'},
318+ }
319
320 y = meta._compose_package_yaml('meta', self.config_data, ['armhf', 'amd64'])
321
322- expected = {
323- 'name': 'my-package',
324- 'version': '1.0',
325- 'vendor': 'Sergio Schvezov <sergio.schvezov@canonical.com>',
326- 'icon': 'my-icon.png',
327- 'architectures': ['armhf', 'amd64'],
328- 'binaries': [
329- {
330- 'name': 'binary1',
331- 'exec': 'binary.wrapped go',
332- },
333- {
334- 'name': 'binary2',
335- 'exec': 'binary.wrapped',
336- },
337- ],
338- }
339-
340- self.assertEqual(y, expected)
341+ self.assertEqual(len(y['binaries']), 2)
342+ for b in y['binaries']:
343+ if b['name'] is 'binary1':
344+ self.assertEqual(b['exec'], 'binary.wrapped go')
345+ else:
346+ self.assertEqual(b['exec'], 'binary.wrapped')
347
348 def test_with_services(self):
349- self.config_data['services'] = [
350- {
351- 'name': 'service1',
352- 'start': 'binary1',
353- },
354- {
355- 'name': 'service2',
356+ self.config_data['services'] = {
357+ 'service1': {'start': 'binary1'},
358+ 'service2': {
359 'start': 'binary2 --start',
360 'stop': 'binary2 --stop',
361 },
362- {
363- 'name': 'service3',
364- },
365- ]
366+ }
367
368 y = meta._compose_package_yaml('meta', self.config_data, ['armhf', 'amd64'])
369
370- expected = {
371- 'name': 'my-package',
372- 'version': '1.0',
373- 'vendor': 'Sergio Schvezov <sergio.schvezov@canonical.com>',
374- 'icon': 'my-icon.png',
375- 'architectures': ['armhf', 'amd64'],
376- 'services': [
377- {
378- 'name': 'service1',
379- 'start': 'binary.wrapped',
380- },
381- {
382- 'name': 'service2',
383- 'start': 'binary.wrapped --start',
384- 'stop': 'binary.wrapped --stop',
385- },
386- {
387- 'name': 'service3',
388- }
389- ],
390- }
391-
392- self.assertEqual(y, expected)
393+ self.assertEqual(len(y['services']), 2)
394+ for b in y['services']:
395+ if b['name'] is 'service1':
396+ self.assertEqual(b['start'], 'binary.wrapped')
397+ else:
398+ self.assertEqual(b['start'], 'binary.wrapped --start')
399+ self.assertEqual(b['stop'], 'binary.wrapped --stop')
400
401 def test_plain_no_binaries_or_services_with_optionals(self):
402 self.config_data['frameworks'] = ['mir', ]
403@@ -200,16 +159,15 @@
404 'summary': 'my summary',
405 'icon': 'my-icon.png',
406 'config': 'bin/config',
407- 'binaries': [
408- {
409- 'name': 'bash',
410+ 'binaries': {
411+ 'bash': {
412 'exec': 'bin/bash',
413 'security-policy': {
414 'apparmor': 'file.apparmor',
415 'seccomp': 'file.seccomp',
416 },
417 }
418- ]
419+ }
420 }
421
422 self.meta_dir = os.path.join(os.path.abspath(os.curdir), 'snap', 'meta')
423
424=== modified file 'snapcraft/tests/test_yaml.py'
425--- snapcraft/tests/test_yaml.py 2015-09-15 14:45:57 +0000
426+++ snapcraft/tests/test_yaml.py 2015-09-21 11:41:30 +0000
427@@ -369,72 +369,61 @@
428 self.assertEqual(raised.exception.message, expected_message, msg=data)
429
430 def test_valid_services(self):
431- self.data['services'] = [
432- {
433- 'name': 'service1',
434- 'start': 'binary1 start',
435- },
436- {
437- 'name': 'service2',
438+ self.data['services'] = {
439+ 'service1': {'start': 'binary1 start'},
440+ 'service2': {
441 'start': 'binary2',
442 'stop': 'binary2 --stop',
443 },
444- {
445- 'name': 'service3',
446- }
447- ]
448+ }
449
450 snapcraft.yaml._validate_snapcraft_yaml(self.data)
451
452 def test_invalid_binary_names(self):
453 invalid_names = {
454- '#': {'name': 'qwe#rty', 'exec': '1'},
455- '_': {'name': 'qwe_rty', 'exec': '1'},
456- 'space': {'name': 'qwe rty', 'exec': '1'},
457- 'spaces': {'name': 'qwe rty', 'exec': '1'},
458+ 'qwe#rty': {'exec': '1'},
459+ 'qwe_rty': {'exec': '1'},
460+ 'que rty': {'exec': '1'},
461+ 'que rty': {'exec': '1'},
462 }
463
464 for t in invalid_names:
465 data = self.data.copy()
466 with self.subTest(key=t):
467- data['binaries'] = [invalid_names[t]]
468+ data['binaries'] = {t: invalid_names[t]}
469
470 with self.assertRaises(snapcraft.yaml.SnapcraftSchemaError) as raised:
471 snapcraft.yaml._validate_snapcraft_yaml(data)
472
473- expected_message = '\'{}\' does not match \'^[A-Za-z0-9/.:-]*$\''.format(invalid_names[t]['name'])
474+ expected_message = 'Additional properties are not allowed (\'{}\' was unexpected)'.format(t)
475 self.assertEqual(raised.exception.message, expected_message, msg=data)
476
477 def test_invalid_service_names(self):
478 invalid_names = {
479- '#': {'name': 'qwe#rty', 'start': '1'},
480- '_': {'name': 'qwe_rty', 'start': '1'},
481- 'space': {'name': 'qwe rty', 'start': '1'},
482- 'spaces': {'name': 'qwe rty', 'start': '1'},
483+ 'qwe#rty': {'start': '1'},
484+ 'qwe_rty': {'start': '1'},
485+ 'que_rty': {'start': '1'},
486+ 'quer ty': {'start': '1'},
487 }
488
489 for t in invalid_names:
490 data = self.data.copy()
491 with self.subTest(key=t):
492- data['services'] = [invalid_names[t]]
493+ data['services'] = {t: invalid_names[t]}
494
495 with self.assertRaises(snapcraft.yaml.SnapcraftSchemaError) as raised:
496 snapcraft.yaml._validate_snapcraft_yaml(data)
497
498- expected_message = '\'{}\' does not match \'^[A-Za-z0-9/.:-]*$\''.format(invalid_names[t]['name'])
499+ expected_message = 'Additional properties are not allowed (\'{}\' was unexpected)'.format(t)
500 self.assertEqual(raised.exception.message, expected_message, msg=data)
501
502 def test_services_required_properties(self):
503- self.data['services'] = [
504- {
505- 'start': 'binary1 start',
506- }
507- ]
508+ self.data['services'] = {'service1': {}}
509
510 with self.assertRaises(snapcraft.yaml.SnapcraftSchemaError) as raised:
511 snapcraft.yaml._validate_snapcraft_yaml(self.data)
512
513- expected_message = '\'name\' is a required property'
514+ expected_message = '\'start\' is a required property'
515 self.assertEqual(raised.exception.message, expected_message, msg=self.data)
516
517 def test_schema_file_not_found(self):

Subscribers

People subscribed via source and target branches