Commit 43f81ef
authored
Fix PermissionError when detecting package manager on WSL (#10084)
I was running into a issue when the python emitter would raise an error
that uv was running in to a `PermissionError`. I didnt have `uv`
installed and wanted it to use my system python instead.
This was preventing the fallback to using pip instead. In the repro
below you can see python is walking down every directory in $PATH tryig
to find uv. It found a stub on Windows side but then doesnt have
permissions to run it.
The fix is to except on `PermissionError` when trying to detect the
package manager so the script does the right fallback.
Error message
```bash
azure_ai_ml_tsp2) kashifkhan@CPC-kashi-72N0D ~/code/azure-sdk-for-python/sdk/ml/azure-ai-ml/azure/ai/ml/_restclient [azure_ai_ml_tsp] % tsp-client update --local-spec-repo /home/kashifkhan/code/azure-rest-api-specs Using output directory '/home/kashifkhan/code/azure-sdk-for-python/sdk/ml/azure-ai-ml/azure/ai/ml/_restclient'
888 888 d8b 888
888 888 Y8P 888
888 888 888
888888 .d8888b 88888b. .d8888b 888 888 .d88b. 88888b. 888888
888 88K 888 "88b d88P" 888 888 d8P Y8b 888 "88b 888
888 "Y8888b. 888 888 888888 888 888 888 88888888 888 888 888
Y88b. X88 888 d88P Y88b. 888 888 Y8b. 888 888 Y88b.
"Y888 88888P' 88888P" "Y8888P 888 888 "Y8888 888 888 "Y888
888
888
888
0.31.0
Found batch configuration with 7 directories
During batch processing will use local spec repo root with child library tsp-location.yaml data to resolve path to typespec project directory: /home/kashifkhan/code/azure-rest-api-specs
Processing batch directory: ./azure_ai_assets_v2024_04_01
Resolved local spec repo path using tsp-location.yaml directory: /home/kashifkhan/code/azure-rest-api-specs/specification/machinelearningservices/AzureAI.Assets
NOTE: A path to a local spec was provided, will generate based off of local files...
Local spec repo root is /home/kashifkhan/code/azure-rest-api-specs
Found emitter package @azure-tools/typespec-python@0.60.2
Skipping creation of tsp-client-metadata.yaml file.
Installing dependencies from npm...
(node:87604) [DEP0190] DeprecationWarning: Passing args to a child process with shell option true can lead to security vulnerabilities, as the arguments are not escaped, only concatenated.
(Use `node --trace-deprecation ...` to show where the warning was created)
npm error code 1
npm error path /home/kashifkhan/code/azure-sdk-for-python/sdk/ml/azure-ai-ml/azure/ai/ml/_restclient/azure_ai_assets_v2024_04_01/TempTypeSpecFiles/node_modules/@typespec/http-client-python
npm error command failed
npm error command sh -c tsx ./eng/scripts/setup/install.ts
npm error (node:87696) [DEP0190] DeprecationWarning: Passing args to a child process with shell option true can lead to security vulnerabilities, as the arguments are not escaped, only concatenated.
npm error (Use `node --trace-deprecation ...` to show where the warning was created)
npm error Traceback (most recent call last):
npm error File "/home/kashifkhan/code/azure-sdk-for-python/sdk/ml/azure-ai-ml/azure/ai/ml/_restclient/azure_ai_assets_v2024_04_01/TempTypeSpecFiles/node_modules/@typespec/http-client-python/./eng/scripts/setup/install.py", line 19, in <module>
npm error detect_package_manager() # Just check if we have a package manager
npm error ~~~~~~~~~~~~~~~~~~~~~~^^
npm error File "/home/kashifkhan/code/azure-sdk-for-python/sdk/ml/azure-ai-ml/azure/ai/ml/_restclient/azure_ai_assets_v2024_04_01/TempTypeSpecFiles/node_modules/@typespec/http-client-python/eng/scripts/setup/package_manager.py", line 42, in detect_package_manager
npm error if _check_command_available("uv"):
npm error ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
npm error File "/home/kashifkhan/code/azure-sdk-for-python/sdk/ml/azure-ai-ml/azure/ai/ml/_restclient/azure_ai_assets_v2024_04_01/TempTypeSpecFiles/node_modules/@typespec/http-client-python/eng/scripts/setup/package_manager.py", line 26, in _check_command_available
npm error subprocess.run([command, "--version"], capture_output=True, check=True)
npm error ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
npm error File "/usr/lib/python3.13/subprocess.py", line 554, in run
npm error with Popen(*popenargs, **kwargs) as process:
npm error ~~~~~^^^^^^^^^^^^^^^^^^^^^^
npm error File "/usr/lib/python3.13/subprocess.py", line 1039, in __init__
npm error self._execute_child(args, executable, preexec_fn, close_fds,
npm error ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
npm error pass_fds, cwd, env,
npm error ^^^^^^^^^^^^^^^^^^^
npm error ...<5 lines>...
npm error gid, gids, uid, umask,
npm error ^^^^^^^^^^^^^^^^^^^^^^
npm error start_new_session, process_group)
npm error ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
npm error File "/usr/lib/python3.13/subprocess.py", line 1991, in _execute_child
npm error raise child_exception_type(errno_num, err_msg, err_filename)
npm error PermissionError: [Errno 13] Permission denied: 'uv'
npm error Python and package manager found but installation failed.
npm error A complete log of this run can be found in: /home/kashifkhan/.npm/_logs/2026-03-13T21_41_19_612Z-debug-0.log
Failed to process batch directory ./azure_ai_assets_v2024_04_01: Error: npm ci failed exited with code 1
```
quick repro
```bash
kashifkhan@CPC-kashi-72N0D ~ % strace -f -e trace=execve python3 -c "import subprocess; subprocess.run(['uv','--version'], capture_output=True)"
execve("/usr/bin/python3", ["python3", "-c", "import subprocess; subprocess.ru"...], 0x7ffc581e6a18 /* 39 vars */) = 0
strace: Process 10939 attached
[pid 10939] execve("/home/kashifkhan/.local/bin/uv", ["uv", "--version"], 0x7fff49cebf28 /* 39 vars */) = -1 ENOENT (No such file or directory)
[pid 10939] execve("/home/kashifkhan/.aspire/bin/uv", ["uv", "--version"], 0x7fff49cebf28 /* 39 vars */) = -1 ENOENT (No such file or directory)
[pid 10939] execve("/home/kashifkhan/go/bin/uv", ["uv", "--version"], 0x7fff49cebf28 /* 39 vars */) = -1 ENOENT (No such file or directory)
[pid 10939] execve("/usr/local/go/bin/uv", ["uv", "--version"], 0x7fff49cebf28 /* 39 vars */) = -1 ENOENT (No such file or directory)
[pid 10939] execve("/home/kashifkhan/.config/nvm/versions/node/v24.14.0/bin/uv", ["uv", "--version"], 0x7fff49cebf28 /* 39 vars */) = -1 ENOENT (No such file or directory)
[pid 10939] execve("/home/kashifkhan/.cargo/bin/uv", ["uv", "--version"], 0x7fff49cebf28 /* 39 vars */) = -1 ENOENT (No such file or directory)
[pid 10939] execve("/usr/local/sbin/uv", ["uv", "--version"], 0x7fff49cebf28 /* 39 vars */) = -1 ENOENT (No such file or directory)
[pid 10939] execve("/usr/local/bin/uv", ["uv", "--version"], 0x7fff49cebf28 /* 39 vars */) = -1 ENOENT (No such file or directory)
[pid 10939] execve("/usr/sbin/uv", ["uv", "--version"], 0x7fff49cebf28 /* 39 vars */) = -1 ENOENT (No such file or directory)
[pid 10939] execve("/usr/bin/uv", ["uv", "--version"], 0x7fff49cebf28 /* 39 vars */) = -1 ENOENT (No such file or directory)
[pid 10939] execve("/sbin/uv", ["uv", "--version"], 0x7fff49cebf28 /* 39 vars */) = -1 ENOENT (No such file or directory)
[pid 10939] execve("/bin/uv", ["uv", "--version"], 0x7fff49cebf28 /* 39 vars */) = -1 ENOENT (No such file or directory)
[pid 10939] execve("/usr/games/uv", ["uv", "--version"], 0x7fff49cebf28 /* 39 vars */) = -1 ENOENT (No such file or directory)
[pid 10939] execve("/usr/local/games/uv", ["uv", "--version"], 0x7fff49cebf28 /* 39 vars */) = -1 ENOENT (No such file or directory)
[pid 10939] execve("/usr/lib/wsl/lib/uv", ["uv", "--version"], 0x7fff49cebf28 /* 39 vars */) = -1 ENOENT (No such file or directory)
[pid 10939] execve("/mnt/c/Windows/system32/uv", ["uv", "--version"], 0x7fff49cebf28 /* 39 vars */) = -1 ENOENT (No such file or directory)
[pid 10939] execve("/mnt/c/Windows/uv", ["uv", "--version"], 0x7fff49cebf28 /* 39 vars */) = -1 ENOENT (No such file or directory)
[pid 10939] execve("/mnt/c/Windows/System32/Wbem/uv", ["uv", "--version"], 0x7fff49cebf28 /* 39 vars */) = -1 ENOENT (No such file or directory)
[pid 10939] execve("/mnt/c/Windows/System32/WindowsPowerShell/v1.0/uv", ["uv", "--version"], 0x7fff49cebf28 /* 39 vars */) = -1 ENOENT (No such file or directory)
[pid 10939] execve("/mnt/c/Windows/System32/OpenSSH/uv", ["uv", "--version"], 0x7fff49cebf28 /* 39 vars */) = -1 ENOENT (No such file or directory)
[pid 10939] execve("/mnt/c/Program Files/Microsoft SQL Server/150/Tools/Binn/uv", ["uv", "--version"], 0x7fff49cebf28 /* 39 vars */) = -1 ENOENT (No such file or directory)
[pid 10939] execve("/mnt/c/.tools/dotnet/uv", ["uv", "--version"], 0x7fff49cebf28 /* 39 vars */) = -1 ENOENT (No such file or directory)
[pid 10939] execve("/mnt/c/.tools/.npm-global/uv", ["uv", "--version"], 0x7fff49cebf28 /* 39 vars */) = -1 ENOENT (No such file or directory)
[pid 10939] execve("/mnt/c/Users/vmadmin/AppData/Local/Microsoft/WindowsApps/uv", ["uv", "--version"], 0x7fff49cebf28 /* 39 vars */) = -1 ENOENT (No such file or directory)
[pid 10939] execve("/mnt/c/Users/vmadmin/.dotnet/tools/uv", ["uv", "--version"], 0x7fff49cebf28 /* 39 vars */) = -1 ENOENT (No such file or directory)
[pid 10939] execve("/mnt/c/Program Files/NuGet/uv", ["uv", "--version"], 0x7fff49cebf28 /* 39 vars */) = -1 ENOENT (No such file or directory)
[pid 10939] execve("/mnt/c/Windows/system32/config/systemprofile/AppData/Local/Microsoft/WindowsApps/uv", ["uv", "--version"], 0x7fff49cebf28 /* 39 vars */) = -1 EACCES (Permission denied)
[pid 10939] execve("/mnt/c/Program Files/Microsoft Dev Box Agent/Scripts/uv", ["uv", "--version"], 0x7fff49cebf28 /* 39 vars */) = -1 ENOENT (No such file or directory)
[pid 10939] execve("/mnt/c/WINDOWS/system32/uv", ["uv", "--version"], 0x7fff49cebf28 /* 39 vars */) = -1 ENOENT (No such file or directory)
[pid 10939] execve("/mnt/c/WINDOWS/uv", ["uv", "--version"], 0x7fff49cebf28 /* 39 vars */) = -1 ENOENT (No such file or directory)
[pid 10939] execve("/mnt/c/WINDOWS/System32/Wbem/uv", ["uv", "--version"], 0x7fff49cebf28 /* 39 vars */) = -1 ENOENT (No such file or directory)
[pid 10939] execve("/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/uv", ["uv", "--version"], 0x7fff49cebf28 /* 39 vars */) = -1 ENOENT (No such file or directory)
[pid 10939] execve("/mnt/c/WINDOWS/System32/OpenSSH/uv", ["uv", "--version"], 0x7fff49cebf28 /* 39 vars */) = -1 ENOENT (No such file or directory)
[pid 10939] execve("/mnt/c/Program Files/PowerShell/7/uv", ["uv", "--version"], 0x7fff49cebf28 /* 39 vars */) = -1 ENOENT (No such file or directory)
[pid 10939] execve("/mnt/c/Program Files/Git/cmd/uv", ["uv", "--version"], 0x7fff49cebf28 /* 39 vars */) = -1 ENOENT (No such file or directory)
[pid 10939] execve("/mnt/c/Program Files/Docker/Docker/resources/bin/uv", ["uv", "--version"], 0x7fff49cebf28 /* 39 vars */) = -1 ENOENT (No such file or directory)
[pid 10939] execve("/mnt/c/Users/kashifkhan/AppData/Local/Microsoft/WindowsApps/uv", ["uv", "--version"], 0x7fff49cebf28 /* 39 vars */) = -1 ENOENT (No such file or directory)
[pid 10939] execve("/mnt/c/Users/kashifkhan/AppData/Local/Programs/Microsoft VS Code/bin/uv", ["uv", "--version"], 0x7fff49cebf28 /* 39 vars */) = -1 ENOENT (No such file or directory)
[pid 10939] execve("/mnt/c/Users/kashifkhan/AppData/Local/Programs/Microsoft VS Code Insiders/bin/uv", ["uv", "--version"], 0x7fff49cebf28 /* 39 vars */) = -1 ENOENT (No such file or directory)
[pid 10939] execve("/mnt/c/Users/kashifkhan/AppData/Local/PowerToys/DSCModules/uv", ["uv", "--version"], 0x7fff49cebf28 /* 39 vars */) = -1 ENOENT (No such file or directory)
[pid 10939] execve("/home/kashifkhan/.fzf/bin/uv", ["uv", "--version"], 0x7fff49cebf28 /* 39 vars */) = -1 ENOENT (No such file or directory)
[pid 10939] execve("/home/kashifkhan/dotnet/uv", ["uv", "--version"], 0x7fff49cebf28 /* 39 vars */) = -1 ENOENT (No such file or directory)
[pid 10939] +++ exited with 255 +++
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=10939, si_uid=1000, si_status=255, si_utime=0, si_stime=0} ---
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python3.12/subprocess.py", line 548, in run
with Popen(*popenargs, **kwargs) as process:
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/subprocess.py", line 1026, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib/python3.12/subprocess.py", line 1955, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
PermissionError: [Errno 13] Permission denied: 'uv'
+++ exited with 1 +++
kashifkhan@CPC-kashi-72N0D ~ %
```1 parent 63fc96b commit 43f81ef
2 files changed
Lines changed: 9 additions & 2 deletions
File tree
- .chronus/changes
- packages/http-client-python/eng/scripts/setup
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
| 53 | + | |
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| |||
0 commit comments