From 810efa014aa370e5f828d7fb9f33cb9e22de56e2 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Fri, 17 Mar 2017 19:00:37 +0000 Subject: [PATCH 1/1] Add a python cookbook --- .kitchen.yml | 3 ++ cookbooks/python/.foodcritic | 3 ++ cookbooks/python/README.md | 4 +++ cookbooks/python/metadata.rb | 7 +++++ cookbooks/python/recipes/default.rb | 21 +++++++++++++ cookbooks/python/resources/package.rb | 44 +++++++++++++++++++++++++++ 6 files changed, 82 insertions(+) create mode 100644 cookbooks/python/.foodcritic create mode 100644 cookbooks/python/README.md create mode 100644 cookbooks/python/metadata.rb create mode 100644 cookbooks/python/recipes/default.rb create mode 100644 cookbooks/python/resources/package.rb diff --git a/.kitchen.yml b/.kitchen.yml index c49fa230f..1b49363e6 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -62,6 +62,9 @@ suites: - recipe[accounts::default] - recipe[chef::default] - role[otrs] + - name: python + run_list: + - recipe[python::default] - name: tools run_list: - recipe[tools::default] diff --git a/cookbooks/python/.foodcritic b/cookbooks/python/.foodcritic new file mode 100644 index 000000000..a085263c8 --- /dev/null +++ b/cookbooks/python/.foodcritic @@ -0,0 +1,3 @@ +~FC001 +~FC064 +~FC065 diff --git a/cookbooks/python/README.md b/cookbooks/python/README.md new file mode 100644 index 000000000..120d7100a --- /dev/null +++ b/cookbooks/python/README.md @@ -0,0 +1,4 @@ +# Python Cookbook + +This cookbook installs the Python runtime, and defines a `python_package` +provider to install packages using pip. diff --git a/cookbooks/python/metadata.rb b/cookbooks/python/metadata.rb new file mode 100644 index 000000000..789050a15 --- /dev/null +++ b/cookbooks/python/metadata.rb @@ -0,0 +1,7 @@ +name "python" +maintainer "OpenStreetMap Administrators" +maintainer_email "admins@openstreetmap.org" +license "Apache 2.0" +description "Installs and configures Python" +long_description IO.read(File.join(File.dirname(__FILE__), "README.md")) +version "1.0.0" diff --git a/cookbooks/python/recipes/default.rb b/cookbooks/python/recipes/default.rb new file mode 100644 index 000000000..14b1e5a87 --- /dev/null +++ b/cookbooks/python/recipes/default.rb @@ -0,0 +1,21 @@ +# +# Cookbook Name:: python +# Recipe:: default +# +# Copyright 2017, OpenStreetMap Foundation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package "python" +package "python-pip" diff --git a/cookbooks/python/resources/package.rb b/cookbooks/python/resources/package.rb new file mode 100644 index 000000000..3a766957e --- /dev/null +++ b/cookbooks/python/resources/package.rb @@ -0,0 +1,44 @@ +# +# Cookbook Name:: python +# Resource:: package +# +# Copyright 2017, OpenStreetMap Foundation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +default_action :install + +attribute :package_name, :kind_of => String, :name_attribute => true +attribute :version, :kind_of => String + +action :install do + if version.nil? + execute "pip-install-#{name}" do + command "pip install #{new_resource.package_name}" + not_if "pip show #{new_resource.package_name}" + end + else + execute "pip-install-#{name}" do + command "pip install #{new_resource.package_name}==#{new_resource.version}" + not_if "pip show #{new_resource.package_name} | fgrep -q #{new_resource.version}" + end + end +end + +action :remove do + execute "pip-uninstall-#{name}" do + command "pip uninstall #{new_resource.package_name}" + only_if "pip show #{new_resource.package_name}" + end +end -- 2.43.2