-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 an option to uv run
to run a .py
script with pythonw.exe
instead of python.exe
#6805
Labels
cli
Related to the command line interface
enhancement
New feature or improvement to existing functionality
good first issue
Good for newcomers
Comments
zanieb
added
cli
Related to the command line interface
enhancement
New feature or improvement to existing functionality
labels
Aug 29, 2024
We could parse the metadata with |
We added a |
zanieb
added a commit
that referenced
this issue
Dec 10, 2024
#9152) 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 --------- Co-authored-by: Zanie Blue <contact@zanie.dev>
Yep this is implemented, sorry! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
cli
Related to the command line interface
enhancement
New feature or improvement to existing functionality
good first issue
Good for newcomers
I am using
uv run
for a simple Python script with inline dependencies.This script is used in two ways/environments.
First, it is run from the console. In this case, it should be run using
python.exe
, thus showing stout/stderr on the console.Second, the same script is run by the Windows 11 Task Scheduler. In this case, I would like to use the windowless
pythonw.exe
to run the script without opening another window.Currently, the only way to get
uv run
to choose either one or the other interpreter, is by naming the script eithermyscript.py
ormyscript.pyw
.In other words, I have to maintain two otherwise identical copies of the same script.
There may be workarounds, but the ideas I came up with either did not work (
uv run pythonw myscript.py
does not parse the inline metadata) or were cumbersome and error prone (i.e. using Windows soft or hard links, or importing the.py
script from a second.pyw
script and keeping the inline dependencies in sync).It would be very convenient, if there was an additional flag for
uv run
to instructuv
to usepythonw.exe
on a file with the.py
extension (e.g.uv run --pythonw myscript.py
).The text was updated successfully, but these errors were encountered: