Wednesday, August 22, 2012

Chef's python cookbook

I am quite impressed with the Chef's Python cookbook. Initially I thought that python_pip does not come with the ability to install packages using requirements.txt.

It turns out it does:
[19:19] <jameson_> Guest94181: you can use the "option" parameter to say "-r"
[19:19] <jameson_> and then you can pass in the requirement.txt as the package name
In another word,s, in your recipe you can write something like this:

python_pip "/var/lib/natrium/requirements.txt" do
  virtualenv "/path/to/virtual-env/"
  action :install
end
 
I was about to write a new resource in ruby like this:

File.open('requirements.txt').each(spe="\n") do |line|
        if line.start_with?("#")
                print "i got a bad one \n"
                print "#{line}"
                print "\n continue \n"
        else
                # line.index("#") != 0
                print "#{line}"
        #if line.index("#") != 0
                print "#{line}"
        end
end

This snippet above is just to show you how you do readlines in ruby, for given content as the one shown below:
Django==1.2.1
#Pinax==0.9a1
PyYAML==3.10
Pygments==1.5
certifi==0.0.8
chardet==1.0.1
decorator==3.3.2

What the actual cookbook will do is this:

---- Begin output of /var/lib/shared/graphyte-virtualenv/natrium-env/bin/pip install -r /var/lib/natrium/requirements.txt ----

The whole Python cookbook is very useful. It can create virtualenv as specified.

No comments:

Post a Comment