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

Explicit fail when python executable is not found #1236

Merged

Conversation

aboellinger
Copy link
Contributor

Problem

We have found ourselves in a situation where during a call to find_pip_from_context, find_python_in_context(context) returns None, resulting in the creation and execution of an invalid command (with None provided as an executable path). This ends up breaking downstream in subprocess with an obscure message.

Solution

Raise an explicit error if the executable is not located, before we try to run it.

src/rez/pip.py Outdated
@@ -202,6 +202,9 @@ def find_pip_from_context(python_version, pip_version=None):

py_exe = find_python_in_context(context)

if not py_exe:
raise RezSystemError("Failed to locate Python executable from context {}".format(context))

Choose a reason for hiding this comment

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

I think returning early like return None, None, context would be slightly better. That's because of the way the function is called: https://github.com/nerdvegas/rez/blob/master/src/rez/pip.py#L92-L101.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, took me a while but I think I see what you mean.
This way we keep on with the logic of find_pip, hoping that we actually find a valid executable later.

I'll change that right away.

src/rez/pip.py Outdated
@@ -202,6 +202,10 @@ def find_pip_from_context(python_version, pip_version=None):

py_exe = find_python_in_context(context)

if not py_exe:
print_debug("Failed to locate python executable from context")

Choose a reason for hiding this comment

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

This log might be redundant I think. The _check_found function already logs when something isn't found and I also have a personal preference to let the caller log instead of letting the callee (find_pip_from_context) log.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright, to me the log seemed consistent with code above and also acted as a comment for the return statement.

But I am fine with removing it.

Fixed in 2a64909

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

Copy link
Member

@JeanChristopheMorinPerso JeanChristopheMorinPerso left a comment

Choose a reason for hiding this comment

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

Thanks for the fix @aboellinger!

@nerdvegas nerdvegas merged commit b9cd152 into AcademySoftwareFoundation:master Feb 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants