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
-
.install_python_packages(requirements, directory) ⇒ Object
Installs a set of Python packages in a given directory based on a requirements file.
-
.pip_install(file, target) ⇒ Object
Installs the packages in the requirements file in a specific directory.
-
.pip_version ⇒ String
Returns a String containing the Pip version in a RubyGems compatible format.
-
.python_version ⇒ String
Returns a String containing the Python version.
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.
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.
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_version ⇒ String
Returns a String containing the Pip version in a RubyGems compatible format.
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_version ⇒ String
Returns a String containing the Python version. This only includes the numerical value, the prefix “Python ” is not included.
16 17 18 |
# File 'lib/opener/build-tools/python.rb', line 16 def python_version return `python --version 2>&1`.split(/([\d\.]+)/)[1] end |