From 1c3fcd2768900177176bf1556190d4902aa0d61f Mon Sep 17 00:00:00 2001 From: AmirAli Moinfar Date: Sat, 4 Jul 2015 16:23:18 +0430 Subject: [PATCH 1/2] Add support for caching pip packages These directories are chached for pip packages: $HOME/.cache/pip/http $HOME/.cache/pip/wheels --- lib/vagrant-cachier/bucket.rb | 1 + lib/vagrant-cachier/bucket/pip.rb | 22 +++++++++++++++++++ .../cap/linux/pip_cache_dir.rb | 20 +++++++++++++++++ lib/vagrant-cachier/capabilities.rb | 5 +++++ 4 files changed, 48 insertions(+) create mode 100644 lib/vagrant-cachier/bucket/pip.rb create mode 100644 lib/vagrant-cachier/cap/linux/pip_cache_dir.rb diff --git a/lib/vagrant-cachier/bucket.rb b/lib/vagrant-cachier/bucket.rb index ac4e76b..4d392a6 100644 --- a/lib/vagrant-cachier/bucket.rb +++ b/lib/vagrant-cachier/bucket.rb @@ -101,3 +101,4 @@ require_relative "bucket/bower" require_relative "bucket/npm" require_relative "bucket/zypper" require_relative "bucket/generic" +require_relative "bucket/pip" diff --git a/lib/vagrant-cachier/bucket/pip.rb b/lib/vagrant-cachier/bucket/pip.rb new file mode 100644 index 0000000..9be5c47 --- /dev/null +++ b/lib/vagrant-cachier/bucket/pip.rb @@ -0,0 +1,22 @@ +module VagrantPlugins + module Cachier + class Bucket + class Pip < Bucket + def self.capability + :pip_cache_dir + end + + def install + if guest.capability?(:pip_cache_dir) + if guest_path = guest.capability(:pip_cache_dir) + symlink("#{guest_path}/http", "/tmp/vagrant-cache/#{@name}/http") + symlink("#{guest_path}/wheels", "/tmp/vagrant-cache/#{@name}/wheels") + end + else + @env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'pip') + end + end + end + end + end +end diff --git a/lib/vagrant-cachier/cap/linux/pip_cache_dir.rb b/lib/vagrant-cachier/cap/linux/pip_cache_dir.rb new file mode 100644 index 0000000..29408f0 --- /dev/null +++ b/lib/vagrant-cachier/cap/linux/pip_cache_dir.rb @@ -0,0 +1,20 @@ +module VagrantPlugins + module Cachier + module Cap + module Linux + module PipCacheDir + def self.pip_cache_dir(machine) + pip_cache_dir = nil + machine.communicate.tap do |comm| + return unless comm.test('which pip') + comm.execute 'echo $HOME' do |buffer, output| + pip_cache_dir = output.chomp if buffer == :stdout + end + end + return "#{pip_cache_dir}/.cache/pip" + end + end + end + end + end +end diff --git a/lib/vagrant-cachier/capabilities.rb b/lib/vagrant-cachier/capabilities.rb index 277ff37..fab48c2 100644 --- a/lib/vagrant-cachier/capabilities.rb +++ b/lib/vagrant-cachier/capabilities.rb @@ -36,6 +36,11 @@ module VagrantPlugins Cap::Linux::NpmCacheDir end + guest_capability 'linux', 'pip_cache_dir' do + require_relative 'cap/linux/pip_cache_dir' + Cap::Linux::PipCacheDir + end + guest_capability 'debian', 'apt_cache_dir' do require_relative 'cap/debian/apt_cache_dir' Cap::Debian::AptCacheDir From 6deb452f0de092e84b451dc85457cff19ed4e8c8 Mon Sep 17 00:00:00 2001 From: AmirAli Moinfar Date: Sun, 5 Jul 2015 14:30:08 +0430 Subject: [PATCH 2/2] Add documentation for caching pip packages --- docs/buckets/pip.md | 15 +++++++++++++++ docs/template.html | 1 + 2 files changed, 16 insertions(+) create mode 100644 docs/buckets/pip.md diff --git a/docs/buckets/pip.md b/docs/buckets/pip.md new file mode 100644 index 0000000..bfa4a3b --- /dev/null +++ b/docs/buckets/pip.md @@ -0,0 +1,15 @@ +# [pip](https://pip.pypa.io/) + +Compatible with probably any type of linux guest distro, will hook into pip's +http and wheels cache directory under `$HOME/.cache/pip/http` and `$HOME/.cache/pip/wheels` as +the default SSH user (usually `vagrant`) on your guest. + +To manually enable it: + +```ruby +Vagrant.configure("2") do |config| + config.vm.box = 'some-box-with-pip-installed' + config.cache.enable :pip +end +``` + diff --git a/docs/template.html b/docs/template.html index 06b1eca..0bdbcd1 100644 --- a/docs/template.html +++ b/docs/template.html @@ -96,6 +96,7 @@
  • rvm
  • Yum
  • Zypper
  • +
  • pip