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'
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