[chef] Re: Re: Re: Re: Re: Re: How would I prevent python_pip from installing packages that are already installed?


Chronological Thread 
  • From: Fabien Delpierre < >
  • To: chef < >
  • Subject: [chef] Re: Re: Re: Re: Re: Re: How would I prevent python_pip from installing packages that are already installed?
  • Date: Tue, 10 Mar 2015 12:57:09 -0400

Thanks Sean.
I got it to work with with Daniel's help. First I was using the :upgrade action because I encountered a problem with :install that using :upgrade instead fixed, but it turns out using :install works fine after refactoring the code some. No bugs as far as I can tell!

On Mon, Mar 9, 2015 at 9:30 AM, Sean OMeara < " target="_blank"> > wrote:
The internal implementation of python_pip should be responsible for
figuring out if it needs to take action to repair its state.

If it doesn't, its a bug.

You shouldn't have to do any of that in your recipe.

-s



On Sun, Mar 8, 2015 at 4:53 PM, Fabien Delpierre
< "> > wrote:
> Success! Initially I had some trouble because I need to remove a few lines
> from my pip requirements file before passing it to Chef, and after running
> that .split, my code that did that no longer worked, so I struggled with
> that for a bit, then it occurred to me that I could just clean up the
> requirements file before splitting the package from the package version, and
> now I have working code, and Chef runs after the first one now take 50-60
> seconds. Seems like I don't even need that not_if anymore, either. So here's
> my updated code if anyone cares. It's probably not very elegant but it's the
> best this newbie programmer can come up with, and it works.
>
> # Install packages not loaded from the requirements file
> node['foo']['venv_packages'].each do |pkg, pkg_version|
>   python_pip pkg do
>     virtualenv node['foo']['venv']
>     version pkg_version
>     action :install
>   end
> end
>
> # Parse the pip requirements file and remove pyodbc, we'll deal with it
> separately
> reqs = IO.readlines("/foo/setup/dev-requirements.txt").map {|r| r.chomp}
> pyodbc = []
>
> while reqs.index{|r| r.include?("pyodbc")} != nil
>   match = reqs.index{|r| r.include?("pyodbc")}
>   pyodbc.push(reqs[match])
>   reqs.delete_at(match)
> end
>
> # Now re-parse the array to split the package names from the desired
> versions
> reqs = reqs.map {|r| r.strip.split('==')}
>
> # Install the packages we want in the virtual environment
> reqs.each do |pkg, pkg_version|
>   python_pip pkg do
>     virtualenv node['foo']['venv']
>     version pkg_version
>     action :install
>   end
> end
>
> # Now install pyodbc
> match = pyodbc.index{|p| p.include?("pyodbc=")}
> pyodbc_pkg = pyodbc[match].split("==") # this should now be =
> ["pyodbc","3.0.7"]
> pyodbc.delete_at(match)
> pyodbc_args = pyodbc * " " # this should now be = "--allow-external pyodbc
> --allow-public pyodbc"
>
> python_pip pyodbc_pkg[0] do
>   virtualenv node['foo']['venv']
>   version pyodbc_pkg[1]
>   options pyodbc_args
>   action :install
> end
>
>
>
>
> On Fri, Mar 6, 2015 at 7:32 PM, Daniel DeLeo < "> > wrote:
>>
>>
>>
>> On Friday, March 6, 2015 at 2:39 PM, Fabien Delpierre wrote:
>>
>> > Daniel,
>> > Setting the version like:
>> > python_pip 'package' do
>> > version 'x'
>> > ...
>> > end
>> > ...sounds like something I should be able to figure out. I have a
>> > requirements file that looks like this:
>> > package==version
>> > And a long list of packages.
>>
>> Ruby’s pretty good for quick and dirty scripting of this kind of thing.
>> Something like this should work:
>>
>> require ‘pp’ # just for debugging/showing the example
>>
>> names_and_version_specs = IO.readlines('/tmp/example.txt')
>> names_and_versions = names_and_version_specs.map do |line|
>>   line.strip.split('==')
>> end
>>
>> # debug
>> pp names_and_versions
>>
>> # do something like this in your recipe:
>> # names_and_versions.each do |name, pkg_version|
>> # python_pip name do
>> # version pkg_version
>> # end
>> # end
>>
>>
>>
>> HTH,
>>
>> --
>> Daniel DeLeo
>>
>




Archive powered by MHonArc 2.6.16.

§