Skip to content

Commit ec9d2dd

Browse files
committed
Fix issue with underscores in package names. Fixespoise#91
Before this commit, `python_pip` reinstalled packages that contain underscores in their names. More details at poise#91
1 parent eba69be commit ec9d2dd

File tree

4 files changed

+73
-1
lines changed

4 files changed

+73
-1
lines changed

‎.kitchen.yml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ suites:
3939
- recipe[python]
4040
- recipe[python_test::cook-3084]
4141
attributes: {}
42+
- name: pip
43+
run_list:
44+
- recipe[minitest-handler]
45+
- recipe[python]
46+
- recipe[python_test::test_pip]
4247

4348
- name: source
4449
run_list:

‎providers/pip.rb‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ def current_installed_version
108108
@current_installed_version ||= begin
109109
delimeter=/==/
110110

111-
version_check_cmd="#{which_pip(new_resource)} freeze | grep -i '^#{new_resource.package_name}=='"
111+
normalized_package_name=new_resource.package_name.gsub('_','-')
112+
version_check_cmd="#{which_pip(new_resource)} freeze | grep -i '^#{normalized_package_name}=='"
112113
# incase you upgrade pip with pip!
113114
ifnew_resource.package_name.eql?('pip')
114115
delimeter=/\s/
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
require'minitest/spec'
2+
3+
describe_recipe'python_test::test_pip'do
4+
includeMiniTest::Chef::Assertions
5+
includeMiniTest::Chef::Context
6+
includeMiniTest::Chef::Resources
7+
8+
it"ran first should_dsl pip install"do
9+
assertFile.exist?("/tmp/first-install.txt"),`/tmp/virtualenv/bin/pip freeze`
10+
end
11+
12+
it"did not run second should_dsl pip install"do
13+
assert !File.exist?("/tmp/second-install.txt"),`/tmp/virtualenv/bin/pip freeze`
14+
end
15+
end
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#
2+
# Author:: Hugo Lopes Tavares <[email protected]>
3+
# Cookbook Name:: python
4+
# Recipe:: test_virtualenv
5+
#
6+
# Copyright 2013, Heavy Water Operations, LLC.
7+
# Copyright 2014, Yipit, Inc.
8+
#
9+
# Licensed under the Apache License, Version 2.0 (the "License");
10+
# you may not use this file except in compliance with the License.
11+
# You may obtain a copy of the License at
12+
#
13+
# http://www.apache.org/licenses/LICENSE-2.0
14+
#
15+
# Unless required by applicable law or agreed to in writing, software
16+
# distributed under the License is distributed on an "AS IS" BASIS,
17+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
# See the License for the specific language governing permissions and
19+
# limitations under the License.
20+
#
21+
22+
file"/tmp/first-install.txt"do
23+
content"test"
24+
action:nothing
25+
end
26+
27+
file"/tmp/second-install.txt"do
28+
content"test"
29+
action:nothing
30+
end
31+
32+
python_virtualenv"/tmp/virtualenv"do
33+
owner"root"
34+
group"root"
35+
action:create
36+
end
37+
38+
python_pip"should_dsl first install"do
39+
package_name"should_dsl"
40+
virtualenv"/tmp/virtualenv"
41+
version"2.1.2"
42+
notifies:create,"file[/tmp/first-install.txt]"
43+
end
44+
45+
python_pip"should_dsl second install"do
46+
package_name"should_dsl"
47+
virtualenv"/tmp/virtualenv"
48+
# same version as before
49+
version"2.1.2"
50+
notifies:create,"file[/tmp/second-install.txt]"
51+
end

0 commit comments

Comments
(0)