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

uv run powershell script fails #9010

Open
jenshnielsen opened this issue Nov 11, 2024 · 7 comments
Open

uv run powershell script fails #9010

jenshnielsen opened this issue Nov 11, 2024 · 7 comments
Labels
windows Specific to the Windows platform

Comments

@jenshnielsen
Copy link

If pyright is installed from npm it will install itself with a cmd and powershell entry point on windows and a shell script on linux.
When trying to run this script using uv run, to run it in uv's managed .venv on windows, it errors unless the cmd script is supplied or an explicit powershell is prefixed.

This is inconvenient since it means that the same command cannot be used to typecheck the code using pyright on windows and linux.

In summary:

The following does not work on windows:

uv run pyright
errors with

error: Failed to spawn: `pyright`
  Caused by: program not found

uv run pyright.ps1

errors with:

error: Failed to spawn: `pyright.ps1`
  Caused by: %1 is not a valid Win32 application. (os error 193)

The following works:

On windows:

uv run pyright.cmd

uv run powershell pyright.ps1

.venv\Scripts\activate
pyright

On linux:

uv run pyright

  • The command you invoked uv run pyright
  • The current uv platform. Windows 11
  • The current uv version: uv 0.5.1
@charliermarsh charliermarsh added the windows Specific to the Windows platform label Nov 12, 2024
@charliermarsh
Copy link
Member

Is this the same as #8770?

@jenshnielsen
Copy link
Author

@charliermarsh it's probably at least related. I think there are two different issues here.

@jenshnielsen
Copy link
Author

Did a test with nuitka and I think the problem is indeed the same as part 1 of this problem.

uv venv nuitka
uv pip install nuitka

then

uv run nuitka

fails with

error: Failed to spawn: `nuitka`
  Caused by: program not found

but

uv run nuitka.cmd

works as expected

@jenshnielsen
Copy link
Author

The reason for issue number 1 e.g. not being able to call a cmd script without the extension is given here.

https://doc.rust-lang.org/std/process/struct.Command.html#platform-specific-behavior

Note on Windows: For executable files with the .exe extension, it can be omitted when specifying the program for this Command. However, if the file has a different extension, a filename including the extension needs to be provided, otherwise the file won’t be found.

Unlike powershell / cmd's behaviour std::process::Command will not execute a .cmd or .ps1 script unless the extension is included.

@zanieb
Copy link
Member

zanieb commented Nov 13, 2024

We can fix the display of these (#9099), but I don't know if uv run foo.ps1 should work or if we should require uv run powershell foo.ps1.

@jenshnielsen
Copy link
Author

From my perspective that would not make a big difference. My main concern is that I have to special case between windows and linux when running commands in CI

e.g. I tried migrating from creating and activating a venv to using uv run
Using uv run I will have to execute the script with an extension (And perhaps a shell prefix) whereas on linux I can just execute the script as is. To my knowledge it seems fairly common to ship crossplatform scripts in this way (cmd/ps1 on windows and bash/sh on linux) so I think it would be nice to support for unified crossplatform support. However, I can understand if stripping extensions and introducing shells seems like too much magic (does this need to be done also for other shells and their scripting languages ? )

For now I was able to work around the specific issue in azure pipelines (I expect this works in github actions too) by doing

uv run --extra test pwsh -C pyright

E.g. running pyright from a powershell core session inside uv run. This works since Azure pipelines ships with powershell 7 installed on all platforms.

@zanieb
Copy link
Member

zanieb commented Nov 15, 2024

Using uv run I will have to execute the script with an extension (And perhaps a shell prefix) whereas on linux I can just execute the script as is. To my knowledge it seems fairly common to ship crossplatform scripts in this way (cmd/ps1 on windows and bash/sh on linux) so I think it would be nice to support for unified crossplatform support.

I think the ideas is that project.scripts should be used for cross-platform scripts since it's the standard, the old behavior seems less common now. I agree cross-platform support is nice though.

However, I can understand if stripping extensions and introducing shells seems like too much magic (does this need to be done also for other shells and their scripting languages ? )

Yeah this is my concern. We don't plan do this for other shells and languages, i.e., uv run foo.sh won't work.

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

No branches or pull requests

3 participants