(puppetlabs/puppet) Pip Package Provider: index-url & extra-index-url

155 views
Skip to first unread message

weareth...@puppetlabs.com

unread,
Feb 21, 2012, 12:30:06 PM2/21/12
to puppe...@googlegroups.com

Please review pull request #521: Pip Package Provider: index-url & extra-index-url opened by (brendanmaguire)

Description:

Modified the pip package provider to take the index-url and extra-index-url in the source parameter. This is useful when you want to point to an index server other than PyPi. i.e.

pip install <local-package> --extra-index-url='http://<your-server>/pypi'

  • Opened: Tue Feb 21 17:15:14 UTC 2012
  • Based on: puppetlabs:master (b8a6f230c99a82ee4fae0ae18bca9dae61e4f1f7)
  • Requested merge: brendanmaguire:master (e417525d2c4dc88db1545bc7213de16b637e5d97)

Diff follows:

diff --git a/lib/puppet/provider/package/pip.rb b/lib/puppet/provider/package/pip.rb
index b6b6089..7ad36b5 100644
--- a/lib/puppet/provider/package/pip.rb
+++ b/lib/puppet/provider/package/pip.rb
@@ -60,10 +60,16 @@ def latest
   # Install a package.  The ensure parameter may specify installed,
   # latest, a version number, or, in conjunction with the source
   # parameter, an SCM revision.  In that case, the source parameter
-  # gives the fully-qualified URL to the repository.
+  # gives the fully-qualified URL to the repository. The source parameter
+  # can also specify the --extra-index-url or --index-url by prepending
+  # the option and a colon in front of the url like so:
+  #   source => 'extra-index-url: http://server/pypi'
   def install
     args = %w{install -q}
-    if @resource[:source]
+
+    if @resource[:source] and
+        !(eurl = /^extra-index-url:(.*)/.match(@resource[:source]) or
+          iurl = /^index-url:(.*)/.match(@resource[:source]))
       args << "-e"
       if String === @resource[:ensure]
         args << "#{@resource[:source]}@#{@resource[:ensure]}#egg=#{
@@ -72,6 +78,12 @@ def install
         args << "#{@resource[:source]}#egg=#{@resource[:name]}"
       end
     else
+      if eurl
+        args << "--extra-index-url='" + eurl[1].strip + "'"
+      elsif iurl
+        args << "--index-url=" + iurl[1].strip
+      end
+
       case @resource[:ensure]
       when String
         args << "#{@resource[:name]}==#{@resource[:ensure]}"
diff --git a/spec/unit/provider/package/pip_spec.rb b/spec/unit/provider/package/pip_spec.rb
index 2de0eb4..140d1fb 100755
--- a/spec/unit/provider/package/pip_spec.rb
+++ b/spec/unit/provider/package/pip_spec.rb
@@ -140,6 +140,36 @@
       @provider.install
     end
 
+    it "should use the extra-index-url option" do
+      @resource[:ensure] = :installed
+      @extra_index_url = 'http://example.com/pypi/'
+      @resource[:source] = "extra-index-url:#{@extra_index_url}"
+      @provider.expects(:lazy_pip).
+        with("install", '-q', "--extra-index-url='#{@extra_index_url}'",
+             "fake_package")
+      @provider.install
+    end
+
+    it "should use the extra-index-url option with spaces" do
+      @resource[:ensure] = :installed
+      @extra_index_url = ' http://example.com/pypi/ http://example2.com/pypi/ '
+      @resource[:source] = "extra-index-url:#{@extra_index_url}"
+      @provider.expects(:lazy_pip).
+        with("install", '-q',
+             "--extra-index-url='http://example.com/pypi/ http://example2.com/pypi/'",
+             "fake_package")
+      @provider.install
+    end
+
+    it "should use the index-url option" do
+      @resource[:ensure] = :installed
+      @index_url = 'http://example.com/pypi/'
+      @resource[:source] = "index-url: #{@index_url}"
+      @provider.expects(:lazy_pip).
+        with("install", '-q', "--index-url=#{@index_url}", "fake_package")
+      @provider.install
+    end
+
   end
 
   describe "uninstall" do

    

Reply all
Reply to author
Forward
0 new messages