diff --git a/.kitchen.yml b/.kitchen.yml index 7eaf82f..6432844 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -39,6 +39,11 @@ suites: - recipe[python] - recipe[python_test::cook-3084] attributes: {} +- name: pip + run_list: + - recipe[minitest-handler] + - recipe[python] + - recipe[python_test::test_pip] - name: source run_list: diff --git a/Berksfile b/Berksfile index f795efe..f59fa9c 100644 --- a/Berksfile +++ b/Berksfile @@ -1,4 +1,4 @@ -site :opscode +site 'https://supermarket.chef.io' metadata diff --git a/CHANGELOG.md b/CHANGELOG.md index 83d283c..a6df03d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,23 +22,23 @@ v1.4.4 v1.4.2 ------ ### Bug -- **[COOK-3796](https://tickets.opscode.com/browse/COOK-3796)** - Virtualenv can fail +- **[COOK-3796](https://tickets.chef.io/browse/COOK-3796)** - Virtualenv can fail ### Improvement -- **[COOK-3719](https://tickets.opscode.com/browse/COOK-3719)** - Allow alternative install python, update pip location -- **[COOK-3703](https://tickets.opscode.com/browse/COOK-3703)** - Create symlink for source built python [python3 support] +- **[COOK-3719](https://tickets.chef.io/browse/COOK-3719)** - Allow alternative install python, update pip location +- **[COOK-3703](https://tickets.chef.io/browse/COOK-3703)** - Create symlink for source built python [python3 support] v1.4.0 ------ ### New Feature -- **[COOK-3248](https://tickets.opscode.com/browse/COOK-3248)** - Improve testing suite +- **[COOK-3248](https://tickets.chef.io/browse/COOK-3248)** - Improve testing suite ### Improvement -- **[COOK-3125](https://tickets.opscode.com/browse/COOK-3125)** - Don't use `normal` attributes +- **[COOK-3125](https://tickets.chef.io/browse/COOK-3125)** - Don't use `normal` attributes ### Bug -- **[COOK-3084](https://tickets.opscode.com/browse/COOK-3084)** - Fix `python_virtualenv` on EL 5 +- **[COOK-3084](https://tickets.chef.io/browse/COOK-3084)** - Fix `python_virtualenv` on EL 5 v1.3.6 ------ diff --git a/README.md b/README.md index dd0b046..9087145 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,14 @@ python Cookbook Installs and configures Python. Also includes LWRPs for managing python packages with `pip` and `virtualenv` isolated Python environments. +## **THIS COOKBOOK IS DEPRECATED** + +[Poise-python](https://github.com/poise/poise-python) is a vastly better cookbook +for managing Python-related things. This cookbook will remain for compatibility +but any future release will only be to gut it and turn it into a wrapper for +`poise-python`. + +## **I REPEAT, THIS COOKBOOK IS DEPRECATED** Requirements ------------ @@ -66,7 +74,7 @@ python_pip "gunicorn" # target a virtualenv python_pip "gunicorn" do - virtualenv "/home/ubunut/my_ve" + virtualenv "/home/ubuntu/my_ve" end ``` @@ -77,13 +85,6 @@ python_pip "django" do end ``` -```ruby -# use this provider with the core package resource -package "django" do - provider Chef::Provider::PythonPip -end -``` - ### python_virtualenv [`virtualenv`](http://pypi.python.org/pypi/virtualenv) is a great tool that creates isolated python environments. Think of it as RVM without all those hipsters and tight jeans. @@ -151,10 +152,10 @@ Installs virtualenv using the `python_pip` resource. License & Authors ----------------- -- Author:: Seth Chisamore () +- Author:: Seth Chisamore () ```text -Copyright:: 2011, Opscode, Inc +Copyright:: 2011, Chef Software, Inc Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/attributes/default.rb b/attributes/default.rb index d0a32c4..699df21 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -1,9 +1,9 @@ # -# Author:: Seth Chisamore () +# Author:: Seth Chisamore () # Cookbook Name:: python # Attribute:: default # -# Copyright 2011, Opscode, Inc. +# Copyright 2011, Chef Software, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -34,9 +34,9 @@ default['python']['binary'] = "#{node['python']['prefix_dir']}/bin/python" default['python']['url'] = 'http://www.python.org/ftp/python' -default['python']['version'] = '2.7.5' -default['python']['checksum'] = '3b477554864e616a041ee4d7cef9849751770bc7c39adaf78a94ea145c488059' -default['python']['configure_options'] = %W{--prefix=#{python['prefix_dir']}} +default['python']['version'] = '2.7.7' +default['python']['checksum'] = '7f49c0a6705ad89d925181e27d0aaa025ee4731ce0de64776c722216c3e66c42' +default['python']['configure_options'] = %W{--prefix=#{node['python']['prefix_dir']}} default['python']['make_options'] = %W{install} default['python']['pip_location'] = "#{node['python']['prefix_dir']}/bin/pip" diff --git a/providers/pip.rb b/providers/pip.rb index 800bed6..bc0d559 100644 --- a/providers/pip.rb +++ b/providers/pip.rb @@ -1,9 +1,9 @@ # -# Author:: Seth Chisamore +# Author:: Seth Chisamore # Cookbook Name:: python # Provider:: pip # -# Copyright:: 2011, Opscode, Inc +# Copyright:: 2011, Chef Software, Inc # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -106,16 +106,13 @@ def load_current_resource def current_installed_version @current_installed_version ||= begin - delimeter = /==/ - - version_check_cmd = "#{which_pip(new_resource)} freeze | grep -i '^#{new_resource.package_name}=='" - # incase you upgrade pip with pip! - if new_resource.package_name.eql?('pip') - delimeter = /\s/ - version_check_cmd = "#{which_pip(@new_resource)} --version" + out = nil + package_name = new_resource.package_name.gsub('_', '-') + pattern = Regexp.new("^#{Regexp.escape(package_name)} \\(([^)]+)\\)$", true) + shell_out("#{which_pip(new_resource)} list").stdout.lines.find do |line| + out = pattern.match(line) end - result = shell_out(version_check_cmd) - (result.exitstatus == 0) ? result.stdout.split(delimeter)[1].strip : nil + out.nil? ? nil : out[1] end end diff --git a/providers/virtualenv.rb b/providers/virtualenv.rb index 904c1b4..a04147b 100644 --- a/providers/virtualenv.rb +++ b/providers/virtualenv.rb @@ -1,9 +1,9 @@ # -# Author:: Seth Chisamore +# Author:: Seth Chisamore # Cookbook Name:: python # Provider:: virtualenv # -# Copyright:: 2011, Opscode, Inc +# Copyright:: 2011, Chef Software, Inc # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/recipes/default.rb b/recipes/default.rb index ee9afe8..725b6cb 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -1,9 +1,9 @@ # -# Author:: Seth Chisamore +# Author:: Seth Chisamore # Cookbook Name:: python # Recipe:: default # -# Copyright 2011, Opscode, Inc. +# Copyright 2011, Chef Software, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/recipes/package.rb b/recipes/package.rb index 115b53b..38ea3b3 100644 --- a/recipes/package.rb +++ b/recipes/package.rb @@ -1,9 +1,9 @@ # -# Author:: Seth Chisamore +# Author:: Seth Chisamore # Cookbook Name:: python # Recipe:: package # -# Copyright 2011, Opscode, Inc. +# Copyright 2011, Chef Software, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/recipes/pip.rb b/recipes/pip.rb index 17110fa..ad02ab7 100644 --- a/recipes/pip.rb +++ b/recipes/pip.rb @@ -1,9 +1,9 @@ # -# Author:: Seth Chisamore +# Author:: Seth Chisamore # Cookbook Name:: python # Recipe:: pip # -# Copyright 2011, Opscode, Inc. +# Copyright 2011, Chef Software, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/recipes/source.rb b/recipes/source.rb index ac8ed86..c6256f7 100644 --- a/recipes/source.rb +++ b/recipes/source.rb @@ -1,9 +1,9 @@ # -# Author:: Seth Chisamore +# Author:: Seth Chisamore # Cookbook Name:: python # Recipe:: source # -# Copyright 2011, Opscode, Inc. +# Copyright 2011, Chef Software, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/recipes/virtualenv.rb b/recipes/virtualenv.rb index 8098492..e0626a4 100644 --- a/recipes/virtualenv.rb +++ b/recipes/virtualenv.rb @@ -1,9 +1,9 @@ # -# Author:: Seth Chisamore +# Author:: Seth Chisamore # Cookbook Name:: python # Recipe:: virtualenv # -# Copyright 2011, Opscode, Inc. +# Copyright 2011, Chef Software, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/resources/pip.rb b/resources/pip.rb index 1475b3a..2b9f13e 100644 --- a/resources/pip.rb +++ b/resources/pip.rb @@ -1,9 +1,9 @@ # -# Author:: Seth Chisamore +# Author:: Seth Chisamore # Cookbook Name:: python # Resource:: pip # -# Copyright:: 2011, Opscode, Inc +# Copyright:: 2011, Chef Software, Inc # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/resources/virtualenv.rb b/resources/virtualenv.rb index e9f7327..8de75be 100644 --- a/resources/virtualenv.rb +++ b/resources/virtualenv.rb @@ -1,9 +1,9 @@ # -# Author:: Seth Chisamore +# Author:: Seth Chisamore # Cookbook Name:: python # Resource:: virtualenv # -# Copyright:: 2011, Opscode, Inc +# Copyright:: 2011, Chef Software, Inc # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/test/cookbooks/python_test/files/default/tests/minitest/test_pip_test.rb b/test/cookbooks/python_test/files/default/tests/minitest/test_pip_test.rb new file mode 100644 index 0000000..15edfff --- /dev/null +++ b/test/cookbooks/python_test/files/default/tests/minitest/test_pip_test.rb @@ -0,0 +1,15 @@ +require 'minitest/spec' + +describe_recipe 'python_test::test_pip' do + include MiniTest::Chef::Assertions + include MiniTest::Chef::Context + include MiniTest::Chef::Resources + + it "ran first should_dsl pip install" do + assert File.exist?("/tmp/first-install.txt"), `/tmp/virtualenv/bin/pip freeze` + end + + it "did not run second should_dsl pip install" do + assert !File.exist?("/tmp/second-install.txt"), `/tmp/virtualenv/bin/pip freeze` + end +end diff --git a/test/cookbooks/python_test/recipes/test_pip.rb b/test/cookbooks/python_test/recipes/test_pip.rb new file mode 100644 index 0000000..136d076 --- /dev/null +++ b/test/cookbooks/python_test/recipes/test_pip.rb @@ -0,0 +1,51 @@ +# +# Author:: Hugo Lopes Tavares +# Cookbook Name:: python +# Recipe:: test_virtualenv +# +# Copyright 2013, Heavy Water Operations, LLC. +# Copyright 2014, Yipit, Inc. +# +# 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. +# + +file "/tmp/first-install.txt" do + content "test" + action :nothing +end + +file "/tmp/second-install.txt" do + content "test" + action :nothing +end + +python_virtualenv "/tmp/virtualenv" do + owner "root" + group "root" + action :create +end + +python_pip "should_dsl first install" do + package_name "should_dsl" + virtualenv "/tmp/virtualenv" + version "2.1.2" + notifies :create, "file[/tmp/first-install.txt]" +end + +python_pip "should_dsl second install" do + package_name "should_dsl" + virtualenv "/tmp/virtualenv" + # same version as before + version "2.1.2" + notifies :create, "file[/tmp/second-install.txt]" +end diff --git a/test/integration/source/bats/source.bats b/test/integration/source/bats/source.bats index ae1fe98..dd35c75 100644 --- a/test/integration/source/bats/source.bats +++ b/test/integration/source/bats/source.bats @@ -4,6 +4,6 @@ [ -x "/usr/local/bin/python" ] } -@test "python should be version 2.7.5" { - /usr/local/bin/python -c 'import sys; print sys.version' | grep '2.7.5' +@test "python should be version 2.7.7" { + /usr/local/bin/python -c 'import sys; print sys.version' | grep '2.7.7' }