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

Fix test_shutils when there is “python3” but no “python” #31

Merged

Conversation

musicinmybrain
Copy link
Contributor

@musicinmybrain musicinmybrain commented May 24, 2022

This allows the tests to pass in environments where the Python interpreter has some other name, such as “python3”.

This allows the tests to pass in environments where there is a “python3” but no “python” in the executable search path.

@mmckerns
Copy link
Member

Can you clarify what your intended changes are doing, or what errors you may be seeing to trigger your changes?

The intent of which('python') is not to find the current interpreter being used. It's to find the path to the first (or all) executables named "python" in the user's PATH. So, if I was running python 3.10, and had several instances of python installed (including multiple instances of 3.10), I might expect results like these:

>>> from pox import *
>>> which('python')
'/usr/bin/python'
>>> which('python3')
'/opt/local/Library/Frameworks/Python.framework/Versions/3.10/bin/python3'
>>> which('python3.10')
'/opt/local/bin/python3.10'
>>>
>>> which_python()
'/opt/local/bin/python3.10'

The last case, using which_python is intended to find the version/path for the current executable.

@musicinmybrain
Copy link
Contributor Author

When building RPMs for Fedora Linux, there is no executable called python in the PATH in the build environment—only python3. (Installed systems typically, but not necessarily, have /usr/bin/python provided by the python-unversioned-command RPM.) This means the tests fail when building a python-pox RPM.

My idea was that, if the test suite is invoked with something like /usr/bin/python3, then searching for python3 will work even if there is no /usr/bin/python.

If you don’t think this makes sense, we can always keep skipping the test in the RPM build, or carry a simpler downstream-only patch that simply replaces each 'python' string in this test with 'python3'.

@mmckerns
Copy link
Member

Ah... ok. I see, that's a case I didn't plan for. How about something like this:

python = 'python' if which('python') else 'python3'
assert which(python).endswith((python,'python.exe'))
assert which(python) in which(python,all=True)

You can update the PR if that works for you.

@musicinmybrain
Copy link
Contributor Author

Thanks for the suggestion. I will update the PR.

This allows the tests to pass in environments where there is a “python3”
but no “python” in the executable search path.
@musicinmybrain musicinmybrain changed the title Fix test_shutils on Python interpreters not called “python” Fix test_shutils when there is “python3” but no “python” May 25, 2022
@mmckerns mmckerns added this to the pox-0.3.2 milestone May 25, 2022
@mmckerns mmckerns merged commit 33290e4 into uqfoundation:master May 25, 2022
@musicinmybrain
Copy link
Contributor Author

Thanks!

@mmckerns
Copy link
Member

thank you for the PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants