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

Cannot run npm via rye run #1031

Open
Aran-Fey opened this issue Apr 19, 2024 · 4 comments
Open

Cannot run npm via rye run #1031

Aran-Fey opened this issue Apr 19, 2024 · 4 comments

Comments

@Aran-Fey
Copy link

Steps to Reproduce

  1. Run rye init bug-demo
  2. Add this to the pyproject.toml:
    [tool.rye.scripts]
    demo-script = "npm --version"
  3. Run it: rye run demo-script

Expected Result

Same as running npm --version: 10.2.0 on my machine.

Actual Result

error: program not found

Version Info

rye 0.32.0
commit: 0.32.0 (e1b4f2a 2024-03-29)
platform: windows (x86_64)
self-python: [email protected]
symlink support: true
uv enabled: true

Stacktrace

No response

@Aran-Fey
Copy link
Author

On linux it works fine though.

rye 0.32.0
commit: 0.32.0 (e1b4f2a29 2024-03-29)
platform: linux (x86_64)
self-python: [email protected]
symlink support: true
uv enabled: true

@Aran-Fey
Copy link
Author

Aran-Fey commented May 7, 2024

I did a bit of digging and found that the output of shutil.which changes when run through rye:

> where npm
C:\Program Files\nodejs\npm
C:\Program Files\nodejs\npm.cmd

> py -c "import shutil; print(shutil.which('npm'))"
C:\Program Files\nodejs\npm

> rye run print-npm-path
C:\Program Files\nodejs\npm.CMD

But oddly, the PATH doesn't change, except for the addition of .venv\Scripts:

> echo %PATH%
C:\Python312\Scripts\;C:\Python312\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\ProgramData\chocolatey\bin;C:\Program Files\Microsoft VS Code\bin;C:\Program Files\nodejs\;C:\Program Files\dotnet\;C:\Program Files\OpenJDK\jdk-21.0.1\bin;C:\Program Files\Docker\Docker\resources\bin;C:\Users\Aran-Fey\.rye\shims;C:\Users\Aran-Fey\bin;C:\Python312\Scripts\;C:\Python312\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\ProgramData\chocolatey\bin;C:\Program Files\Git\cmd;C:\Program Files\Microsoft VS Code\bin;C:\tools\msys64\usr\bin;C:\Users\Aran-Fey\AppData\Local\Microsoft\WindowsApps;C:\Users\Aran-Fey\AppData\Roaming\npm;C:\ghcup\bin;
> rye run print-path
D:\Users\Aran-Fey\Desktop\folder\coding\python\rio\.venv\Scripts;C:\Python312\Scripts\;C:\Python312\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\ProgramData\chocolatey\bin;C:\Program Files\Microsoft VS Code\bin;C:\Program Files\nodejs\;C:\Program Files\dotnet\;C:\Program Files\OpenJDK\jdk-21.0.1\bin;C:\Program Files\Docker\Docker\resources\bin;C:\Users\Aran-Fey\.rye\shims;C:\Users\Aran-Fey\bin;C:\Python312\Scripts\;C:\Python312\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\ProgramData\chocolatey\bin;C:\Program Files\Git\cmd;C:\Program Files\Microsoft VS Code\bin;C:\tools\msys64\usr\bin;C:\Users\Aran-Fey\AppData\Local\Microsoft\WindowsApps;C:\Users\Aran-Fey\AppData\Roaming\npm;C:\ghcup\bin;

@Aran-Fey
Copy link
Author

Aran-Fey commented May 7, 2024

More info: The output of where is unaffected when run through rye:

> rye run where
C:\Program Files\nodejs\npm
C:\Program Files\nodejs\npm.cmd

@Aran-Fey
Copy link
Author

Aran-Fey commented May 7, 2024

So apparently the problem is that there is no npm.exe. Turns out that npm is a shell script, so I can execute it in my cygwin terminal, and npm.cmd does the same for cmd.exe/powershell. But since there is no npm.exe, something like subprocess.run('npm') (and whatever the equivalent of that in rust is) fails.

That said, adding shell=True would fix this problem. Is there any way to make a rye script do that? Currently my script is defined like so:

[tool.rye.scripts]
build = "npm run build"

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

No branches or pull requests

1 participant