-
Notifications
You must be signed in to change notification settings - Fork 42
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
Add frozen environment support #238
base: master
Are you sure you want to change the base?
Conversation
for more information, see https://pre-commit.ci
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.
Any idea how we could test this in automation, it may easily break if we have no test for it
Yes, let me explain how it would differenciate for regular testing: For a 'normal' run (meaning it would run perfectly without this PR and with the PR also works perfectly still) just create any test you want in a separate file (insert prints or write to files inside of them so you can debug if they ran or not), then pip install pytest xdist then start from a main.py file a call to pytest.main such as:
Run via command line as usual with The issue then arises when you compile into a pyinstaller single .exe where it no longer works, the expected debug print/file write will not happen and errors will arise, usually it opens a second .exe instead (related to trying to open sys.executable I assume). Basically just open the .exe and it should execute the code of main.py and it does but the pytest.main'' call doesn't execute properly as you will be able to test yourself. For a run with this PR if you run normally it will still work without any kind of issues and the difference comes when ran with the pyinstaller single .exe, it will work perfectly aswell just by changing the execnet source code with this PR and without making any other changes. To compile the On there the pytest-xdist folder is just a copy of: https://github.com/pytest-dev/pytest-xdist/tree/master/src/xdist so feel free to download yourself if you want. On that directory run Let me know if you need any extra details. |
@AlexPaiva I think @RonnyPfannschmidt just meant that we need to add tests to For that, we need some tests:
|
@@ -18,6 +18,9 @@ | |||
class Popen2IOMaster(Popen2IO): | |||
def __init__(self, args, execmodel): | |||
PIPE = execmodel.subprocess.PIPE | |||
if is_frozen_environment(): | |||
args[0] = str(sys.executable) |
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.
I don't think this is correct, we should not be mutating the input arguments like this, nor assuming the first argument is the interpreter. This class is public, and even if it was not the case, this is certainly surprising behavior.
Clients of this class should instead use sys.executable
instead of just "python"
, for example here: https://github.com/AlexPaiva/execnet/blob/227da4174e349b0cc198619b5fd186c6f137df82/src/execnet/gateway_io.py#L86C5-L86C43
def get_python_executable(): | ||
"""Get the correct Python interpreter path.""" | ||
if is_frozen_environment(): | ||
return os.environ.get("PYTHON_EXECUTABLE", "python") |
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.
As I mentioned, not clear to me why this is needed, seems to me we should always return sys.executable
from here?
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.
Besides my comments, I think we should at least document things a bit, even if we decide to mark this workflow as experimental.
Sorry on the late reply, was very busy! |
Yes. 👍 |
The goal was to leave the entire thing as it was and only change when it's a frozen env, especially for testing. |
Fixes #237
Fixes pytest-dev/pytest-xdist#991
Adds support for frozen environments such as pyinstaller, with proper imports on the pyinstaller side this change will work, tested with pytest and pytest-xdist.
Extra documentation available on both the mentioned issues.