Skip to content

Commit

Permalink
Fix VirtualEnv Provider
Browse files Browse the repository at this point in the history
Signed-off-by: Seth Vargo <[email protected]>
  • Loading branch information
akiernan authored and sethvargo committed Aug 28, 2013
1 parent ed1d192 commit e3d1dcc
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 6 deletions.
5 changes: 4 additions & 1 deletion .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,23 @@ platforms:
suites:
- name: default
run_list:
- recipe[minitest-handler]
- recipe[python]
- recipe[python_test::cook-3084]
attributes: {}

- name: source
run_list:
- recipe[minitest-handler]
- recipe[python]
- recipe[python_test::cook-3084]
attributes: {python: {install_method: "source"}}
- name: exert
excludes: ["centos-5.9"]
run_list:
- recipe[python]
- recipe[python_test::test_exert]
- name: virtualenv
excludes: ["centos-5.9"]
run_list:
- recipe[python]
- recipe[python_test::test_virtualenv]
1 change: 1 addition & 0 deletions Berksfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ site :opscode
metadata

group :integration do
cookbook "minitest-handler"
cookbook "apt"
cookbook "yum"
cookbook "build-essential"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Install packages using the new hotness in Python package management...[`pip`](ht
# Attribute Parameters

- path: name attribute. The path where the virtualenv will be created
- interpreter: The Python interpreter to use. default is `python2.6`
- interpreter: The Python interpreter to use. default is null (i.e. use whatever python the virtualenv command is using).
- owner: The owner for the virtualenv
- group: The group owner of the file (string or id)
- options : Command line options (string)
Expand Down
3 changes: 2 additions & 1 deletion providers/virtualenv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def whyrun_supported?
action :create do
unless exists?
Chef::Log.info("Creating virtualenv #{new_resource} at #{new_resource.path}")
execute "#{virtualenv_cmd} --python=#{new_resource.interpreter} #{new_resource.options} #{new_resource.path}" do
interpreter = new_resource.interpreter ? " --python=#{new_resource.interpreter}" : ""
execute "#{virtualenv_cmd}#{interpreter} #{new_resource.options} #{new_resource.path}" do
user new_resource.owner if new_resource.owner
group new_resource.group if new_resource.group
end
Expand Down
2 changes: 1 addition & 1 deletion resources/virtualenv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def initialize(*args)
end

attribute :path, :kind_of => String, :name_attribute => true
attribute :interpreter, :default => 'python'
attribute :interpreter, :kind_of => String
attribute :owner, :regex => Chef::Config[:user_valid_regex]
attribute :group, :regex => Chef::Config[:group_valid_regex]
attribute :options, :kind_of => String
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'minitest/spec'

describe_recipe 'python_test::cook-3084' do
include MiniTest::Chef::Assertions
include MiniTest::Chef::Context
include MiniTest::Chef::Resources

it "created a virtualenv in cook-3084" do
result = assert_sh("cook-3084/bin/python -c 'import sys; from os.path import basename; print basename(sys.prefix)'")
assert_match /cook-3084\n/, result
end

it "created a virtualenv in cook-3084-interpreter" do
result = assert_sh("cook-3084-interpreter/bin/python -c 'import sys; from os.path import basename; print basename(sys.prefix)'")
assert_match /cook-3084-interpreter\n/, result
end
end
35 changes: 35 additions & 0 deletions test/cookbooks/python_test/recipes/cook-3084.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#
# Author:: Alex Kiernan (<[email protected]>)
# Cookbook Name:: python
# Recipe:: cook-3084
#
# Copyright 2013, Alex Kiernan
#
# 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.
#

include_recipe "python"

python_virtualenv "cook-3084" do
end

python_virtualenv "cook-3084-interpreter" do
# on EL5 the default python we install is called python26
if !node['python']['install_method'].eql?("source") &&
platform_family?('rhel') &&
node['platform_version'].split('.').first.to_i < 6
interpreter '/usr/bin/python26'
else
interpreter 'python'
end
end
2 changes: 0 additions & 2 deletions test/cookbooks/python_test/recipes/test_virtualenv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@
#

python_virtualenv "/tmp/virtualenv" do
interpreter "python"
owner "root"
group "root"
action :create
end

python_virtualenv "isolated python environment" do
path "/tmp/tobedestroyed"
interpreter "python"
action :create
end

Expand Down

0 comments on commit e3d1dcc

Please sign in to comment.