Skip to content
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

Merged
merged 4 commits into from
Mar 29, 2018
Merged

Pw/pip windows bug #2883

merged 4 commits into from
Mar 29, 2018

Conversation

pwelch
Copy link
Contributor

@pwelch pwelch commented Mar 27, 2018

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

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.
@pwelch pwelch requested a review from a team as a code owner March 27, 2018 15:16
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]>
@pwelch pwelch force-pushed the pw/pip-windows-bug branch from 350cd78 to 161ddf3 Compare March 27, 2018 15:28
Copy link
Contributor

@jquick jquick left a 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.

end

def cmd_successful?
result = inspec.command("#{@pip_cmd} show #{@package_name}")
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

# {"Pip" => nil, "Python" => "/path/to/python"}
#
# @return [Hash] of paths
def paths
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jquick good catch! Thanks!

Copy link
Contributor

@TrevorBramble TrevorBramble left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some nitpicks

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?
Copy link
Contributor

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?

end

def cmd_successful?
result = cmd
Copy link
Contributor

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?)

# @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')
Copy link
Contributor

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(' | '))

@pwelch
Copy link
Contributor Author

pwelch commented Mar 28, 2018

@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]>
@pwelch pwelch force-pushed the pw/pip-windows-bug branch from 653542b to 860c951 Compare March 28, 2018 17:07
Copy link
Contributor

@jquick jquick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @pwelch !

@jquick
Copy link
Contributor

jquick commented Mar 29, 2018

Confirmed commit was signed. DCO bot is bugged.

@jquick jquick merged commit d3b90a7 into master Mar 29, 2018
@jquick jquick added the Type: Bug Feature not working as expected label Mar 29, 2018
@jquick jquick deleted the pw/pip-windows-bug branch March 29, 2018 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Feature not working as expected
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants