From 07e0b7eaa3f67fdf1f793a8a47474dcb077cd9a1 Mon Sep 17 00:00:00 2001 From: "jls@semicomplete.com" Date: Wed, 18 May 2011 08:08:35 +0000 Subject: [PATCH] - Add new flags for the python source: --python-bin - path to the python binary you want to run --python-easyinstall - path to the easy_install script you want to use https://github.com/jordansissel/fpm/issues/38 --- lib/fpm/program.rb | 2 ++ lib/fpm/source.rb | 2 ++ lib/fpm/source/gem.rb | 1 + lib/fpm/source/python.rb | 25 +++++++++++++++++++++---- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/lib/fpm/program.rb b/lib/fpm/program.rb index 5a33f2b443..0900f2c460 100644 --- a/lib/fpm/program.rb +++ b/lib/fpm/program.rb @@ -54,6 +54,8 @@ def options(args) # Add extra flags from plugins FPM::Source::Gem.flags(FPM::Flags.new(opts, "gem", "gem source only"), @settings) + FPM::Source::Python.flags(FPM::Flags.new(opts, "python", "python source only"), + @settings) # Process fpmrc first fpmrc(opts) diff --git a/lib/fpm/source.rb b/lib/fpm/source.rb index 47beeb00e8..cd32b9ce45 100644 --- a/lib/fpm/source.rb +++ b/lib/fpm/source.rb @@ -29,6 +29,8 @@ def initialize(paths, root, params={}) @root = root self[:suffix] = params[:suffix] + self[:settings] = params[:settings] + get_source(params) get_metadata diff --git a/lib/fpm/source/gem.rb b/lib/fpm/source/gem.rb index b230db04ab..6fc57a811e 100644 --- a/lib/fpm/source/gem.rb +++ b/lib/fpm/source/gem.rb @@ -119,6 +119,7 @@ def make_tarball!(tar_path, builddir) ::FileUtils.mkdir_p(installdir) args = ["gem", "install", "--quiet", "--no-ri", "--no-rdoc", "--install-dir", installdir, "--ignore-dependencies"] + p :make_tarball => metadata if self[:settings][:bin_path] args += ["--bindir", File.join(tmpdir, self[:settings][:bin_path])] @paths << self[:settings][:bin_path] diff --git a/lib/fpm/source/python.rb b/lib/fpm/source/python.rb index 8010bfafdf..ca0ec78c54 100644 --- a/lib/fpm/source/python.rb +++ b/lib/fpm/source/python.rb @@ -7,6 +7,21 @@ require "json" class FPM::Source::Python < FPM::Source + def self.flags(opts, settings) + settings.source[:python] = "python" + settings.source[:easy_install] = "easy_install" + + opts.on("--bin PYTHON_BINARY_LOCATION", + "The path to the python you want to run. Default is 'python'") do |path| + settings.source[:python] = path + end + + opts.on("--easyinstall EASY_INSTALL_PATH", + "The path to your easy_install tool. Default is 'easy_install'") do |path| + settings.source[:easy_install] = path + end + end # def flags + def get_source(params) package = @paths.first if ["setup.py", "."].include?(package) @@ -23,7 +38,8 @@ def get_source(params) end # def get_source def download(package, version=nil) - puts "Trying to download #{package} (using easy_install)" + p metadata + puts "Trying to download #{package} (using: #{self[:settings][:easy_install]})" @tmpdir = ::Dir.mktmpdir("python-build", ::Dir.pwd) if version.nil? @@ -31,7 +47,8 @@ def download(package, version=nil) else want_pkg = "#{package}==#{version}" end - system("easy_install", "--editable", "--build-directory", @tmpdir, want_pkg) + + system(self[:settings][:easy_install], "--editable", "--build-directory", @tmpdir, want_pkg) # easy_install will put stuff in @tmpdir/packagename/, flatten that. # That is, we want @tmpdir/setup.py, and start with @@ -55,7 +72,7 @@ def get_metadata end pylib = File.expand_path(File.dirname(__FILE__)) - setup_cmd = "env PYTHONPATH=#{pylib} python #{setup_py} --command-packages=pyfpm get_metadata" + setup_cmd = "env PYTHONPATH=#{pylib} #{self[:settings][:python]} #{setup_py} --command-packages=pyfpm get_metadata" output = ::Dir.chdir(File.dirname(setup_py)) { `#{setup_cmd}` } puts output metadata = JSON.parse(output[/\{.*\}/msx]) @@ -81,7 +98,7 @@ def make_tarball!(tar_path, builddir) # Some setup.py's assume $PWD == current directory of setup.py, so let's # chdir first. ::Dir.chdir(dir) do - system("python", "setup.py", "bdist") + system(self[:settings][:python], "setup.py", "bdist") end dist_tar = ::Dir.glob(File.join(dir, "dist", "*.tar.gz")).first