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

Add --gui-script flag for running Python scripts with pythonw.exe on … #9152

Open
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

rajko-rad
Copy link

Addresses #6805

Summary

This PR adds a --gui-script flag to uv run that allows running Python scripts with pythonw.exe on Windows, regardless of file extension. This solves the issue where users need to maintain duplicate .py and .pyw files to run the same script with and without a console window.

The implementation follows the pattern established by the existing --script flag, but uses pythonw.exe instead of python.exe on Windows. On non-Windows platforms, the flag is present but returns an error indicating it's Windows-only functionality.

Changes:

  • Added --gui-script flag (Windows-only)
  • Added Windows test to verify GUI script behavior
  • Added non-Windows test to verify proper error message
  • Updated CLI documentation

Test Plan

The changes are tested through:

  1. New Windows-specific test that verifies:

    • Script runs successfully with pythonw.exe when using --gui-script
    • Console output is suppressed in GUI mode but visible in regular mode
    • Same script can be run both ways without modification
  2. New non-Windows test that verifies:

    • Appropriate error message when --gui-script is used on non-Windows platforms
  3. Documentation updates to clearly indicate Windows-only functionality

@zanieb zanieb self-assigned this Nov 15, 2024
@konstin konstin requested a review from zanieb November 15, 2024 15:00
@zanieb
Copy link
Member

zanieb commented Nov 15, 2024

You can add an ignore for that Clippy complaint, if you want — or we will. We generally take our time about splitting those bools out into a struct.

sys.exit(1)
"#})?;

let output = context.run().arg("--script").arg("script").output()?;
Copy link
Member

Choose a reason for hiding this comment

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

Should this be using --gui-script?

Copy link
Collaborator

@samypr100 samypr100 Nov 21, 2024

Choose a reason for hiding this comment

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

Agreed, but would this pass with exit code 0 on a headless windows CI run?

Copy link
Author

Choose a reason for hiding this comment

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

you are right, and I'm slightly confused why/how we passed tests with that typo... Changing now and will see how it behaves!

@zanieb
Copy link
Member

zanieb commented Nov 18, 2024

Nice! I made some minor tweaks and have one blocking question.

@samypr100 samypr100 added the windows Specific to the Windows platform label Nov 21, 2024
@rajko-rad
Copy link
Author

You can add an ignore for that Clippy complaint, if you want — or we will. We generally take our time about splitting those bools out into a struct.

Perfect thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
windows Specific to the Windows platform
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants