class Autobuild::Python

Handler class to build python-based packages

Attributes

buildflags[RW]
installflags[RW]

Public Class Methods

new(options) click to toggle source
Calls superclass method Autobuild::Configurable::new
# File lib/autobuild/packages/python.rb, line 18
def initialize(options)
    @buildflags = []
    @installflags = []
    super
end
user_site(prefix) click to toggle source
# File lib/autobuild/packages/python.rb, line 53
def self.user_site(prefix)
    return File.join(prefix, @user_site) if @user_site

    begin
        env = Autobuild.env.resolved_env.merge({ 'PYTHONUSERBASE' => "/" })
        _, output, _, ret = Open3.popen3(env, 'python -m site --user-site')
    rescue Exception => e
        raise "Unable to set PYTHONPATH: #{e.message}"
    end

    if ret.value.success?
        @user_site = Pathname.new(output.read.chomp)
                             .relative_path_from(Pathname.new("/"))
        File.join(prefix, @user_site)
    else
        raise 'Unable to set PYTHONPATH: user site directory disabled?'
    end
end

Public Instance Methods

build() click to toggle source

Do the build in builddir

# File lib/autobuild/packages/python.rb, line 77
def build
    return unless install_mode?

    command = generate_build_command
    command << '--force' if @forced
    progress_start 'building %s [progress not available]',
                   done_message: 'built %s' do
        run 'build', *command, working_directory: srcdir
    end
    Autobuild.touch_stamp(buildstamp)
end
configurestamp() click to toggle source
# File lib/autobuild/packages/python.rb, line 14
def configurestamp
    "#{builddir}/configure-autobuild-stamp"
end
generate_build_command() click to toggle source
# File lib/autobuild/packages/python.rb, line 33
def generate_build_command
    command = %w[python setup.py]
    command << "egg_info"
    command << "--egg-base=#{builddir}"
    command << "build"
    command << "--build-base=#{builddir}"
    command += buildflags.flatten
    command
end
generate_install_command() click to toggle source
# File lib/autobuild/packages/python.rb, line 43
def generate_install_command
    command = generate_build_command
    command << 'install'
    command << "--prefix=#{prefix}"
    command << "--record=#{builddir}/install.log"
    command << "--single-version-externally-managed"
    command += installflags.flatten
    command
end
install() click to toggle source

Install the result in prefix

Calls superclass method
# File lib/autobuild/packages/python.rb, line 90
def install
    return unless install_mode?

    command = generate_install_command
    command << '--force' if @forced
    progress_start 'installing %s',
                   done_message: 'installed %s' do
        run 'install', *command, working_directory: srcdir
    end
    super
end
install_mode?() click to toggle source
# File lib/autobuild/packages/python.rb, line 24
def install_mode?
    File.file?(File.join(srcdir, 'setup.py'))
end
prepare_for_forced_build() click to toggle source
# File lib/autobuild/packages/python.rb, line 28
def prepare_for_forced_build
    super
    @forced = true
end
python_path() click to toggle source
# File lib/autobuild/packages/python.rb, line 72
def python_path
    self.class.user_site(prefix)
end
update_environment() click to toggle source
Calls superclass method
# File lib/autobuild/packages/python.rb, line 102
def update_environment
    super
    path = install_mode? ? python_path : srcdir
    env_add_path 'PYTHONPATH', path
end