Class: Serverspec::Type::Virtualenv
- Inherits:
-
Base
- Object
- Base
- Serverspec::Type::Virtualenv
- Defined in:
- lib/serverspec_extended_types/virtualenv.rb
Instance Method Summary collapse
-
#get_pip_freeze ⇒ nil
private
private
Get a hash for the ‘pip freeze` output; set @pip_freeze.
-
#get_pip_version ⇒ nil
private
private
Get the pip version from the venv; set @pip_version.
-
#get_python_version ⇒ nil
private
private
Get the python version from the venv; set @python_version.
-
#pip_freeze ⇒ Hash
Return a hash of all packages present in ‘pip freeze` output for the venv.
-
#pip_version ⇒ String
Return the version of pip installed in the virtualenv.
-
#python_version ⇒ String
Return the version of python installed in the virtualenv.
-
#virtualenv? ⇒ Boolean
Test whether this appears to be a working venv.
Instance Method Details
#get_pip_freeze ⇒ nil (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get a hash for the ‘pip freeze` output; set @pip_freeze
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/serverspec_extended_types/virtualenv.rb', line 91 def get_pip_freeze() pip_path = ::File.join(@name, 'bin', 'pip') tmp = @runner.run_command("#{pip_path} freeze") @pip_freeze = Hash.new() if tmp.exit_status.to_i != 0 return @pip_freeze end lines = tmp.stdout.split("\n") lines.each do |line| line.strip! if line =~ /^-e / @pip_freeze[line] = '' next end parts = line.split(/==/) @pip_freeze[parts[0]] = parts[1] end @pip_freeze end |
#get_pip_version ⇒ nil (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get the pip version from the venv; set @pip_version
116 117 118 119 120 121 122 123 124 125 |
# File 'lib/serverspec_extended_types/virtualenv.rb', line 116 def get_pip_version() pip_path = ::File.join(@name, 'bin', 'pip') pip_path = ::File.join(@name, 'bin', 'pip') tmp = @runner.run_command("#{pip_path} --version") if ( tmp.stdout =~ /^pip (\d+\S+)/ ) @pip_version = $1 else @pip_version = '' end end |
#get_python_version ⇒ nil (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get the python version from the venv; set @python_version
132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/serverspec_extended_types/virtualenv.rb', line 132 def get_python_version() python_path = ::File.join(@name, 'bin', 'python') tmp = @runner.run_command("#{python_path} --version") if ( tmp.stderr =~ /^[Pp]ython (\d+\S+)/ ) @python_version = $1 elsif ( tmp.stdout =~ /^[Pp]ython (\d+\S+)/ ) @python_version = $1 else @python_version = '' end end |
#pip_freeze ⇒ Hash
Return a hash of all packages present in ‘pip freeze` output for the venv
Note that any editable packages (‘-e something`) are returned as hash keys with an empty value
82 83 84 |
# File 'lib/serverspec_extended_types/virtualenv.rb', line 82 def pip_freeze @pip_freeze || get_pip_freeze end |
#pip_version ⇒ String
Return the version of pip installed in the virtualenv
50 51 52 |
# File 'lib/serverspec_extended_types/virtualenv.rb', line 50 def pip_version @pip_version || get_pip_version end |
#python_version ⇒ String
Return the version of python installed in the virtualenv
63 64 65 |
# File 'lib/serverspec_extended_types/virtualenv.rb', line 63 def python_version @python_version || get_python_version end |
#virtualenv? ⇒ Boolean
Test whether this appears to be a working venv
Tests performed:
-
venv_path/bin/pip executable by owner?
-
venv_path/bin/python executable by owner?
-
venv_path/bin/activate readable by owner?
-
‘export VIRTUAL_ENV’ in venv_path/bin/activate?
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/serverspec_extended_types/virtualenv.rb', line 30 def virtualenv? pip_path = ::File.join(@name, 'bin', 'pip') python_path = ::File.join(@name, 'bin', 'python') act_path = ::File.join(@name, 'bin', 'activate') cmd = "grep -q 'export VIRTUAL_ENV' #{act_path}" @runner.check_file_is_executable(pip_path, 'owner') and @runner.check_file_is_executable(python_path, 'owner') and @runner.check_file_is_readable(act_path, 'owner') and @runner.run_command(cmd).exit_status.to_i == 0 end |