Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f6d0837

Browse files
committed
Fix version detection (setuptools and distribute)
The versions of `distribute`, `pip`, `setuptools` and `wsgiref` are excluded from the output of `pip freeze`, however they do show up in the output from `pip list`. This allows us to use a more general implentation of parsing the output from `pip list` to get the current version of all distributions. Also removes a dependency on `grep`. Distributions excluded from `pip freeze`: /pypa/pip/blob/2ad8888901c041b8f9aacebb3a16d55bf631e867/pip/util.py#L372
1 parent 574ad93 commit f6d0837

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

providers/pip.rb

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,13 @@ def load_current_resource
106106

107107
def current_installed_version
108108
@current_installed_version ||= begin
109-
delimeter = /==/
110-
111-
normalized_package_name = new_resource.package_name.gsub('_', '-')
112-
version_check_cmd = "#{which_pip(new_resource)} freeze | grep -i '^#{normalized_package_name}=='"
113-
# incase you upgrade pip with pip!
114-
if new_resource.package_name.eql?('pip')
115-
delimeter = /\s/
116-
version_check_cmd = "#{which_pip(@new_resource)} --version"
109+
out = nil
110+
package_name = new_resource.package_name.gsub('_', '-')
111+
pattern = Regexp.new("^#{Regexp.escape(package_name)} \\(([^)]+)\\)$", true)
112+
shell_out("#{which_pip(new_resource)} list").stdout.lines.find do |line|
113+
out = pattern.match(line)
117114
end
118-
result = shell_out(version_check_cmd)
119-
(result.exitstatus == 0) ? result.stdout.split(delimeter)[1].strip : nil
115+
out.nil? ? nil : out[1]
120116
end
121117
end
122118

0 commit comments

Comments
 (0)