From ba263e475db1005655d734491ceda887af79b22f Mon Sep 17 00:00:00 2001 From: Kirk Hansen Date: Thu, 14 Jun 2018 10:19:55 -0500 Subject: [PATCH] Added pip3_plugin --- bootstrapvz/plugins/pip3_install/README.rst | 14 +++++++++++ bootstrapvz/plugins/pip3_install/__init__.py | 11 ++++++++ .../plugins/pip3_install/manifest-schema.yml | 18 +++++++++++++ bootstrapvz/plugins/pip3_install/tasks.py | 25 +++++++++++++++++++ 4 files changed, 68 insertions(+) create mode 100644 bootstrapvz/plugins/pip3_install/README.rst create mode 100644 bootstrapvz/plugins/pip3_install/__init__.py create mode 100644 bootstrapvz/plugins/pip3_install/manifest-schema.yml create mode 100644 bootstrapvz/plugins/pip3_install/tasks.py diff --git a/bootstrapvz/plugins/pip3_install/README.rst b/bootstrapvz/plugins/pip3_install/README.rst new file mode 100644 index 0000000..9a0d160 --- /dev/null +++ b/bootstrapvz/plugins/pip3_install/README.rst @@ -0,0 +1,14 @@ +Pip3 install +------------ + +Install packages from the Python Package Index via pip for python3 + +Installs ``build-essential`` and ``python3-dev`` debian packages, so +Python extension modules can be built. + +Settings +~~~~~~~~ + +- ``packages``: Python packages to install, a list of strings. The list + can contain anything that ``pip install`` would accept as an + argument, for example ``awscli==1.3.13``. diff --git a/bootstrapvz/plugins/pip3_install/__init__.py b/bootstrapvz/plugins/pip3_install/__init__.py new file mode 100644 index 0000000..4330d4d --- /dev/null +++ b/bootstrapvz/plugins/pip3_install/__init__.py @@ -0,0 +1,11 @@ +from . import tasks + + +def validate_manifest(data, validator, error): + from bootstrapvz.common.tools import rel_path + validator(data, rel_path(__file__, 'manifest-schema.yml')) + + +def resolve_tasks(taskset, manifest): + taskset.add(tasks.AddPip3Package) + taskset.add(tasks.Pip3InstallCommand) diff --git a/bootstrapvz/plugins/pip3_install/manifest-schema.yml b/bootstrapvz/plugins/pip3_install/manifest-schema.yml new file mode 100644 index 0000000..dd80c1e --- /dev/null +++ b/bootstrapvz/plugins/pip3_install/manifest-schema.yml @@ -0,0 +1,18 @@ +--- +$schema: http://json-schema.org/draft-04/schema# +title: Pip3 install plugin manifest +type: object +properties: + plugins: + type: object + properties: + pip_install: + type: object + properties: + packages: + type: array + items: + type: string + minItems: 1 + uniqueItems: true + additionalProperties: false diff --git a/bootstrapvz/plugins/pip3_install/tasks.py b/bootstrapvz/plugins/pip3_install/tasks.py new file mode 100644 index 0000000..b8d854b --- /dev/null +++ b/bootstrapvz/plugins/pip3_install/tasks.py @@ -0,0 +1,25 @@ +from bootstrapvz.base import Task +from bootstrapvz.common import phases + + +class AddPip3Package(Task): + description = 'Adding `pip\' and Co. to the image packages' + phase = phases.preparation + + @classmethod + def run(cls, info): + for package_name in ('build-essential', 'python3-dev', 'python3-pip'): + info.packages.add(package_name) + + +class Pip3InstallCommand(Task): + description = 'Install python packages from pypi with pip' + phase = phases.system_modification + + @classmethod + def run(cls, info): + from bootstrapvz.common.tools import log_check_call + packages = info.manifest.plugins['pip3_install']['packages'] + pip_install_command = ['chroot', info.root, 'pip3', 'install'] + pip_install_command.extend(packages) + log_check_call(pip_install_command)