Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e3d1dcc

Browse files
akiernansethvargo
authored andcommitted
Fix VirtualEnv Provider
Signed-off-by: Seth Vargo <[email protected]>
1 parent ed1d192 commit e3d1dcc

File tree

8 files changed

+61
-6
lines changed

8 files changed

+61
-6
lines changed

.kitchen.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,23 @@ platforms:
3535
suites:
3636
- name: default
3737
run_list:
38+
- recipe[minitest-handler]
3839
- recipe[python]
40+
- recipe[python_test::cook-3084]
3941
attributes: {}
4042

4143
- name: source
4244
run_list:
45+
- recipe[minitest-handler]
4346
- recipe[python]
47+
- recipe[python_test::cook-3084]
4448
attributes: {python: {install_method: "source"}}
4549
- name: exert
4650
excludes: ["centos-5.9"]
4751
run_list:
4852
- recipe[python]
4953
- recipe[python_test::test_exert]
5054
- name: virtualenv
51-
excludes: ["centos-5.9"]
5255
run_list:
5356
- recipe[python]
5457
- recipe[python_test::test_virtualenv]

Berksfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ site :opscode
33
metadata
44

55
group :integration do
6+
cookbook "minitest-handler"
67
cookbook "apt"
78
cookbook "yum"
89
cookbook "build-essential"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ Install packages using the new hotness in Python package management...[`pip`](ht
9595
# Attribute Parameters
9696

9797
- path: name attribute. The path where the virtualenv will be created
98-
- interpreter: The Python interpreter to use. default is `python2.6`
98+
- interpreter: The Python interpreter to use. default is null (i.e. use whatever python the virtualenv command is using).
9999
- owner: The owner for the virtualenv
100100
- group: The group owner of the file (string or id)
101101
- options : Command line options (string)

providers/virtualenv.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ def whyrun_supported?
2929
action :create do
3030
unless exists?
3131
Chef::Log.info("Creating virtualenv #{new_resource} at #{new_resource.path}")
32-
execute "#{virtualenv_cmd} --python=#{new_resource.interpreter} #{new_resource.options} #{new_resource.path}" do
32+
interpreter = new_resource.interpreter ? " --python=#{new_resource.interpreter}" : ""
33+
execute "#{virtualenv_cmd}#{interpreter} #{new_resource.options} #{new_resource.path}" do
3334
user new_resource.owner if new_resource.owner
3435
group new_resource.group if new_resource.group
3536
end

resources/virtualenv.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def initialize(*args)
2828
end
2929

3030
attribute :path, :kind_of => String, :name_attribute => true
31-
attribute :interpreter, :default => 'python'
31+
attribute :interpreter, :kind_of => String
3232
attribute :owner, :regex => Chef::Config[:user_valid_regex]
3333
attribute :group, :regex => Chef::Config[:group_valid_regex]
3434
attribute :options, :kind_of => String
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
require 'minitest/spec'
2+
3+
describe_recipe 'python_test::cook-3084' do
4+
include MiniTest::Chef::Assertions
5+
include MiniTest::Chef::Context
6+
include MiniTest::Chef::Resources
7+
8+
it "created a virtualenv in cook-3084" do
9+
result = assert_sh("cook-3084/bin/python -c 'import sys; from os.path import basename; print basename(sys.prefix)'")
10+
assert_match /cook-3084\n/, result
11+
end
12+
13+
it "created a virtualenv in cook-3084-interpreter" do
14+
result = assert_sh("cook-3084-interpreter/bin/python -c 'import sys; from os.path import basename; print basename(sys.prefix)'")
15+
assert_match /cook-3084-interpreter\n/, result
16+
end
17+
end
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#
2+
# Author:: Alex Kiernan (<[email protected]>)
3+
# Cookbook Name:: python
4+
# Recipe:: cook-3084
5+
#
6+
# Copyright 2013, Alex Kiernan
7+
#
8+
# Licensed under the Apache License, Version 2.0 (the "License");
9+
# you may not use this file except in compliance with the License.
10+
# You may obtain a copy of the License at
11+
#
12+
# http://www.apache.org/licenses/LICENSE-2.0
13+
#
14+
# Unless required by applicable law or agreed to in writing, software
15+
# distributed under the License is distributed on an "AS IS" BASIS,
16+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
# See the License for the specific language governing permissions and
18+
# limitations under the License.
19+
#
20+
21+
include_recipe "python"
22+
23+
python_virtualenv "cook-3084" do
24+
end
25+
26+
python_virtualenv "cook-3084-interpreter" do
27+
# on EL5 the default python we install is called python26
28+
if !node['python']['install_method'].eql?("source") &&
29+
platform_family?('rhel') &&
30+
node['platform_version'].split('.').first.to_i < 6
31+
interpreter '/usr/bin/python26'
32+
else
33+
interpreter 'python'
34+
end
35+
end

test/cookbooks/python_test/recipes/test_virtualenv.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,13 @@
1919
#
2020

2121
python_virtualenv "/tmp/virtualenv" do
22-
interpreter "python"
2322
owner "root"
2423
group "root"
2524
action :create
2625
end
2726

2827
python_virtualenv "isolated python environment" do
2928
path "/tmp/tobedestroyed"
30-
interpreter "python"
3129
action :create
3230
end
3331

0 commit comments

Comments
 (0)