Class: FPM::Source::Python
- Inherits:
-
FPM::Source
- Object
- FPM::Source
- FPM::Source::Python
- Defined in:
- lib/fpm/source/python.rb
Instance Attribute Summary
Attributes inherited from FPM::Source
Class Method Summary collapse
Instance Method Summary collapse
-
#download(package, version = nil) ⇒ Object
def get_source.
-
#garbage ⇒ Object
def make_tarball!.
-
#get_metadata ⇒ Object
def download.
-
#get_source(params) ⇒ Object
def flags.
-
#make_tarball!(tar_path, builddir) ⇒ Object
def get_metadata.
Methods inherited from FPM::Source
#[], #[]=, #dependencies, #initialize, #metadata, #package
Constructor Details
This class inherits a constructor from FPM::Source
Class Method Details
.flags(opts, settings) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/fpm/source/python.rb', line 10 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 |
Instance Method Details
#download(package, version = nil) ⇒ Object
def get_source
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/fpm/source/python.rb', line 40 def download(package, version=nil) 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 return_value = system(self[:settings][:easy_install], "--editable", "--build-directory", @tmpdir, want_pkg) if return_value.nil? raise "The execution of #{self[:settings][:easy_install]} failed" end # easy_install will put stuff in @tmpdir/packagename/, flatten that. # That is, we want @tmpdir/setup.py, and start with # @tmpdir/somepackage/setup.py dirs = ::Dir.glob(File.join(@tmpdir, "*")) if dirs.length != 1 raise "Unexpected directory layout after easy_install. Maybe file a bug? The directory is #{@tmpdir}" end @paths = dirs end |
#garbage ⇒ Object
def make_tarball!
116 117 118 119 120 |
# File 'lib/fpm/source/python.rb', line 116 def garbage trash = [] trash << @tmpdir if @tmpdir return trash end |
#get_metadata ⇒ Object
def download
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/fpm/source/python.rb', line 66 def setup_py = @paths.first if File.directory?(setup_py) setup_py = File.join(setup_py, "setup.py") @paths = [setup_py] end if !File.exists?(setup_py) raise "Unable to find python package; tried #{setup_py}" end pylib = File.(File.dirname(__FILE__)) 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 = JSON.parse(output[/\{.*\}/msx]) #p metadata self[:architecture] = ["architecture"] self[:description] = ["description"] self[:license] = ["license"] self[:version] = ["version"] self[:name] = "python#{self[:suffix]}-#{metadata["name"]}" self[:url] = ["url"] self[:dependencies] = ["dependencies"].collect do |dep| name, cmp, version = dep.split "python#{self[:suffix]}-#{name} #{cmp} #{version}" end end |
#get_source(params) ⇒ Object
def flags
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/fpm/source/python.rb', line 25 def get_source(params) package = @paths.first if ["setup.py", "."].include?(package) # Assume we're building from an existing python package. # Source already acquired, nothing to do! return end if !File.exists?(package) download(package, params[:version]) else @paths = [ File.(package) ] end end |
#make_tarball!(tar_path, builddir) ⇒ Object
def get_metadata
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/fpm/source/python.rb', line 97 def make_tarball!(tar_path, builddir) setup_py = @paths.first dir = File.dirname(setup_py) # Some setup.py's assume $PWD == current directory of setup.py, so let's # chdir first. ::Dir.chdir(dir) do system(self[:settings][:python], "setup.py", "bdist") end dist_tar = ::Dir.glob(File.join(dir, "dist", "*.tar.gz")).first puts "Found dist tar: #{dist_tar}" puts "Copying to #{tar_path}" @paths = [ "." ] system("cp", dist_tar, "#{tar_path}.gz") end |