From 5b5fbc6b14d624e1175812b85180e1279c71cbcf Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Fri, 17 May 2013 18:15:40 -0400 Subject: [PATCH] Fingerprint the filenames in site-packages to decide when to install requirements. --- rakefiles/helpers.rb | 2 +- rakefiles/prereqs.rake | 24 ++++++++++++++---------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/rakefiles/helpers.rb b/rakefiles/helpers.rb index 4c4d400b8a..eef93538eb 100644 --- a/rakefiles/helpers.rb +++ b/rakefiles/helpers.rb @@ -16,7 +16,7 @@ end def when_changed(unchanged_message, *files) Rake::Task[PREREQS_MD5_DIR].invoke - cache_file = File.join(PREREQS_MD5_DIR, files.join('-').gsub(/\W+/, '-')) + '.md5' + cache_file = File.join(PREREQS_MD5_DIR, files[0].gsub(/\W+/, '-').sub(/-+$/, '') + '.md5' digest = Digest::MD5.new() Dir[*files].select{|file| File.file?(file)}.each do |file| digest.file(file) diff --git a/rakefiles/prereqs.rake b/rakefiles/prereqs.rake index ef4958e9d7..782bbb9d99 100644 --- a/rakefiles/prereqs.rake +++ b/rakefiles/prereqs.rake @@ -1,5 +1,5 @@ require './rakefiles/helpers.rb' - +require 'tempfile' PREREQS_MD5_DIR = ENV["PREREQ_CACHE_DIR"] || File.join(REPO_ROOT, '.prereqs_cache') @@ -28,15 +28,19 @@ end desc "Install all python prerequisites for the lms and cms" task :install_python_prereqs => "ws:migrate" do - unchanged = 'Python requirements unchanged, nothing to install' - when_changed(unchanged, 'requirements/**/*') do - ENV['PIP_DOWNLOAD_CACHE'] ||= '.pip_download_cache' - sh('pip install --exists-action w -r requirements/edx/base.txt') - sh('pip install --exists-action w -r requirements/edx/post.txt') - # Check for private-requirements.txt: used to install our libs as working dirs, - # or personal-use tools. - if File.file?("requirements/private.txt") - sh('pip install -r requirements/private.txt') + Tempfile.open('pyinstalled') do |pyinstalled| + # Read the names of everything in site-packages, and include them in the fingerprint. + sh("python -c 'import os; import distutils.sysconfig as dusc; print sorted(os.listdir(dusc.get_python_lib()))' > #{pyinstalled.path}") + unchanged = 'Python requirements unchanged, nothing to install' + when_changed(unchanged, 'requirements/**/*', pyinstalled.path) do + ENV['PIP_DOWNLOAD_CACHE'] ||= '.pip_download_cache' + sh('pip install --exists-action w -r requirements/edx/base.txt') + sh('pip install --exists-action w -r requirements/edx/post.txt') + # requirements/private.txt is used to install our libs as + # working dirs, or for personal-use tools. + if File.file?("requirements/private.txt") + sh('pip install -r requirements/private.txt') + end end end unless ENV['NO_PREREQ_INSTALL'] end