From 782af6bdf0405209c6f062b90b67f8b123fadd5a Mon Sep 17 00:00:00 2001 From: Donald Stufft Date: Wed, 30 Apr 2014 07:22:32 -0400 Subject: [PATCH] Only adjust $PATH instead of symlinking to an intermediate directory --- ci_environment/python/attributes/default.rb | 13 +++-- ci_environment/python/recipes/pyenv.rb | 50 +++++++------------ .../python/templates/default/pyenv.sh.erb | 2 + 3 files changed, 30 insertions(+), 35 deletions(-) create mode 100644 ci_environment/python/templates/default/pyenv.sh.erb diff --git a/ci_environment/python/attributes/default.rb b/ci_environment/python/attributes/default.rb index 34e75b6bd..1e7186dbb 100644 --- a/ci_environment/python/attributes/default.rb +++ b/ci_environment/python/attributes/default.rb @@ -18,14 +18,20 @@ # limitations under the License. # default['python']['pyenv']['revision'] = "cf89abaacff804b7b2047e3ee2ff6df5651b1ce5" + +# Order matters for this list of Pythons. It will be used to construct the +# $PATH so items earlier in the list will take precedence over items later in +# the list. This order means that ``python`` will be 2.7.6, ``python2`` will be +# 2.7.6, and ``python3`` will be 3.4.0. default['python']['pyenv']['pythons'] = [ - "2.6.9", "2.7.6", - "3.2.5", - "3.3.5", + "2.6.9", "3.4.0", + "3.3.5", + "3.2.5", "pypy-2.2.1", ] + default['python']['pyenv']['aliases'] = { "2.6.9" => ["2.6"], "2.7.6" => ["2.7"], @@ -34,6 +40,7 @@ "3.4.0" => ["3.4"], "pypy-2.2.1" => ["pypy"], } + default['python']['pip']['packages'] = { "default" => ["nose", "pytest", "mock"], "2.6" => ["numpy"], diff --git a/ci_environment/python/recipes/pyenv.rb b/ci_environment/python/recipes/pyenv.rb index a0ca2cee2..4da445324 100644 --- a/ci_environment/python/recipes/pyenv.rb +++ b/ci_environment/python/recipes/pyenv.rb @@ -32,15 +32,6 @@ action :create end -# Create a directory to store our "flattened" bins in -directory "/opt/python/bin" do - owner "root" - group "root" - mode "755" - - action :create -end - # Create a directory to store our virtualenvs in directory virtualenv_root do owner node.travis_build_environment.user @@ -50,16 +41,8 @@ action :create end -# Create a profile script that adds our Python bins to the $PATH -file "/etc/profile.d/pyenv.sh" do - owner node.travis_build_environment.user - group node.travis_build_environment.group - mode "0755" - - content "export PATH=/opt/python/bin:$PATH" - - action :create -end +# Store a list of all of our bin dirs +bindirs = Array.new # Install the baked in versions of Python we are offering node.python.pyenv.pythons.each do |py| @@ -79,12 +62,8 @@ }) end - # Add a symlink to /usr/local/bin - link "/opt/python/bin/#{pyname}" do - to "/opt/python/#{py}/bin/python" - owner node.travis_build_environment.user - group node.travis_build_environment.group - end + # Record our bindir + bindirs << "/opt/python/#{py}/bin" # Create our virtualenvs for this python python_virtualenv "python_#{py}" do @@ -104,13 +83,6 @@ pyaliasname = pyalias end - # Add an alias link in our /opt/python/bin directory - link "/opt/python/bin/#{pyaliasname}" do - to "/opt/python/#{py}/bin/python" - owner node.travis_build_environment.user - group node.travis_build_environment.group - end - link "#{virtualenv_root}/#{pyaliasname}" do to "#{virtualenv_root}/#{pyname}" owner node.travis_build_environment.user @@ -131,3 +103,17 @@ group node.travis_build_environment.group end end + +# Create a profile script that adds our Python bins to the $PATH +template "/etc/profile.d/pyenv.sh" do + owner node.travis_build_environment.user + group node.travis_build_environment.group + mode 0755 + + variables({ + :bindirs => bindirs, + }) + + source "pyenv.sh.erb" + backup false +end diff --git a/ci_environment/python/templates/default/pyenv.sh.erb b/ci_environment/python/templates/default/pyenv.sh.erb new file mode 100644 index 000000000..6079c69c3 --- /dev/null +++ b/ci_environment/python/templates/default/pyenv.sh.erb @@ -0,0 +1,2 @@ +# Export the $PATH with the pyenv bindirs prepended to it +export PATH=<%= @bindirs.join(':') %>:$PATH