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