puppet-pip 0.0.5 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/puppet/provider/package/pip.rb +6 -12
- data/spec/unit/provider/package/pip_spec.rb +49 -63
- metadata +4 -4
@@ -25,29 +25,23 @@ Puppet::Type.type(:package).provide :pip,
|
|
25
25
|
# that's managed by `pip` or an empty array if `pip` is not available.
|
26
26
|
def self.instances
|
27
27
|
packages = []
|
28
|
-
|
28
|
+
pip_cmd = which('pip') or return []
|
29
|
+
execpipe "#{pip_cmd} freeze" do |process|
|
29
30
|
process.collect do |line|
|
30
31
|
next unless options = parse(line)
|
31
32
|
packages << new(options)
|
32
33
|
end
|
33
34
|
end
|
34
35
|
packages
|
35
|
-
rescue Puppet::DevError
|
36
|
-
[]
|
37
36
|
end
|
38
37
|
|
39
38
|
# Return structured information about a particular package or `nil` if
|
40
39
|
# it is not installed or `pip` itself is not available.
|
41
40
|
def query
|
42
|
-
|
43
|
-
|
44
|
-
options = self.class.parse(line)
|
45
|
-
return options if options[:name] == @resource[:name]
|
46
|
-
end
|
41
|
+
self.class.instances.each do |provider_pip|
|
42
|
+
return provider_pip.properties if @resource[:name] == provider_pip.name
|
47
43
|
end
|
48
|
-
nil
|
49
|
-
rescue Puppet::DevError
|
50
|
-
nil
|
44
|
+
return nil
|
51
45
|
end
|
52
46
|
|
53
47
|
# Ask the PyPI API for the latest version number. There is no local
|
@@ -104,7 +98,7 @@ Puppet::Type.type(:package).provide :pip,
|
|
104
98
|
def lazy_pip(*args)
|
105
99
|
pip *args
|
106
100
|
rescue NoMethodError => e
|
107
|
-
if pathname =
|
101
|
+
if pathname = which('pip')
|
108
102
|
self.class.commands :pip => pathname
|
109
103
|
pip *args
|
110
104
|
else
|
@@ -1,23 +1,21 @@
|
|
1
|
-
#!/usr/bin/env
|
2
|
-
|
3
|
-
require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
|
1
|
+
#!/usr/bin/env rspec
|
2
|
+
require 'spec_helper'
|
4
3
|
|
5
4
|
provider_class = Puppet::Type.type(:package).provider(:pip)
|
6
5
|
|
7
6
|
describe provider_class do
|
8
7
|
|
9
8
|
before do
|
10
|
-
@resource =
|
11
|
-
@provider = provider_class.new
|
12
|
-
@provider.instance_variable_set(:@resource, @resource)
|
9
|
+
@resource = Puppet::Resource.new(:package, "sdsfdssdhdfyjymdgfcjdfjxdrssf")
|
10
|
+
@provider = provider_class.new(@resource)
|
13
11
|
end
|
14
12
|
|
15
13
|
describe "parse" do
|
16
14
|
|
17
15
|
it "should return a hash on valid input" do
|
18
16
|
provider_class.parse("Django==1.2.5").should == {
|
19
|
-
:ensure
|
20
|
-
:name
|
17
|
+
:ensure => "1.2.5",
|
18
|
+
:name => "Django",
|
21
19
|
:provider => :pip,
|
22
20
|
}
|
23
21
|
end
|
@@ -31,7 +29,7 @@ describe provider_class do
|
|
31
29
|
describe "instances" do
|
32
30
|
|
33
31
|
it "should return an array when pip is present" do
|
34
|
-
provider_class.expects(:
|
32
|
+
provider_class.expects(:which).with('pip').returns("/fake/bin/pip")
|
35
33
|
p = stub("process")
|
36
34
|
p.expects(:collect).yields("Django==1.2.5")
|
37
35
|
provider_class.expects(:execpipe).with("/fake/bin/pip freeze").yields(p)
|
@@ -39,8 +37,7 @@ describe provider_class do
|
|
39
37
|
end
|
40
38
|
|
41
39
|
it "should return an empty array when pip is missing" do
|
42
|
-
provider_class.expects(:
|
43
|
-
Puppet::DevError.new("Pretend pip isn't installed."))
|
40
|
+
provider_class.expects(:which).with('pip').returns nil
|
44
41
|
provider_class.instances.should == []
|
45
42
|
end
|
46
43
|
|
@@ -49,32 +46,25 @@ describe provider_class do
|
|
49
46
|
describe "query" do
|
50
47
|
|
51
48
|
before do
|
52
|
-
@resource
|
49
|
+
@resource[:name] = "Django"
|
53
50
|
end
|
54
51
|
|
55
52
|
it "should return a hash when pip and the package are present" do
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
53
|
+
provider_class.expects(:instances).returns [provider_class.new({
|
54
|
+
:ensure => "1.2.5",
|
55
|
+
:name => "Django",
|
56
|
+
:provider => :pip,
|
57
|
+
})]
|
58
|
+
|
60
59
|
@provider.query.should == {
|
61
|
-
:ensure
|
62
|
-
:name
|
60
|
+
:ensure => "1.2.5",
|
61
|
+
:name => "Django",
|
63
62
|
:provider => :pip,
|
64
63
|
}
|
65
64
|
end
|
66
65
|
|
67
|
-
it "should return nil when pip is missing" do
|
68
|
-
@provider.expects(:command).with(:pip).raises(
|
69
|
-
Puppet::DevError.new("Pretend pip isn't installed."))
|
70
|
-
@provider.query.should == nil
|
71
|
-
end
|
72
|
-
|
73
66
|
it "should return nil when the package is missing" do
|
74
|
-
|
75
|
-
p = stub("process")
|
76
|
-
p.expects(:each).yields("sdsfdssdhdfyjymdgfcjdfjxdrssf==0.0.0")
|
77
|
-
@provider.expects(:execpipe).with("/fake/bin/pip freeze").yields(p)
|
67
|
+
provider_class.expects(:instances).returns []
|
78
68
|
@provider.query.should == nil
|
79
69
|
end
|
80
70
|
|
@@ -83,12 +73,12 @@ describe provider_class do
|
|
83
73
|
describe "latest" do
|
84
74
|
|
85
75
|
it "should find a version number for Django" do
|
86
|
-
@resource
|
76
|
+
@resource[:name] = "Django"
|
87
77
|
@provider.latest.should_not == nil
|
88
78
|
end
|
89
79
|
|
90
80
|
it "should not find a version number for sdsfdssdhdfyjymdgfcjdfjxdrssf" do
|
91
|
-
@resource
|
81
|
+
@resource[:name] = "sdsfdssdhdfyjymdgfcjdfjxdrssf"
|
92
82
|
@provider.latest.should == nil
|
93
83
|
end
|
94
84
|
|
@@ -97,52 +87,46 @@ describe provider_class do
|
|
97
87
|
describe "install" do
|
98
88
|
|
99
89
|
before do
|
100
|
-
@resource
|
90
|
+
@resource[:name] = "sdsfdssdhdfyjymdgfcjdfjxdrssf"
|
101
91
|
@url = "git+https://example.com/sdsfdssdhdfyjymdgfcjdfjxdrssf.git"
|
102
92
|
end
|
103
93
|
|
104
94
|
it "should install" do
|
105
|
-
@resource
|
106
|
-
@resource
|
107
|
-
@provider.expects(:lazy_pip).
|
108
|
-
"install"
|
109
|
-
end.returns nil
|
95
|
+
@resource[:ensure] = :installed
|
96
|
+
@resource[:source] = nil
|
97
|
+
@provider.expects(:lazy_pip).
|
98
|
+
with("install", '-q', "sdsfdssdhdfyjymdgfcjdfjxdrssf")
|
110
99
|
@provider.install
|
111
100
|
end
|
112
101
|
|
113
102
|
it "should install from SCM" do
|
114
|
-
@resource
|
115
|
-
@resource
|
116
|
-
@provider.expects(:lazy_pip).
|
117
|
-
"#{@url}#egg=sdsfdssdhdfyjymdgfcjdfjxdrssf"
|
118
|
-
end.returns nil
|
103
|
+
@resource[:ensure] = :installed
|
104
|
+
@resource[:source] = @url
|
105
|
+
@provider.expects(:lazy_pip).
|
106
|
+
with("install", '-q', '-e', "#{@url}#egg=sdsfdssdhdfyjymdgfcjdfjxdrssf")
|
119
107
|
@provider.install
|
120
108
|
end
|
121
109
|
|
122
|
-
it "should install a particular revision" do
|
123
|
-
@resource
|
124
|
-
@resource
|
125
|
-
@provider.expects(:lazy_pip).
|
126
|
-
"#{@url}@0123456#egg=sdsfdssdhdfyjymdgfcjdfjxdrssf"
|
127
|
-
end.returns nil
|
110
|
+
it "should install a particular SCM revision" do
|
111
|
+
@resource[:ensure] = "0123456"
|
112
|
+
@resource[:source] = @url
|
113
|
+
@provider.expects(:lazy_pip).
|
114
|
+
with("install", "-q", "-e", "#{@url}@0123456#egg=sdsfdssdhdfyjymdgfcjdfjxdrssf")
|
128
115
|
@provider.install
|
129
116
|
end
|
130
117
|
|
131
118
|
it "should install a particular version" do
|
132
|
-
@resource
|
133
|
-
@resource
|
134
|
-
@provider.expects(:lazy_pip).with
|
135
|
-
"sdsfdssdhdfyjymdgfcjdfjxdrssf==0.0.0" == args[-1]
|
136
|
-
end.returns nil
|
119
|
+
@resource[:ensure] = "0.0.0"
|
120
|
+
@resource[:source] = nil
|
121
|
+
@provider.expects(:lazy_pip).with("install", "-q", "sdsfdssdhdfyjymdgfcjdfjxdrssf==0.0.0")
|
137
122
|
@provider.install
|
138
123
|
end
|
139
124
|
|
140
125
|
it "should upgrade" do
|
141
|
-
@resource
|
142
|
-
@resource
|
143
|
-
@provider.expects(:lazy_pip).
|
144
|
-
"
|
145
|
-
end.returns nil
|
126
|
+
@resource[:ensure] = :latest
|
127
|
+
@resource[:source] = nil
|
128
|
+
@provider.expects(:lazy_pip).
|
129
|
+
with("install", "-q", "--upgrade", "sdsfdssdhdfyjymdgfcjdfjxdrssf")
|
146
130
|
@provider.install
|
147
131
|
end
|
148
132
|
|
@@ -151,8 +135,9 @@ describe provider_class do
|
|
151
135
|
describe "uninstall" do
|
152
136
|
|
153
137
|
it "should uninstall" do
|
154
|
-
@resource
|
155
|
-
@provider.expects(:lazy_pip).
|
138
|
+
@resource[:name] = "sdsfdssdhdfyjymdgfcjdfjxdrssf"
|
139
|
+
@provider.expects(:lazy_pip).
|
140
|
+
with('uninstall', '-y', '-q', 'sdsfdssdhdfyjymdgfcjdfjxdrssf')
|
156
141
|
@provider.uninstall
|
157
142
|
end
|
158
143
|
|
@@ -175,14 +160,15 @@ describe provider_class do
|
|
175
160
|
end
|
176
161
|
|
177
162
|
it "should retry if pip has not yet been found" do
|
178
|
-
@provider.
|
163
|
+
@provider.expects(:pip).twice.with('freeze').raises(NoMethodError).then.returns(nil)
|
164
|
+
@provider.expects(:which).with('pip').returns("/fake/bin/pip")
|
179
165
|
@provider.method(:lazy_pip).call "freeze"
|
180
166
|
end
|
181
167
|
|
182
168
|
it "should fail if pip is missing" do
|
183
|
-
@provider.
|
184
|
-
|
185
|
-
|
169
|
+
@provider.expects(:pip).with('freeze').raises(NoMethodError)
|
170
|
+
@provider.expects(:which).with('pip').returns(nil)
|
171
|
+
expect { @provider.method(:lazy_pip).call("freeze") }.to raise_error(NoMethodError)
|
186
172
|
end
|
187
173
|
|
188
174
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet-pip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
|
+
- 1
|
7
8
|
- 0
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 0.0.5
|
10
|
+
version: 1.0.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Richard Crowley
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-04-18 00:00:00 +00:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|