Skip to content

Commit

Permalink
- Add new flags for the python source:
Browse files Browse the repository at this point in the history
  --python-bin - path to the python binary you want to run
  --python-easyinstall - path to the easy_install script you want to use
  jordansissel#38
  • Loading branch information
jordansissel committed May 18, 2011
1 parent 6905fb5 commit 07e0b7e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
2 changes: 2 additions & 0 deletions lib/fpm/program.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions lib/fpm/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ def initialize(paths, root, params={})
@root = root

self[:suffix] = params[:suffix]
self[:settings] = params[:settings]

get_source(params)
get_metadata

Expand Down
1 change: 1 addition & 0 deletions lib/fpm/source/gem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
25 changes: 21 additions & 4 deletions lib/fpm/source/python.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -23,15 +38,17 @@ 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?
want_pkg = "#{package}"
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
Expand All @@ -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])
Expand All @@ -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
Expand Down

0 comments on commit 07e0b7e

Please sign in to comment.