-
Notifications
You must be signed in to change notification settings - Fork 679
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pw/pip windows bug #2883
Pw/pip windows bug #2883
Conversation
When checking pip resources, we should skip resource if python is not installed or we will fail with an error when trying to parse the path.
On Windows, if pip has a newer version available, it adds an error message to stderr. Now checking if both stderr and stdout on windows have values. If so, assume pip package is installed. Fixes #2855 Signed-off-by: Paul Welch <[email protected]>
350cd78
to
161ddf3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really nice work here @pwelch ! Just a few comments.
lib/resources/pip.rb
Outdated
end | ||
|
||
def cmd_successful? | ||
result = inspec.command("#{@pip_cmd} show #{@package_name}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we just use cmd
here instead of doing the inspec.command
again?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
lib/resources/pip.rb
Outdated
# {"Pip" => nil, "Python" => "/path/to/python"} | ||
# | ||
# @return [Hash] of paths | ||
def paths |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mind updating this to windows_paths
. Since its windows only command it may read better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jquick good catch! Thanks!
Signed-off-by: Paul Welch <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some nitpicks
lib/resources/pip.rb
Outdated
end | ||
|
||
def info | ||
return @info if defined?(@info) | ||
|
||
@info = {} | ||
@info[:type] = 'pip' | ||
cmd = inspec.command("#{@pip_cmd} show #{@package_name}") | ||
return @info if cmd.exit_status != 0 | ||
return @info if !cmd_successful? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return @info unless cmd_successful?
lib/resources/pip.rb
Outdated
end | ||
|
||
def cmd_successful? | ||
result = cmd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like every instance of result
in this method could just be cmd
? (And would actually read better that way?)
lib/resources/pip.rb
Outdated
# @return [Hash] of windows_paths | ||
def windows_paths | ||
return @__windows_paths if @__windows_paths | ||
cmd = inspec.command('New-Object -Type PSObject | Add-Member -MemberType NoteProperty -Name Pip -Value (Invoke-Command -ScriptBlock {where.exe pip}) -PassThru | Add-Member -MemberType NoteProperty -Name Python -Value (Invoke-Command -ScriptBlock {where.exe python}) -PassThru | ConvertTo-Json') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we break this out onto multiple lines?
cmd = inspec.command(
'New-Object -Type PSObject' \
' | Add-Member -MemberType NoteProperty -Name Pip -Value (Invoke-Command -ScriptBlock {where.exe pip}) -PassThru' \
' | Add-Member -MemberType NoteProperty -Name Python -Value (Invoke-Command -ScriptBlock {where.exe python}) -PassThru' \
' | ConvertTo-Json')
or better...
cmd = inspec.command([
'New-Object -Type PSObject',
'Add-Member -MemberType NoteProperty -Name Pip -Value (Invoke-Command -ScriptBlock {where.exe pip}) -PassThru',
'Add-Member -MemberType NoteProperty -Name Python -Value (Invoke-Command -ScriptBlock {where.exe python}) -PassThru',
'ConvertTo-Json'
].join(' | '))
@TrevorBramble changes for feedback applied. |
- Make it easier to read what the powershell command is doing - Make it easier to read what the cmd_successful method lokos for Signed-off-by: Paul Welch <[email protected]>
653542b
to
860c951
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @pwelch !
Confirmed commit was signed. DCO bot is bugged. |
When pip on windows has a newer version available it spits out a stderr message along with the results of the
pip show
command.This adds logic to ignore the pip message that there is a newer version.
Fixes #2855