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

Proposed by Sergio Schvezov
Status: Merged
Approved by: Leo Arias
Approved revision: 254
Merged at revision: 252
Proposed branch: lp:~sergiusens/snapcraft/1481122
Merge into: lp:~snappy-dev/snapcraft/core
Diff against target: 1075 lines (+146/-292)
25 files modified
snapcraft/__init__.py (+3/-15)
snapcraft/cmds.py (+9/-5)
snapcraft/common.py (+1/-1)
snapcraft/lifecycle.py (+9/-36)
snapcraft/meta.py (+2/-5)
snapcraft/plugins/ant.py (+4/-8)
snapcraft/plugins/autotools.py (+6/-7)
snapcraft/plugins/catkin.py (+12/-34)
snapcraft/plugins/cmake.py (+3/-2)
snapcraft/plugins/copy.py (+4/-10)
snapcraft/plugins/go.py (+7/-9)
snapcraft/plugins/make.py (+2/-2)
snapcraft/plugins/maven.py (+4/-10)
snapcraft/plugins/python2.py (+11/-17)
snapcraft/plugins/python3.py (+11/-17)
snapcraft/plugins/qml.py (+2/-3)
snapcraft/plugins/roscore.py (+0/-1)
snapcraft/plugins/scons.py (+2/-3)
snapcraft/plugins/tar_content.py (+2/-2)
snapcraft/sources.py (+12/-18)
snapcraft/tests/test_base_plugin.py (+19/-41)
snapcraft/tests/test_copy_plugin.py (+7/-9)
snapcraft/tests/test_lifecycle.py (+8/-35)
snapcraft/tests/test_meta.py (+4/-0)
snapcraft/tests/test_sources.py (+2/-2)
To merge this branch: bzr merge lp:~sergiusens/snapcraft/1481122
Reviewer Review Type Date Requested Status
Leo Arias (community) Approve
Review via email: mp+275237@code.launchpad.net

Commit message

Plugins raise exception instead of true/false

To post a comment you must log in.
lp:~sergiusens/snapcraft/1481122 updated
252. By Sergio Schvezov

Move lifecycle exception handling to not lose data (__str__())

Revision history for this message
Leo Arias (elopio) wrote :

Just one needs information because I don't understand one of the changes.

I love the rest, thanks a lot!

review: Needs Information
lp:~sergiusens/snapcraft/1481122 updated
253. By Sergio Schvezov

Improve the base plugin's pull logic

254. By Sergio Schvezov

Reverting a rogue change

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

land!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'snapcraft/__init__.py'
2--- snapcraft/__init__.py 2015-10-19 19:00:55 +0000
3+++ snapcraft/__init__.py 2015-10-26 14:06:39 +0000
4@@ -106,21 +106,9 @@
5 Override or inherit from this method if you need to implement or
6 enhance with custom pull logic.
7 """
8- if not getattr(self.options, 'source', None):
9- return True
10- try:
11- return snapcraft.sources.get(
12+ if getattr(self.options, 'source', None):
13+ snapcraft.sources.get(
14 self.sourcedir, self.builddir, self.options)
15- except ValueError as e:
16- logger.error('Unrecognized source %r for part %r: %s.',
17- self.options.source, self.name, e)
18- snapcraft.common.fatal()
19- except snapcraft.sources.IncompatibleOptionsError as e:
20- logger.error(
21- 'Issues while setting up sources for part \'%s\': %s.',
22- self.name,
23- e.message)
24- snapcraft.common.fatal()
25
26 def build(self):
27 """Build the source code retrieved from the pull phase.
28@@ -128,7 +116,7 @@
29 The base implementation does nothing by default. Override this method
30 if you need to process the source code to make it runnable.
31 """
32- return True
33+ pass
34
35 def snap_fileset(self):
36 """Return a list of files to include or exclude in the resulting snap
37
38=== modified file 'snapcraft/cmds.py'
39--- snapcraft/cmds.py 2015-10-20 13:49:11 +0000
40+++ snapcraft/cmds.py 2015-10-26 14:06:39 +0000
41@@ -26,9 +26,9 @@
42 import tempfile
43 import time
44
45-import snapcraft.lifecycle
46 import snapcraft.yaml
47 from snapcraft import common
48+from snapcraft import lifecycle
49 from snapcraft import meta
50
51 logger = logging.getLogger(__name__)
52@@ -55,7 +55,7 @@
53 if args.part:
54 yaml += 'parts:\n'
55 for part_name in args.part:
56- part = snapcraft.lifecycle.load_plugin(part_name, part_name)
57+ part = lifecycle.load_plugin(part_name, part_name)
58 yaml += ' ' + part.name + ':\n'
59 for opt in part.config.get('options', []):
60 if part.config['options'][opt].get('required', False):
61@@ -264,7 +264,7 @@
62 for part in parts:
63 # Gather our own files up
64 fileset = getattr(part.code.options, 'stage', ['*']) or ['*']
65- part_files, _ = snapcraft.lifecycle.migratable_filesets(
66+ part_files, _ = lifecycle.migratable_filesets(
67 fileset,
68 part.installdir)
69
70@@ -335,8 +335,10 @@
71 common.env = config.build_env_for_part(part)
72 force = forceAll or cmd == forceCommand
73
74- if not getattr(part, cmd)(force=force):
75- logger.error('Failed doing %s for %s!', cmd, part.name)
76+ try:
77+ getattr(part, cmd)(force=force)
78+ except Exception as e:
79+ logger.error('Failed doing %s for %s: %s', cmd, part.name, e)
80 sys.exit(1)
81
82
83@@ -393,3 +395,5 @@
84 logger.error('Issue detected while analyzing '
85 'snapcraft.yaml: {}'.format(e.message))
86 sys.exit(1)
87+ except lifecycle.PluginError as e:
88+ logger.error('Issue while loading plugin: {}'.format(e))
89
90=== modified file 'snapcraft/common.py'
91--- snapcraft/common.py 2015-10-05 18:24:04 +0000
92+++ snapcraft/common.py 2015-10-26 14:06:39 +0000
93@@ -46,7 +46,7 @@
94 f.write('\n')
95 f.write('exec $*')
96 f.flush()
97- return subprocess.call(['/bin/sh', f.name] + cmd, **kwargs) == 0
98+ subprocess.check_call(['/bin/sh', f.name] + cmd, **kwargs)
99
100
101 def run_output(cmd, **kwargs):
102
103=== modified file 'snapcraft/lifecycle.py'
104--- snapcraft/lifecycle.py 2015-10-19 20:42:36 +0000
105+++ snapcraft/lifecycle.py 2015-10-26 14:06:39 +0000
106@@ -25,7 +25,6 @@
107
108 import snapcraft
109 from snapcraft import common
110-from snapcraft import repo
111
112
113 logger = logging.getLogger(__name__)
114@@ -64,15 +63,9 @@
115
116 try:
117 self._load_code(plugin_name, properties)
118- # only set to valid if it loads without PluginError
119- self.valid = True
120- except PluginError as e:
121- logger.error(str(e))
122- return
123 except jsonschema.ValidationError as e:
124- logger.error('Issues while loading properties for '
125- '{}: {}'.format(part_name, e.message))
126- return
127+ raise PluginError('properties failed to load for {}: {}'.format(
128+ part_name, e.message))
129
130 def _load_code(self, plugin_name, properties):
131 module_name = plugin_name.replace('-', '_')
132@@ -92,7 +85,7 @@
133 with contextlib.suppress(ImportError):
134 module = _load_local(module_name)
135 if not module:
136- raise PluginError('Unknown plugin: {}'.format(plugin_name))
137+ raise PluginError('unknown plugin: {}'.format(plugin_name))
138
139 plugin = _get_plugin(module)
140 options = _make_options(properties, plugin.schema())
141@@ -112,9 +105,6 @@
142 for d in dirs:
143 os.makedirs(d, exist_ok=True)
144
145- def is_valid(self):
146- return self.valid
147-
148 def notify_stage(self, stage, hint=''):
149 logger.info('%s %s %s', stage, self.name, hint)
150
151@@ -146,33 +136,20 @@
152
153 def pull(self, force=False):
154 if not self.should_stage_run('pull', force):
155- return True
156+ return
157 self.makedirs()
158-
159 self.notify_stage("Pulling")
160-
161- try:
162- self._setup_stage_packages()
163- except repo.PackageNotFoundError as e:
164- logger.error(e.message)
165- return False
166-
167- if not self.code.pull():
168- return False
169-
170+ self._setup_stage_packages()
171+ self.code.pull()
172 self.mark_done('pull')
173- return True
174
175 def build(self, force=False):
176 if not self.should_stage_run('build', force):
177- return True
178+ return
179 self.makedirs()
180 self.notify_stage("Building")
181- if not self.code.build():
182- return False
183-
184+ self.code.build()
185 self.mark_done('build')
186- return True
187
188 def _migratable_fileset_for(self, stage):
189 plugin_fileset = self.code.snap_fileset()
190@@ -294,11 +271,7 @@
191
192
193 def load_plugin(part_name, plugin_name, properties={}):
194- part = PluginHandler(plugin_name, part_name, properties)
195- if not part.is_valid():
196- logger.error('Could not load part %s', plugin_name)
197- sys.exit(1)
198- return part
199+ return PluginHandler(plugin_name, part_name, properties)
200
201
202 def migratable_filesets(fileset, srcdir):
203
204=== modified file 'snapcraft/meta.py'
205--- snapcraft/meta.py 2015-10-14 21:42:35 +0000
206+++ snapcraft/meta.py 2015-10-26 14:06:39 +0000
207@@ -216,11 +216,8 @@
208 'which "{}"\n'.format(relexepath))
209 tempf.write(script)
210 tempf.flush()
211- if common.run(['/bin/sh', tempf.name], cwd=snap_dir):
212- wrapexec = relexepath
213- else:
214- logger.warning('Warning: unable to find "{}" in the path'.
215- format(relexepath))
216+ common.run(['/bin/sh', tempf.name], cwd=snap_dir)
217+ wrapexec = relexepath
218
219 _write_wrap_exe(wrapexec, wrappath)
220
221
222=== modified file 'snapcraft/plugins/ant.py'
223--- snapcraft/plugins/ant.py 2015-10-17 02:25:13 +0000
224+++ snapcraft/plugins/ant.py 2015-10-26 14:06:39 +0000
225@@ -17,7 +17,6 @@
226 import glob
227 import logging
228 import os
229-import sys
230
231 import snapcraft
232 import snapcraft.common
233@@ -35,16 +34,13 @@
234
235 def build(self):
236 super().build()
237- if not self.run(['ant']):
238- return False
239+ self.run(['ant'])
240 files = glob.glob(os.path.join(self.builddir, 'target', '*.jar'))
241 if not files:
242- logger.error('Could not find any built jar files for part %s',
243- self.name)
244- sys.exit(1)
245+ raise RuntimeError('could not find any built jar files for part')
246 jardir = os.path.join(self.installdir, 'jar')
247- return self.run(['mkdir', '-p', jardir]) and \
248- self.run(['cp', '-a'] + files + [jardir])
249+ self.run(['mkdir', '-p', jardir])
250+ self.run(['cp', '-a'] + files + [jardir])
251
252 def env(self, root):
253 env = super().env(root)
254
255=== modified file 'snapcraft/plugins/autotools.py'
256--- snapcraft/plugins/autotools.py 2015-10-19 16:00:59 +0000
257+++ snapcraft/plugins/autotools.py 2015-10-26 14:06:39 +0000
258@@ -47,11 +47,10 @@
259 def build(self):
260 if not os.path.exists(os.path.join(self.builddir, "configure")):
261 if os.path.exists(os.path.join(self.builddir, "autogen.sh")):
262- if not self.run(['env', 'NOCONFIGURE=1', './autogen.sh'],
263- cwd=self.builddir):
264- return False
265+ self.run(['env', 'NOCONFIGURE=1', './autogen.sh'],
266+ cwd=self.builddir)
267 else:
268- if not self.run(['autoreconf', '-i'], cwd=self.builddir):
269- return False
270- return self.run(['./configure', '--prefix='] +
271- self.options.configflags) and super().build()
272+ self.run(['autoreconf', '-i'], cwd=self.builddir)
273+ self.run(['./configure', '--prefix='] +
274+ self.options.configflags)
275+ super().build()
276
277=== modified file 'snapcraft/plugins/catkin.py'
278--- snapcraft/plugins/catkin.py 2015-10-17 02:25:13 +0000
279+++ snapcraft/plugins/catkin.py 2015-10-26 14:06:39 +0000
280@@ -65,16 +65,8 @@
281 self._deb_packages = []
282
283 def pull(self):
284- if not super().pull():
285- return False
286-
287- try:
288- self._setup_deb_packages()
289- except snapcraft.repo.PackageNotFoundError as e:
290- logger.error(e.message)
291- return False
292-
293- return True
294+ super().pull()
295+ self._setup_deb_packages()
296
297 def env(self, root):
298 return [
299@@ -186,41 +178,34 @@
300 f.write('exec {}\n'.format(' '.join(commandlist)))
301 f.flush()
302
303- return self.run(['/bin/bash', f.name], cwd=cwd)
304+ self.run(['/bin/bash', f.name], cwd=cwd)
305
306 def build(self):
307 # Fixup ROS Cmake files that have hardcoded paths in them
308- if not self.run([
309+ self.run([
310 'find', self.rosdir, '-name', '*.cmake',
311 '-exec', 'sed', '-i', '-e',
312 r's|\(\W\)/usr/lib/|\1{0}/usr/lib/|g'.format(self.installdir),
313 '{}', ';'
314- ]):
315- return False
316+ ])
317
318 self._find_package_deps()
319-
320- if not self._build_packages_deps():
321- return False
322+ self._build_packages_deps()
323
324 # the hacks
325 findcmd = ['find', self.installdir, '-name', '*.cmake', '-delete']
326- if not self.run(findcmd):
327- return False
328+ self.run(findcmd)
329
330- if not self.run(
331+ self.run(
332 ['rm', '-f',
333 'opt/ros/' + self.options.rosversion + '/.catkin',
334 'opt/ros/' + self.options.rosversion + '/.rosinstall',
335 'opt/ros/' + self.options.rosversion + '/setup.sh',
336 'opt/ros/' + self.options.rosversion + '/_setup_util.py'],
337- cwd=self.installdir):
338- return False
339+ cwd=self.installdir)
340
341 os.remove(os.path.join(self.installdir, 'usr/bin/xml2-config'))
342
343- return True
344-
345 def _build_packages_deps(self):
346 # Ugly dependency resolution, just loop through until we can
347 # find something to build. When we do, build it. Loop until we
348@@ -233,17 +218,13 @@
349 for pkg in self.packages - built:
350 if len(self.package_local_deps[pkg] - built) > 0:
351 continue
352-
353- if not self._handle_package(pkg):
354- return False
355+ self._handle_package(pkg)
356
357 built.add(pkg)
358 built_pkg = True
359
360 if not built_pkg:
361- return False
362-
363- return True
364+ raise RuntimeError('some packages failed to build')
365
366 def _handle_package(self, pkg):
367 catkincmd = ['catkin_make_isolated']
368@@ -278,7 +259,4 @@
369 os.path.join(self.installdir, 'usr', 'bin', 'g++'))
370 ])
371
372- if not self._rosrun(catkincmd):
373- return False
374-
375- return True
376+ self._rosrun(catkincmd)
377
378=== modified file 'snapcraft/plugins/cmake.py'
379--- snapcraft/plugins/cmake.py 2015-10-09 17:43:20 +0000
380+++ snapcraft/plugins/cmake.py 2015-10-26 14:06:39 +0000
381@@ -39,5 +39,6 @@
382 self.build_packages.append('cmake')
383
384 def build(self):
385- return self.run(['cmake', '.', '-DCMAKE_INSTALL_PREFIX='] +
386- self.options.configflags) and super().build()
387+ self.run(['cmake', '.', '-DCMAKE_INSTALL_PREFIX='] +
388+ self.options.configflags)
389+ super().build()
390
391=== modified file 'snapcraft/plugins/copy.py'
392--- snapcraft/plugins/copy.py 2015-10-09 17:43:20 +0000
393+++ snapcraft/plugins/copy.py 2015-10-26 14:06:39 +0000
394@@ -39,17 +39,11 @@
395 }
396
397 def build(self):
398- res = True
399 for src in sorted(self.options.files):
400 dst = self.options.files[src]
401 if not os.path.lexists(src):
402- logger.warning("WARNING: file '%s' missing", src)
403- res = False
404- continue
405+ raise EnvironmentError('file "{}" missing'.format(src))
406 dst = os.path.join(self.installdir, dst)
407- dst_dir = os.path.dirname(dst)
408- if not os.path.exists(dst_dir):
409- os.makedirs(dst_dir)
410- res &= self.run(["cp", "--preserve=all", "-R", src, dst],
411- cwd=os.getcwd())
412- return res
413+ os.makedirs(os.path.dirname(dst), exist_ok=True)
414+ self.run(["cp", "--preserve=all", "-R", src, dst],
415+ cwd=os.getcwd())
416
417=== modified file 'snapcraft/plugins/go.py'
418--- snapcraft/plugins/go.py 2015-10-09 17:43:20 +0000
419+++ snapcraft/plugins/go.py 2015-10-26 14:06:39 +0000
420@@ -51,16 +51,14 @@
421 def pull(self):
422 # use -d to only download (build will happen later)
423 # use -t to also get the test-deps
424- return self.run(['go', 'get', '-t', '-d', self.fullname])
425+ self._run(['go', 'get', '-t', '-d', self.fullname])
426
427 def build(self):
428- if not self.run(['go', 'build', self.fullname]):
429- return False
430- if not self.run(['go', 'install', self.fullname]):
431- return False
432- return self.run(['cp', '-a', os.path.join(self.builddir, 'bin'),
433- self.installdir])
434+ self._run(['go', 'build', self.fullname])
435+ self._run(['go', 'install', self.fullname])
436+ self._run(['cp', '-a', os.path.join(self.builddir, 'bin'),
437+ self.installdir])
438
439- def run(self, cmd, **kwargs):
440+ def _run(self, cmd, **kwargs):
441 cmd = ['env', 'GOPATH=' + self.builddir] + cmd
442- return super().run(cmd, **kwargs)
443+ return self.run(cmd, **kwargs)
444
445=== modified file 'snapcraft/plugins/make.py'
446--- snapcraft/plugins/make.py 2015-10-17 02:25:13 +0000
447+++ snapcraft/plugins/make.py 2015-10-26 14:06:39 +0000
448@@ -24,5 +24,5 @@
449 self.build_packages.append('make')
450
451 def build(self):
452- return self.run(['make']) and \
453- self.run(['make', 'install', 'DESTDIR=' + self.installdir])
454+ self.run(['make'])
455+ self.run(['make', 'install', 'DESTDIR=' + self.installdir])
456
457=== modified file 'snapcraft/plugins/maven.py'
458--- snapcraft/plugins/maven.py 2015-10-19 23:44:27 +0000
459+++ snapcraft/plugins/maven.py 2015-10-26 14:06:39 +0000
460@@ -50,22 +50,16 @@
461 def build(self):
462 super().build()
463
464- if not self.run(['mvn', 'package'] + self.options.maven_options):
465- return False
466+ self.run(['mvn', 'package'] + self.options.maven_options)
467 jarfiles = glob.glob(os.path.join(self.builddir, 'target', '*.jar'))
468 warfiles = glob.glob(os.path.join(self.builddir, 'target', '*.war'))
469 if not (jarfiles or warfiles):
470- logger.error('Could not find any built jar or war files for '
471- 'part %s', self.name)
472- snapcraft.common.fatal()
473+ raise RuntimeError('could not find any built jar files for part')
474 if jarfiles:
475 jardir = os.path.join(self.installdir, 'jar')
476 os.makedirs(jardir, exist_ok=True)
477- if not self.run(['cp', '-a'] + jarfiles + [jardir]):
478- return False
479+ self.run(['cp', '-a'] + jarfiles + [jardir])
480 if warfiles:
481 wardir = os.path.join(self.installdir, 'war')
482 os.makedirs(wardir, exist_ok=True)
483- if not self.run(['cp', '-a'] + warfiles + [wardir]):
484- return False
485- return True
486+ self.run(['cp', '-a'] + warfiles + [wardir])
487
488=== modified file 'snapcraft/plugins/python2.py'
489--- snapcraft/plugins/python2.py 2015-10-17 02:25:13 +0000
490+++ snapcraft/plugins/python2.py 2015-10-26 14:06:39 +0000
491@@ -45,10 +45,8 @@
492 root, 'usr', 'lib', self.python_version, 'dist-packages')]
493
494 def pull(self):
495- if not super().pull():
496- return False
497-
498- return self._pip()
499+ super().pull()
500+ self._pip()
501
502 def _pip(self):
503 setup = 'setup.py'
504@@ -59,7 +57,7 @@
505 requirements = os.path.join(os.getcwd(), self.options.requirements)
506
507 if not os.path.exists(setup) and not self.options.requirements:
508- return True
509+ return
510
511 easy_install = os.path.join(
512 self.installdir, 'usr', 'bin', 'easy_install')
513@@ -73,21 +71,17 @@
514 'dist-packages'),
515 site_packages_dir)
516
517- if not self.run(['python2', easy_install, '--prefix', prefix, 'pip']):
518- return False
519+ self.run(['python2', easy_install, '--prefix', prefix, 'pip'])
520
521 pip2 = os.path.join(self.installdir, 'usr', 'bin', 'pip2')
522 pip_install = ['python2', pip2, 'install', '--target',
523 site_packages_dir]
524
525- if self.options.requirements and not self.run(
526- pip_install + ['--requirement', requirements]):
527- return False
528-
529- if os.path.exists(setup) and not self.run(pip_install + ['.', ]):
530- return False
531-
532- return True
533+ if self.options.requirements:
534+ self.run(pip_install + ['--requirement', requirements])
535+
536+ if os.path.exists(setup):
537+ self.run(pip_install + ['.', ])
538
539 def build(self):
540 # If setuptools is used, it tries to create files in the
541@@ -96,11 +90,11 @@
542 # used.
543
544 if not os.path.exists(os.path.join(self.builddir, 'setup.py')):
545- return True
546+ return
547
548 os.makedirs(self.dist_packages_dir, exist_ok=True)
549 setuptemp = self.copy_setup()
550- return self.run(
551+ self.run(
552 ['python2', setuptemp.name, 'install', '--install-layout=deb',
553 '--prefix={}/usr'.format(self.installdir)], cwd=self.builddir)
554
555
556=== modified file 'snapcraft/plugins/python3.py'
557--- snapcraft/plugins/python3.py 2015-10-17 02:25:13 +0000
558+++ snapcraft/plugins/python3.py 2015-10-26 14:06:39 +0000
559@@ -45,10 +45,8 @@
560 root, 'usr', 'lib', self.python_version, 'dist-packages')]
561
562 def pull(self):
563- if not super().pull():
564- return False
565-
566- return self._pip()
567+ super().pull()
568+ self._pip()
569
570 def _pip(self):
571 setup = 'setup.py'
572@@ -59,7 +57,7 @@
573 requirements = os.path.join(os.getcwd(), self.options.requirements)
574
575 if not os.path.exists(setup) and not self.options.requirements:
576- return True
577+ return
578
579 easy_install = os.path.join(
580 self.installdir, 'usr', 'bin', 'easy_install3')
581@@ -72,21 +70,17 @@
582 os.path.join(prefix, 'lib', 'python3', 'dist-packages'),
583 site_packages_dir)
584
585- if not self.run(['python3', easy_install, '--prefix', prefix, 'pip']):
586- return False
587+ self.run(['python3', easy_install, '--prefix', prefix, 'pip'])
588
589 pip3 = os.path.join(self.installdir, 'usr', 'bin', 'pip3')
590 pip_install = ['python3', pip3, 'install', '--target',
591 site_packages_dir]
592
593- if self.options.requirements and not self.run(
594- pip_install + ['--requirement', requirements]):
595- return False
596-
597- if os.path.exists(setup) and not self.run(pip_install + ['.', ]):
598- return False
599-
600- return True
601+ if self.options.requirements:
602+ self.run(pip_install + ['--requirement', requirements])
603+
604+ if os.path.exists(setup):
605+ self.run(pip_install + ['.', ])
606
607 def build(self):
608 # If setuptools is used, it tries to create files in the
609@@ -95,11 +89,11 @@
610 # used.
611
612 if not os.path.exists(os.path.join(self.builddir, 'setup.py')):
613- return True
614+ return
615
616 os.makedirs(self.dist_packages_dir, exist_ok=True)
617 setuptemp = self.copy_setup()
618- return self.run(
619+ self.run(
620 ['python3', setuptemp.name, 'install', '--install-layout=deb',
621 '--prefix={}/usr'.format(self.installdir)], cwd=self.builddir)
622
623
624=== modified file 'snapcraft/plugins/qml.py'
625--- snapcraft/plugins/qml.py 2015-10-09 17:43:20 +0000
626+++ snapcraft/plugins/qml.py 2015-10-26 14:06:39 +0000
627@@ -68,7 +68,7 @@
628 'etc/xdg/qtchooser/snappy-qt5.conf',
629 ]
630
631- def build_qt_config(self):
632+ def _build_qt_config(self):
633 arch = snapcraft.common.get_arch_triplet()
634 configdir = os.path.join(self.installdir, 'etc', 'xdg', 'qtchooser')
635 os.makedirs(configdir, exist_ok=True)
636@@ -76,10 +76,9 @@
637 config.write('./usr/lib/{}/qt5/bin\n'.format(arch))
638 config.write('./usr/lib/{}\n'.format(arch))
639 config.close
640- return True
641
642 def build(self):
643- return self.build_qt_config()
644+ self._build_qt_config()
645
646 def env(self, root):
647 arch = snapcraft.common.get_arch_triplet()
648
649=== modified file 'snapcraft/plugins/roscore.py'
650--- snapcraft/plugins/roscore.py 2015-10-16 19:05:42 +0000
651+++ snapcraft/plugins/roscore.py 2015-10-26 14:06:39 +0000
652@@ -66,7 +66,6 @@
653 f.write('exec {}/bin/rosmaster\n'.format(ros_dir))
654
655 os.chmod(service_wrapper, 0o755)
656- return True
657
658 def snap_fileset(self):
659 rospath = os.path.join('opt', 'ros', self.options.rosversion)
660
661=== modified file 'snapcraft/plugins/scons.py'
662--- snapcraft/plugins/scons.py 2015-10-17 02:25:13 +0000
663+++ snapcraft/plugins/scons.py 2015-10-26 14:06:39 +0000
664@@ -43,6 +43,5 @@
665 def build(self):
666 env = os.environ.copy()
667 env['DESTDIR'] = self.installdir
668- return (self.run(['scons', ] + self.options.scons_options) and
669- self.run(['scons', 'install'] +
670- self.options.scons_options, env=env))
671+ self.run(['scons', ] + self.options.scons_options)
672+ self.run(['scons', 'install'] + self.options.scons_options, env=env)
673
674=== modified file 'snapcraft/plugins/tar_content.py'
675--- snapcraft/plugins/tar_content.py 2015-10-09 17:43:20 +0000
676+++ snapcraft/plugins/tar_content.py 2015-10-26 14:06:39 +0000
677@@ -38,7 +38,7 @@
678 self.tar = snapcraft.sources.Tar(self.options.source, self.builddir)
679
680 def pull(self):
681- return self.tar.pull()
682+ self.tar.pull()
683
684 def build(self):
685- return self.tar.provision(self.installdir)
686+ self.tar.provision(self.installdir)
687
688=== modified file 'snapcraft/sources.py'
689--- snapcraft/sources.py 2015-10-19 18:39:31 +0000
690+++ snapcraft/sources.py 2015-10-26 14:06:39 +0000
691@@ -73,7 +73,7 @@
692 cmd = ['bzr', 'branch'] + tag_opts + \
693 [self.source, self.source_dir]
694
695- return snapcraft.common.run(cmd, cwd=os.getcwd())
696+ snapcraft.common.run(cmd, cwd=os.getcwd())
697
698
699 class Git(Base):
700@@ -102,7 +102,7 @@
701 cmd = ['git', 'clone'] + branch_opts + \
702 [self.source, self.source_dir]
703
704- return snapcraft.common.run(cmd, cwd=os.getcwd())
705+ snapcraft.common.run(cmd, cwd=os.getcwd())
706
707
708 class Mercurial(Base):
709@@ -129,7 +129,7 @@
710 ref = ['-u', self.source_tag or self.source_branch]
711 cmd = ['hg', 'clone'] + ref + [self.source, self.source_dir]
712
713- return snapcraft.common.run(cmd, cwd=os.getcwd())
714+ snapcraft.common.run(cmd, cwd=os.getcwd())
715
716
717 class Tar(Base):
718@@ -146,19 +146,18 @@
719
720 def pull(self):
721 if not snapcraft.common.isurl(self.source):
722- return True
723+ return
724
725 req = requests.get(self.source, stream=True, allow_redirects=True)
726 if req.status_code is not 200:
727- return False
728+ raise EnvironmentError('unexpected http status code when '
729+ 'downloading %r'.format(req.status_code))
730
731 file = os.path.join(self.source_dir, os.path.basename(self.source))
732 with open(file, 'wb') as f:
733 for chunk in req.iter_content(1024):
734 f.write(chunk)
735
736- return True
737-
738 def provision(self, dst, clean_target=True):
739 # TODO add unit tests.
740 if snapcraft.common.isurl(self.source):
741@@ -172,7 +171,7 @@
742 shutil.rmtree(dst)
743 os.makedirs(dst)
744
745- return self._extract(tarball, dst)
746+ self._extract(tarball, dst)
747
748 def _extract(self, tarball, dst):
749 with tarfile.open(tarball) as tar:
750@@ -208,13 +207,11 @@
751
752 tar.extractall(members=filter_members(tar), path=dst)
753
754- return True
755-
756
757 class Local(Base):
758
759 def pull(self):
760- return True
761+ pass
762
763 def provision(self, dst):
764 path = os.path.abspath(self.source)
765@@ -226,8 +223,6 @@
766 os.remove(dst)
767 os.symlink(path, dst)
768
769- return True
770-
771
772 def get(sourcedir, builddir, options):
773 source_type = getattr(options, 'source_type', None)
774@@ -237,9 +232,8 @@
775 handler_class = _get_source_handler(source_type, options.source)
776 handler = handler_class(options.source, sourcedir, source_tag,
777 source_branch)
778- if not handler.pull():
779- return False
780- return handler.provision(builddir)
781+ handler.pull()
782+ handler.provision(builddir)
783
784
785 _source_handler = {
786@@ -270,8 +264,8 @@
787 elif _tar_type_regex.match(source):
788 source_type = 'tar'
789 elif snapcraft.common.isurl(source):
790- raise ValueError('No handler to manage source')
791+ raise ValueError('no handler to manage source')
792 elif not os.path.isdir(source):
793- raise ValueError('Local source is not a directory')
794+ raise ValueError('local source is not a directory')
795
796 return source_type
797
798=== modified file 'snapcraft/tests/test_base_plugin.py'
799--- snapcraft/tests/test_base_plugin.py 2015-10-17 02:25:13 +0000
800+++ snapcraft/tests/test_base_plugin.py 2015-10-26 14:06:39 +0000
801@@ -14,11 +14,10 @@
802 # You should have received a copy of the GNU General Public License
803 # along with this program. If not, see <http://www.gnu.org/licenses/>.
804
805-import fixtures
806-import logging
807 import unittest.mock
808
809 import snapcraft
810+from snapcraft import sources
811 from snapcraft import tests
812
813
814@@ -34,38 +33,27 @@
815
816 class TestBasePlugin(tests.TestCase):
817
818- def test_get_source_with_unrecognized_source_must_raise_error(self):
819- fake_logger = fixtures.FakeLogger(level=logging.ERROR)
820- self.useFixture(fake_logger)
821-
822+ def test_get_source_with_unrecognized_source_must_raise_exception(self):
823 options = MockOptions('unrecognized://test_source')
824 plugin = snapcraft.BasePlugin('test_plugin', options)
825- with self.assertRaises(SystemExit) as raised:
826+ with self.assertRaises(ValueError) as raised:
827 plugin.pull()
828
829- self.assertEqual(raised.exception.code, 1, 'Wrong exit code returned.')
830- expected = (
831- "Unrecognized source 'unrecognized://test_source' for part "
832- "'test_plugin': No handler to manage source.\n")
833- self.assertEqual(expected, fake_logger.output)
834+ self.assertEqual(raised.exception.__str__(),
835+ 'no handler to manage source')
836
837 @unittest.mock.patch('os.path.isdir')
838- def test_local_non_dir_source_path_must_raise_error(self, mock_isdir):
839- fake_logger = fixtures.FakeLogger(level=logging.ERROR)
840- self.useFixture(fake_logger)
841-
842+ def test_local_non_dir_source_path_must_raise_exception(self, mock_isdir):
843 options = MockOptions('file')
844 mock_isdir.return_value = False
845 plugin = snapcraft.BasePlugin('test_plugin', options)
846- with self.assertRaises(SystemExit) as raised:
847+ with self.assertRaises(ValueError) as raised:
848 plugin.pull()
849
850 mock_isdir.assert_called_once_with('file')
851- self.assertEqual(raised.exception.code, 1, 'Wrong exit code returned.')
852- expected = (
853- "Unrecognized source 'file' for part 'test_plugin': "
854- "Local source is not a directory.\n")
855- self.assertEqual(expected, fake_logger.output)
856+
857+ self.assertEqual(raised.exception.__str__(),
858+ 'local source is not a directory')
859
860
861 class GetSourceWithBranches(tests.TestCase):
862@@ -84,21 +72,16 @@
863 ]
864
865 def test_get_source_with_branch_and_tag_must_raise_error(self):
866- fake_logger = fixtures.FakeLogger(level=logging.ERROR)
867- self.useFixture(fake_logger)
868-
869 options = MockOptions('lp:source', self.source_type,
870 self.source_branch, self.source_tag)
871 plugin = snapcraft.BasePlugin('test_plugin', options)
872- with self.assertRaises(SystemExit) as raised:
873+ with self.assertRaises(sources.IncompatibleOptionsError) as raised:
874 plugin.pull()
875
876- self.assertEqual(raised.exception.code, 1, 'Wrong exit code returned.')
877- expected = (
878- 'Issues while setting up sources for part \'test_plugin\': '
879+ self.assertEqual(
880+ raised.exception.__str__(),
881 'can\'t specify both source-tag and source-branch for a {} '
882- "source.\n".format(self.source_type))
883- self.assertEqual(expected, fake_logger.output)
884+ 'source'.format(self.source_type))
885
886
887 class GetSourceTestCase(tests.TestCase):
888@@ -122,19 +105,14 @@
889 ]
890
891 def test_get_source_with_branch_must_raise_error(self):
892- fake_logger = fixtures.FakeLogger(level=logging.ERROR)
893- self.useFixture(fake_logger)
894-
895 options = MockOptions('lp:this', self.source_type, self.source_branch,
896 self.source_tag)
897 plugin = snapcraft.BasePlugin('test_plugin', options)
898
899- with self.assertRaises(SystemExit) as raised:
900+ with self.assertRaises(sources.IncompatibleOptionsError) as raised:
901 plugin.pull()
902
903- self.assertEqual(raised.exception.code, 1, 'Wrong exit code returned.')
904- expected = (
905- 'Issues while setting up sources for part \'test_plugin\': can\'t '
906- 'specify a {} for a {} source.\n'
907- .format(self.error, self.source_type))
908- self.assertEqual(expected, fake_logger.output)
909+ self.assertEqual(
910+ raised.exception.__str__(),
911+ 'can\'t specify a {} for a {} source'.format(
912+ self.error, self.source_type))
913
914=== modified file 'snapcraft/tests/test_copy_plugin.py'
915--- snapcraft/tests/test_copy_plugin.py 2015-10-02 09:13:00 +0000
916+++ snapcraft/tests/test_copy_plugin.py 2015-10-26 14:06:39 +0000
917@@ -14,7 +14,6 @@
918 # You should have received a copy of the GNU General Public License
919 # along with this program. If not, see <http://www.gnu.org/licenses/>.
920
921-import logging
922 import os.path
923 from unittest.mock import Mock
924
925@@ -34,7 +33,7 @@
926 self.dst_prefix = "parts/copy/install/"
927 os.makedirs(self.dst_prefix)
928
929- def test_copy_plugin_any_missing_src_warns_and_errors(self):
930+ def test_copy_plugin_any_missing_src_raises_exception(self):
931 # ensure that a bad file causes a warning and fails the build even
932 # if there is a good file last
933 self.mock_options.files = {
934@@ -44,12 +43,11 @@
935 open("zzz", "w").close()
936 c = CopyPlugin("copy", self.mock_options)
937
938- fake_logger = fixtures.FakeLogger(level=logging.WARNING)
939- self.useFixture(fake_logger)
940+ with self.assertRaises(EnvironmentError) as raised:
941+ c.build()
942
943- res = c.build()
944- self.assertFalse(res)
945- self.assertEqual("WARNING: file 'src' missing\n", fake_logger.output)
946+ self.assertEqual(raised.exception.__str__(),
947+ 'file "src" missing')
948
949 def test_copy_plugin_copies(self):
950 self.useFixture(fixtures.FakeLogger())
951@@ -60,7 +58,7 @@
952 open("src", "w").close()
953
954 c = CopyPlugin("copy", self.mock_options)
955- self.assertTrue(c.build())
956+ c.build()
957 self.assertTrue(os.path.exists(os.path.join(self.dst_prefix, "dst")))
958
959 def test_copy_plugin_creates_prefixes(self):
960@@ -72,6 +70,6 @@
961 open("src", "w").close()
962
963 c = CopyPlugin("copy", self.mock_options)
964- self.assertTrue(c.build())
965+ c.build()
966 self.assertTrue(os.path.exists(os.path.join(self.dst_prefix,
967 "dir/dst")))
968
969=== modified file 'snapcraft/tests/test_lifecycle.py'
970--- snapcraft/tests/test_lifecycle.py 2015-10-19 20:42:36 +0000
971+++ snapcraft/tests/test_lifecycle.py 2015-10-26 14:06:39 +0000
972@@ -28,36 +28,23 @@
973 import snapcraft.tests
974
975
976-def get_test_plugin(name='mock', part_name='mock-part', properties=None):
977+def get_test_plugin(name='copy', part_name='mock-part', properties=None):
978 if properties is None:
979- properties = {}
980+ properties = {'files': {'1': '1'}}
981 return snapcraft.lifecycle.PluginHandler(name, part_name, properties)
982
983
984 class PluginTestCase(snapcraft.tests.TestCase):
985
986- def test_init_unknown_plugin_must_log_error(self):
987+ def test_init_unknown_plugin_must_raise_exception(self):
988 fake_logger = fixtures.FakeLogger(level=logging.ERROR)
989 self.useFixture(fake_logger)
990
991- get_test_plugin('test_unexisting_name')
992-
993- self.assertEqual(
994- 'Unknown plugin: test_unexisting_name\n', fake_logger.output)
995-
996- def test_is_dirty(self):
997- p = get_test_plugin()
998- p.statefile = tempfile.NamedTemporaryFile().name
999- self.addCleanup(os.remove, p.statefile)
1000- p.code = Mock()
1001- p._setup_stage_packages = Mock()
1002- # pull once
1003- p.pull()
1004- p.code.pull.assert_called()
1005- # pull again, not dirty no need to pull
1006- p.code.pull.reset_mock()
1007- p.pull()
1008- self.assertFalse(p.code.pull.called)
1009+ with self.assertRaises(snapcraft.lifecycle.PluginError) as raised:
1010+ get_test_plugin('test_unexisting_name')
1011+
1012+ self.assertEqual(raised.exception.__str__(),
1013+ 'unknown plugin: test_unexisting_name')
1014
1015 def test_fileset_include_excludes(self):
1016 stage_set = [
1017@@ -224,20 +211,6 @@
1018 self.assertEqual(
1019 "path '/abs/exclude' must be relative", str(raised.exception))
1020
1021- def test_load_plugin_with_invalid_part_must_exit_with_error(self):
1022- fake_logger = fixtures.FakeLogger(level=logging.ERROR)
1023- self.useFixture(fake_logger)
1024-
1025- with self.assertRaises(SystemExit) as raised:
1026- snapcraft.lifecycle.load_plugin(
1027- 'dummy-part', 'test_unexisting_name')
1028-
1029- self.assertEqual(raised.exception.code, 1, 'Wrong exit code returned.')
1030- self.assertEqual(
1031- 'Unknown plugin: test_unexisting_name\n'
1032- 'Could not load part test_unexisting_name\n',
1033- fake_logger.output)
1034-
1035
1036 class PluginMakedirsTestCase(snapcraft.tests.TestCase):
1037
1038
1039=== modified file 'snapcraft/tests/test_meta.py'
1040--- snapcraft/tests/test_meta.py 2015-10-02 09:13:00 +0000
1041+++ snapcraft/tests/test_meta.py 2015-10-26 14:06:39 +0000
1042@@ -334,7 +334,11 @@
1043 def test_wrap_exe_must_write_wrapper(self):
1044 snapdir = common.get_snapdir()
1045 os.mkdir(snapdir)
1046+
1047 relative_exe_path = 'test_relexepath'
1048+ with open(os.path.join(snapdir, relative_exe_path), 'w'):
1049+ pass
1050+
1051 relative_wrapper_path = meta._wrap_exe(relative_exe_path)
1052 wrapper_path = os.path.join(snapdir, relative_wrapper_path)
1053
1054
1055=== modified file 'snapcraft/tests/test_sources.py'
1056--- snapcraft/tests/test_sources.py 2015-10-17 02:25:13 +0000
1057+++ snapcraft/tests/test_sources.py 2015-10-26 14:06:39 +0000
1058@@ -59,7 +59,7 @@
1059 *server.server_address, file_name=tar_file_name)
1060 tar_source = snapcraft.sources.Tar(source, dest_dir)
1061
1062- self.assertTrue(tar_source.pull())
1063+ tar_source.pull()
1064
1065 with open(os.path.join(dest_dir, tar_file_name), 'r') as tar_file:
1066 self.assertEqual('Test fake tarball file', tar_file.read())
1067@@ -314,7 +314,7 @@
1068
1069 def test_pull(self):
1070 local = snapcraft.sources.Local('.', 'source_dir')
1071- self.assertTrue(local.pull())
1072+ local.pull()
1073
1074 def test_provision(self):
1075 local = snapcraft.sources.Local('.', 'source_dir')

Subscribers

People subscribed via source and target branches