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

Proposed by Sergio Schvezov on 2015-10-27
Status: Merged
Approved by: Sergio Schvezov on 2015-10-27
Approved revision: 267
Merged at revision: 254
Proposed branch: lp:~sergiusens/snapcraft/help
Merge into: lp:~snappy-dev/snapcraft/core
Diff against target: 583 lines (+376/-10)
14 files modified
snapcraft/__init__.py (+103/-9)
snapcraft/help.py (+73/-0)
snapcraft/main.py (+11/-0)
snapcraft/plugins/ant.py (+10/-0)
snapcraft/plugins/autotools.py (+20/-0)
snapcraft/plugins/catkin.py (+13/-0)
snapcraft/plugins/cmake.py (+16/-0)
snapcraft/plugins/go.py (+13/-0)
snapcraft/plugins/make.py (+10/-0)
snapcraft/plugins/maven.py (+16/-0)
snapcraft/plugins/python2.py (+20/-0)
snapcraft/plugins/python3.py (+20/-0)
snapcraft/plugins/scons.py (+15/-0)
snapcraft/sources.py (+36/-1)
To merge this branch: bzr merge lp:~sergiusens/snapcraft/help
Reviewer Review Type Date Requested Status
John Lenton 2015-10-27 Approve on 2015-10-27
Review via email: mp+275858@code.launchpad.net

Commit Message

Adding a help command to get snapcraft help from the cli.

To post a comment you must log in.
John Lenton (chipaca) wrote :

Nice work.

Loots of comments, below ... needsfixing just because they're so many.

review: Needs Fixing
John Lenton (chipaca) wrote :

Mucho bettero!
One that I didn't catch last time. But +1'ing it.

review: Approve
Snappy Tarmac (snappydevtarmac) wrote :

The attempt to merge lp:~sergiusens/snapcraft/help into lp:snapcraft failed. Below is the output from the failed tests.

snapcraft/help.py:19: 'sys' imported but unused

Snappy Tarmac (snappydevtarmac) wrote :

There are additional revisions which have not been approved in review. Please seek review and approval of these new revisions.

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-26 14:02:06 +0000
3+++ snapcraft/__init__.py 2015-10-27 20:21:51 +0000
4@@ -14,8 +14,104 @@
5 # You should have received a copy of the GNU General Public License
6 # along with this program. If not, see <http://www.gnu.org/licenses/>.
7
8+"""Plugins drive the build process for a part.
9+Each part can use an individual plugin that understands how to work with
10+the declared sources.
11+
12+These plugins have a lifecycle that consists of the following steps:
13+
14+ - pull
15+ - build
16+ - stage
17+ - snap
18+ - assemble
19+
20+# Lifecycle
21+
22+## Pull
23+This is the first step. This is where content is downloaded, e.g. checkout a
24+git repository or download a binary component like the Java SDK. Snapcraft
25+will place the downloaded content for each part in that part's
26+`parts/<part-name>/src` directory.
27+
28+## Build
29+This is the step that follows pull. Each part is built in its
30+`parts/part-name/build` directory and installs itself into
31+`parts/part-name/install`.
32+
33+## Stage
34+After the build step of each part, the parts are combined into a single
35+directory tree that is called the "staging area". It can be found
36+under the `./stage` directory.
37+
38+This is the area where all parts can share assets such as libraries to link
39+against.
40+
41+## Snap
42+The snap step moves the data into a `./snap` directory. It contains only
43+the content that will be put into the final snap package, unlike the staging
44+area which may include some development files not destined for your package.
45+
46+The Snappy metadata information about your project will also now be placed
47+in `./snap/meta`.
48+
49+This `./snap` directory is useful for inspecting what is going into your
50+snap and to make any final post-processing on snapcraft's output.
51+
52+## Assemble
53+The final step builds a snap package out of the `snap` directory.
54+
55+# Common keywords
56+
57+There are common builtin keywords provided to a snapcraft plugin which can
58+be used in any part irrespective of the plugin, these are
59+
60+ - after:
61+ (list of strings)
62+ Specifies any parts that should be built before this part is. This
63+ is mostly useful when a part needs a library or build tool built by
64+ another part.
65+ If a part listed in `after` is not defined locally, it will be
66+ searched for in the wiki (https://wiki.ubuntu.com/Snappy/Wiki)
67+ - stage-packages:
68+ (list of strings)
69+ A list of Ubuntu packages to use that are needed to support the part
70+ creation.
71+ - build-packages:
72+ (list of strings)
73+ A list of Ubuntu packages to be installed on the host to aid in
74+ building the part but not going into the final snap.
75+ - organize:
76+ (yaml subsection)
77+ A dictionary exposing replacements, the key is the internal filename
78+ whilst the value is the exposed filename, filesets will refer to the
79+ exposed named applied after organization is applied.
80+ This can be used to avoid conflicts by renaming files or using a
81+ different layout from what came out of the build, e.g.;
82+ `/usr/local/share/icon.png` -> `/usr/share/icon.png`.
83+ - filesets:
84+ (yaml subsection)
85+ A dictionary with filesets, the key being a recognizable user defined
86+ string and its value a list of filenames to be included or
87+ excluded. Globbing is achieved with * for either inclusions or
88+ exclusion. Exclusions are denoted by an initial `-`.
89+ Globbing is computed from the part's install directory in
90+ `parts/<part-name>/install`.
91+ - stage:
92+ (list of strings)
93+ A list of files from a part’s installation to expose in `stage`.
94+ Rules applying to the list here are the same as those of filesets.
95+ Referencing of fileset keys is done with a $ prefixing the fileset
96+ key, which will expand with the value of such key.
97+ - snap:
98+ (list of strings)
99+ A list of files from a part’s installation to expose in `snap`.
100+ Rules applying to the list here are the same as those of filesets.
101+ Referencing of fileset keys is done with a $ prefixing the fileset
102+ key, which will expand with the value of such key.
103+"""
104+
105 import contextlib
106-import logging
107 import os
108
109 import snapcraft.common
110@@ -23,9 +119,6 @@
111 import snapcraft.repo
112
113
114-logger = logging.getLogger(__name__)
115-
116-
117 class BasePlugin:
118
119 @classmethod
120@@ -35,8 +128,8 @@
121 optionally the 'requires' keyword with a list of required
122 'properties'.
123
124- By default the the properties will be that of a standard VCS, override
125- in custom implementations if required.
126+ By default the properties will be that of a standard VCS,
127+ override in custom implementations if required.
128 """
129 return {
130 '$schema': 'http://json-schema.org/draft-04/schema#',
131@@ -113,8 +206,8 @@
132 def build(self):
133 """Build the source code retrieved from the pull phase.
134
135- The base implementation does nothing by default. Override this method
136- if you need to process the source code to make it runnable.
137+ The base implementation does nothing by default. Override this
138+ method if you need to process the source code to make it runnable.
139 """
140 pass
141
142@@ -122,7 +215,8 @@
143 """Return a list of files to include or exclude in the resulting snap
144
145 The staging phase of a plugin's lifecycle may populate many things
146- into the staging directory in order to succeed in building a project.
147+ into the staging directory in order to succeed in building a
148+ project.
149 During the stripping phase and in order to have a clean snap, the
150 plugin can provide additional logic for stripping build components
151 from the final snap and alleviate the part author from doing so for
152
153=== added file 'snapcraft/help.py'
154--- snapcraft/help.py 1970-01-01 00:00:00 +0000
155+++ snapcraft/help.py 2015-10-27 20:21:51 +0000
156@@ -0,0 +1,73 @@
157+# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
158+#
159+# Copyright (C) 2015 Canonical Ltd
160+#
161+# This program is free software: you can redistribute it and/or modify
162+# it under the terms of the GNU General Public License version 3 as
163+# published by the Free Software Foundation.
164+#
165+# This program is distributed in the hope that it will be useful,
166+# but WITHOUT ANY WARRANTY; without even the implied warranty of
167+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
168+# GNU General Public License for more details.
169+#
170+# You should have received a copy of the GNU General Public License
171+# along with this program. If not, see <http://www.gnu.org/licenses/>.
172+
173+import importlib
174+import logging
175+
176+import snapcraft
177+from snapcraft import sources
178+from snapcraft import cmds
179+
180+
181+logger = logging.getLogger(__name__)
182+
183+
184+_TOPICS = {
185+ 'sources': sources,
186+ 'plugins': snapcraft,
187+}
188+
189+
190+def topic(args=None):
191+ """Get help on additional topics or plugin usage.
192+ snapcraft help topics To get the list of topics
193+ snapcraft help <plugin> To get help for a specific plugin
194+ snapcraft help <topic> To get help on a speficic topic
195+
196+To see the list of available plugins run
197+
198+ snapcraft list-plugins
199+"""
200+ if args.topic == 'topics':
201+ for key in _TOPICS:
202+ print(key)
203+ elif args.topic in _TOPICS:
204+ _topic_help(args.topic, args.devel)
205+ else:
206+ _module_help(args.topic, args.devel)
207+
208+
209+def _topic_help(module_name, devel):
210+ if devel:
211+ help(_TOPICS[module_name])
212+ else:
213+ print(_TOPICS[module_name].__doc__)
214+
215+
216+def _module_help(module_name, devel):
217+ try:
218+ module = importlib.import_module(
219+ 'snapcraft.plugins.{}'.format(module_name))
220+ except ImportError:
221+ logger.error('The plugin does not exist. Use one of the following:')
222+ cmds.list_plugins()
223+
224+ if module.__doc__ and devel:
225+ help(module)
226+ elif module.__doc__:
227+ print(module.__doc__)
228+ else:
229+ print('The plugin has no documentation')
230
231=== modified file 'snapcraft/main.py'
232--- snapcraft/main.py 2015-10-26 15:54:30 +0000
233+++ snapcraft/main.py 2015-10-27 20:21:51 +0000
234@@ -19,6 +19,8 @@
235 import sys
236
237 import snapcraft.cmds
238+
239+from snapcraft import help
240 from snapcraft import log
241
242
243@@ -65,6 +67,15 @@
244 help='clean up the environment (to start from scratch)')
245 parser.set_defaults(func=snapcraft.cmds.clean)
246
247+ parser = subparsers.add_parser(
248+ 'help',
249+ usage=help.topic.__doc__,
250+ help='obtain help for plugins and specific topics')
251+ parser.set_defaults(func=help.topic)
252+ parser.add_argument('topic', help='plugin name or topic to get help from')
253+ parser.add_argument('--devel', action='store_true',
254+ help='show the development help')
255+
256 parser = subparsers.add_parser('pull', help='get sources',
257 parents=[cmd_parser])
258 parser.set_defaults(func=snapcraft.cmds.cmd)
259
260=== modified file 'snapcraft/plugins/ant.py'
261--- snapcraft/plugins/ant.py 2015-10-21 20:03:15 +0000
262+++ snapcraft/plugins/ant.py 2015-10-27 20:21:51 +0000
263@@ -14,6 +14,16 @@
264 # You should have received a copy of the GNU General Public License
265 # along with this program. If not, see <http://www.gnu.org/licenses/>.
266
267+"""The ant plugin is useful for ant based parts.
268+
269+The ant build system is commonly used to build Java projects.
270+The plugin requires a build.xml in the root of the source tree.
271+
272+This plugin uses the common plugin keywords as well as those for "sources".
273+For more information check the 'plugins' topic for the former and the
274+'sources' topic for the latter.
275+"""
276+
277 import glob
278 import logging
279 import os
280
281=== modified file 'snapcraft/plugins/autotools.py'
282--- snapcraft/plugins/autotools.py 2015-10-21 20:03:15 +0000
283+++ snapcraft/plugins/autotools.py 2015-10-27 20:21:51 +0000
284@@ -14,6 +14,26 @@
285 # You should have received a copy of the GNU General Public License
286 # along with this program. If not, see <http://www.gnu.org/licenses/>.
287
288+"""The autotools plugin is used for autotools based parts.
289+
290+Autotools based projects are the ones that have the usual
291+`./configure && make && make install` instruction set.
292+
293+The plugin tries to build using ./configure first, if it is not there
294+it will run ./autogen and if autogen is not there it will run autoreconf.
295+
296+This plugin uses the common plugin keywords as well as those for "sources".
297+For more information check the 'plugins' topic for the former and the
298+'sources' topic for the latter.
299+
300+In additon, this plugin uses the following plugin specific keywords:
301+
302+ - configflags:
303+ (list of strings)
304+ configure flags to pass to the build such as those shown by running
305+ './configure --help'
306+"""
307+
308 import os
309 from snapcraft.plugins.make import MakePlugin
310
311
312=== modified file 'snapcraft/plugins/catkin.py'
313--- snapcraft/plugins/catkin.py 2015-10-21 20:03:15 +0000
314+++ snapcraft/plugins/catkin.py 2015-10-27 20:21:51 +0000
315@@ -14,6 +14,19 @@
316 # You should have received a copy of the GNU General Public License
317 # along with this program. If not, see <http://www.gnu.org/licenses/>.
318
319+"""The catkin plugin is useful for building ROS parts.
320+
321+This plugin uses the common plugin keywords as well as those for "sources".
322+For more information check the 'plugins' topic for the former and the
323+'sources' topic for the latter.
324+
325+Additionally, this plugin uses the following plugin specific keywords:
326+
327+ - catkin-packages:
328+ (list of strings)
329+ List of catkin packages to build.
330+"""
331+
332 import lxml.etree
333 import os
334 import tempfile
335
336=== modified file 'snapcraft/plugins/cmake.py'
337--- snapcraft/plugins/cmake.py 2015-10-21 20:03:15 +0000
338+++ snapcraft/plugins/cmake.py 2015-10-27 20:21:51 +0000
339@@ -14,6 +14,22 @@
340 # You should have received a copy of the GNU General Public License
341 # along with this program. If not, see <http://www.gnu.org/licenses/>.
342
343+"""The cmake plugin is useful for building cmake based parts.
344+
345+These are projects that have a CMakeLists.txt that drives the build.
346+The plugin requires a CMakeLists.txt in the root of the source tree.
347+
348+This plugin uses the common plugin keywords as well as those for "sources".
349+For more information check the 'plugins' topic for the former and the
350+'sources' topic for the latter.
351+
352+Additionally, this plugin uses the following plugin specific keywords:
353+
354+ - configflags:
355+ (list of strings)
356+ configure flags to pass to the build using the common cmake semantics.
357+"""
358+
359 import snapcraft.plugins.make
360
361
362
363=== modified file 'snapcraft/plugins/go.py'
364--- snapcraft/plugins/go.py 2015-10-21 20:03:15 +0000
365+++ snapcraft/plugins/go.py 2015-10-27 20:21:51 +0000
366@@ -14,6 +14,19 @@
367 # You should have received a copy of the GNU General Public License
368 # along with this program. If not, see <http://www.gnu.org/licenses/>.
369
370+"""The go plugin can be used for go projects using `go get`.
371+
372+This plugin uses the common plugin keywords, for more information check the
373+'plugins' topic.
374+
375+Additionally, this plugin uses the following plugin specific keywords:
376+
377+ - source:
378+ (string)
379+ A path to some source tree to build in the form of something `go get`
380+ understands.
381+"""
382+
383 import os
384 import snapcraft
385
386
387=== modified file 'snapcraft/plugins/make.py'
388--- snapcraft/plugins/make.py 2015-10-21 20:03:15 +0000
389+++ snapcraft/plugins/make.py 2015-10-27 20:21:51 +0000
390@@ -14,6 +14,16 @@
391 # You should have received a copy of the GNU General Public License
392 # along with this program. If not, see <http://www.gnu.org/licenses/>.
393
394+"""The make plugin is useful for building make based parts.
395+
396+Make based projects are projects that have a Makefile that drives the
397+build.
398+
399+This plugin uses the common plugin keywords as well as those for "sources".
400+For more information check the 'plugins' topic for the former and the
401+'sources' topic for the latter.
402+"""
403+
404 import snapcraft
405
406
407
408=== modified file 'snapcraft/plugins/maven.py'
409--- snapcraft/plugins/maven.py 2015-10-21 20:03:15 +0000
410+++ snapcraft/plugins/maven.py 2015-10-27 20:21:51 +0000
411@@ -14,6 +14,22 @@
412 # You should have received a copy of the GNU General Public License
413 # along with this program. If not, see <http://www.gnu.org/licenses/>.
414
415+"""This plugin is useful for building parts that use maven.
416+
417+The maven build system is commonly used to build Java projects.
418+The plugin requires a pom.xml in the root of the source tree.
419+
420+This plugin uses the common plugin keywords as well as those for "sources".
421+For more information check the 'plugins' topic for the former and the
422+'sources' topic for the latter.
423+
424+Additionally, this plugin uses the following plugin specific keywords:
425+
426+ - maven-options:
427+ (list of strings)
428+ flags to pass to the build using the maven semantics for parameters.
429+"""
430+
431 import glob
432 import logging
433 import os
434
435=== modified file 'snapcraft/plugins/python2.py'
436--- snapcraft/plugins/python2.py 2015-10-21 20:03:15 +0000
437+++ snapcraft/plugins/python2.py 2015-10-27 20:21:51 +0000
438@@ -14,6 +14,26 @@
439 # You should have received a copy of the GNU General Public License
440 # along with this program. If not, see <http://www.gnu.org/licenses/>.
441
442+"""The python2 plugin can be used for python 2 based parts.
443+
444+The python2 plugin can be used for python 2 projects where you would
445+want to do:
446+
447+ - import python modules with a requirements.txt
448+ - build a python project that has a setup.py
449+ - install sources straight from pip
450+
451+This plugin uses the common plugin keywords as well as those for "sources".
452+For more information check the 'plugins' topic for the former and the
453+'sources' topic for the latter.
454+
455+Additionally, this plugin uses the following plugin specific keywords:
456+
457+ - requirements:
458+ (string)
459+ path to a requirements.txt file
460+"""
461+
462 import os
463 import tempfile
464
465
466=== modified file 'snapcraft/plugins/python3.py'
467--- snapcraft/plugins/python3.py 2015-10-21 20:03:15 +0000
468+++ snapcraft/plugins/python3.py 2015-10-27 20:21:51 +0000
469@@ -14,6 +14,26 @@
470 # You should have received a copy of the GNU General Public License
471 # along with this program. If not, see <http://www.gnu.org/licenses/>.
472
473+"""The python3 plugin can be used for python 3 based parts.
474+
475+The python3 plugin can be used for python 3 projects where you would
476+want to do:
477+
478+ - import python modules with a requirements.txt
479+ - build a python project that has a setup.py
480+ - install sources straight from pip
481+
482+This plugin uses the common plugin keywords as well as those for "sources".
483+For more information check the 'plugins' topic for the former and the
484+'sources' topic for the latter.
485+
486+Additionally, this plugin uses the following plugin specific keywords:
487+
488+ - requirements:
489+ (string)
490+ path to a requirements.txt file
491+"""
492+
493 import os
494 import tempfile
495
496
497=== modified file 'snapcraft/plugins/scons.py'
498--- snapcraft/plugins/scons.py 2015-10-21 20:03:15 +0000
499+++ snapcraft/plugins/scons.py 2015-10-27 20:21:51 +0000
500@@ -14,6 +14,21 @@
501 # You should have received a copy of the GNU General Public License
502 # along with this program. If not, see <http://www.gnu.org/licenses/>.
503
504+"""The scons plugin is useful for building parts that build with scons.
505+
506+These are projects that have a SConstruct that drives the build.
507+
508+This plugin uses the common plugin keywords as well as those for "sources".
509+For more information check the 'plugins' topic for the former and the
510+'sources' topic for the latter.
511+
512+Additionally, this plugin uses the following plugin specific keywords:
513+
514+ - scons-options:
515+ (list of strings)
516+ flags to pass to the build using the scons semantics for parameters.
517+"""
518+
519 import os
520
521 import snapcraft
522
523=== modified file 'snapcraft/sources.py'
524--- snapcraft/sources.py 2015-10-21 20:03:15 +0000
525+++ snapcraft/sources.py 2015-10-27 20:21:51 +0000
526@@ -14,6 +14,36 @@
527 # You should have received a copy of the GNU General Public License
528 # along with this program. If not, see <http://www.gnu.org/licenses/>.
529
530+"""Common keywords for plugins that use common source options.
531+
532+A part that uses common source options can have these keyword entries:
533+
534+ - source:
535+ (string)
536+ A path to some source tree to build. It can be either remote or local,
537+ and either a directory tree or a tarball.
538+ - source-type:
539+ (string)
540+ In some cases the source is not enough to identify the version control
541+ system or compression algorithim. This hints the system into what to
542+ do, the valid values are:
543+
544+ - bzr
545+ - mercurial
546+ - hg
547+ - git
548+ - tar
549+
550+ - source-branch:
551+ (string)
552+ A specific branch from the source tree. This will result in an error
553+ if used with a bazaar source type.
554+ - source-tag:
555+ (string)
556+ A specific tag from the source tree.
557+"""
558+
559+
560 import logging
561 import os
562 import os.path
563@@ -25,7 +55,6 @@
564 import snapcraft.common
565
566
567-logger = logging.getLogger(__name__)
568 logging.getLogger('urllib3').setLevel(logging.CRITICAL)
569
570
571@@ -225,6 +254,12 @@
572
573
574 def get(sourcedir, builddir, options):
575+ """Populate sourcedir and builddir from parameters defined in options.
576+
577+ :param str sourcedir: The source directory to use.
578+ :param str builddir: The build directory to use.
579+ :param options: source options.
580+ """
581 source_type = getattr(options, 'source_type', None)
582 source_tag = getattr(options, 'source_tag', None)
583 source_branch = getattr(options, 'source_branch', None)

Subscribers

People subscribed via source and target branches