Add node-engine to snapcraft.yaml #509

Merged
merged 16 commits into from May 26, 2016
@@ -28,6 +28,9 @@
- node-packages:
(list)
A list of dependencies to fetch using npm.
+ - node-engine:
+ (string)
+ The version of nodejs you want the snap to run on.
"""
import logging
@@ -41,7 +44,7 @@
logger = logging.getLogger(__name__)
_NODEJS_BASE = 'node-v{version}-linux-{arch}'
-_NODEJS_VERSION = '4.2.2'
+_NODEJS_VERSION = '4.4.4'
_NODEJS_TMPL = 'https://nodejs.org/dist/v{version}/{base}.tar.gz'
_NODEJS_ARCHES = {
'i686': 'x86',
@@ -63,22 +66,27 @@ def schema(cls):
'items': {
'type': 'string'
},
- 'default': [],
+ 'default': []
+ }
+ schema['properties']['node-engine'] = {
+ 'type': 'string',
+ 'default': _NODEJS_VERSION
}
if 'required' in schema:
del schema['required']
# Inform Snapcraft of the properties associated with building. If these
# change in the YAML Snapcraft will consider the build step dirty.
- schema['build-properties'].append('node-packages')
+ schema['build-properties'].extend(['node-packages', 'node-engine'])
return schema
def __init__(self, name, options, project):
super().__init__(name, options, project)
self._npm_dir = os.path.join(self.partdir, 'npm')
- self._nodejs_tar = sources.Tar(_get_nodejs_release(), self._npm_dir)
+ self._nodejs_tar = sources.Tar(_get_nodejs_release(
+ self.options.node_engine), self._npm_dir)
def pull(self):
super().pull()
@@ -102,15 +110,15 @@ def build(self):
self.run(['npm', 'install', '-g'])
-def _get_nodejs_base():
+def _get_nodejs_base(node_engine):
machine = platform.machine()
if machine not in _NODEJS_ARCHES:
raise EnvironmentError('architecture not supported ({})'.format(
machine))
- return _NODEJS_BASE.format(version=_NODEJS_VERSION,
+ return _NODEJS_BASE.format(version=node_engine,
arch=_NODEJS_ARCHES[machine])
-def _get_nodejs_release():
- return _NODEJS_TMPL.format(version=_NODEJS_VERSION,
- base=_get_nodejs_base())
+def _get_nodejs_release(node_engine):
+ return _NODEJS_TMPL.format(version=node_engine,
+ base=_get_nodejs_base(node_engine))
@@ -47,6 +47,7 @@ def test_pull_local_sources(self):
class Options:
source = '.'
node_packages = []
+ node_engine = '4'
plugin = nodejs.NodePlugin('test-part', Options(),
self.project_options)
@@ -58,14 +59,15 @@ class Options:
self.assertFalse(self.run_mock.called, 'run() was called')
self.tar_mock.assert_has_calls([
mock.call(
- nodejs._get_nodejs_release(),
+ nodejs._get_nodejs_release(plugin.options.node_engine),
path.join(os.path.abspath('.'), 'parts', 'test-part', 'npm')),
mock.call().download()])
def test_build_local_sources(self):
class Options:
source = '.'
node_packages = []
+ node_engine = '4'
plugin = nodejs.NodePlugin('test-part', Options(),
self.project_options)
@@ -79,7 +81,7 @@ class Options:
mock.call(['npm', 'install', '-g'], cwd=plugin.builddir)])
self.tar_mock.assert_has_calls([
mock.call(
- nodejs._get_nodejs_release(),
+ nodejs._get_nodejs_release(plugin.options.node_engine),
path.join(os.path.abspath('.'), 'parts', 'test-part', 'npm')),
mock.call().provision(
plugin.installdir, clean_target=False, keep_tarball=True)])
@@ -88,6 +90,7 @@ def test_pull_and_build_node_packages_sources(self):
class Options:
source = None
node_packages = ['my-pkg']
+ node_engine = '4'
plugin = nodejs.NodePlugin('test-part', Options(),
self.project_options)
@@ -102,7 +105,7 @@ class Options:
cwd=plugin.builddir)])
self.tar_mock.assert_has_calls([
mock.call(
- nodejs._get_nodejs_release(),
+ nodejs._get_nodejs_release(plugin.options.node_engine),
path.join(os.path.abspath('.'), 'parts', 'test-part', 'npm')),
mock.call().download(),
mock.call().provision(
@@ -115,6 +118,7 @@ def test_unsupported_arch_raises_exception(self, machine_mock):
class Options:
source = None
node_packages = []
+ node_engine = '4'
with self.assertRaises(EnvironmentError) as raised:
nodejs.NodePlugin('test-part', Options(),
@@ -124,10 +128,12 @@ class Options:
'architecture not supported (fantasy-arch)')
def test_schema(self):
+ self.maxDiff = None
plugin_schema = {
'$schema': 'http://json-schema.org/draft-04/schema#',
'additionalProperties': False,
'properties': {
+ 'node-engine': {'default': '4.4.4', 'type': 'string'},
'node-packages': {'default': [],
'items': {'type': 'string'},
'minitems': 1,
@@ -140,7 +146,7 @@ def test_schema(self):
'source-type': {'default': '', 'type': 'string'}},
'pull-properties': ['source', 'source-type', 'source-branch',
'source-tag', 'source-subdir'],
- 'build-properties': ['node-packages'],
+ 'build-properties': ['node-packages', 'node-engine'],
'type': 'object'}
self.assertEqual(nodejs.NodePlugin.schema(), plugin_schema)
@@ -152,13 +158,13 @@ def test_required_not_in_parent_schema(self, schema_mock):
'pull-properties': [],
'build-properties': []
}
-
self.assertTrue('required' not in nodejs.NodePlugin.schema())
def test_clean_pull_step(self):
class Options:
source = '.'
node_packages = []
+ node_engine = '4'
plugin = nodejs.NodePlugin('test-part', Options(),
self.project_options)