Module: Opener::BuildTools::Python

Defined in:
lib/opener/build-tools/python.rb

Overview

Module that contains various helper methods for dealing with Python, Pip and other Python tools.

Class Method Summary collapse

Class Method Details

.install_python_packages(requirements, directory) ⇒ Object

Installs a set of Python packages in a given directory based on a requirements file. If the directory is not empty this process is aborted.

Parameters:

  • file (String)

    The requirements file to install.

  • directory (String)

    The name of the directory to install the packages into.



52
53
54
55
56
# File 'lib/opener/build-tools/python.rb', line 52

def install_python_packages(requirements, directory)
  return unless directory_contents(directory).empty?

  pip_install(requirements, directory)
end

.pip_install(file, target) ⇒ Object

Installs the packages in the requirements file in a specific directory.

Parameters:

  • file (String)

    The requirements file to use.

  • target (String)

    The target directory to install packages in.



36
37
38
39
40
41
# File 'lib/opener/build-tools/python.rb', line 36

def pip_install(file, target)
  Rake::FileUtilsExt.sh(
    "pip install --requirement=#{file} --target=#{target} " \
      "--ignore-installed"
  )
end

.pip_versionString

Returns a String containing the Pip version in a RubyGems compatible format.

Returns:

  • (String)


26
27
28
# File 'lib/opener/build-tools/python.rb', line 26

def pip_version
  return `pip --version 2>&1`.match(/pip\s+([\d\.]+)/)[1].chomp('.')
end

.python_versionString

Returns a String containing the Python version. This only includes the numerical value, the prefix “Python ” is not included.

Returns:

  • (String)


16
17
18
# File 'lib/opener/build-tools/python.rb', line 16

def python_version
  return `python --version 2>&1`.split(/([\d\.]+)/)[1]
end