Skip to content

Commit d72f4f1

Browse files
authored
[python] update python emitter install with helpful 401 error output (#10720)
closes Azure/azure-sdk-for-python#46964 Because the python emitter's `install.ts` may use `uv pip` to install packages, it can run into authentication errors if a package version isn't cached in our central feed service, which we now default to pulling from instead of PyPI (see Azure/azure-sdk-for-python#46281 ) updates the error point to link to python repo's authentication docs
1 parent f9d02ed commit d72f4f1

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
changeKind: internal
3+
packages:
4+
- "@typespec/http-client-python"
5+
---
6+
7+
When python emitter install fails due to 401 error, output informative instructions linking to resolution steps in the Python SDK's repo docs.

packages/http-client-python/eng/scripts/setup/package_manager.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,20 @@ def install_packages(packages: list, venv_context=None, package_manager: str = N
100100

101101
try:
102102
if cwd:
103-
subprocess.check_call(install_cmd + packages, cwd=cwd)
103+
result = subprocess.run(install_cmd + packages, cwd=cwd, capture_output=True, text=True)
104104
else:
105-
subprocess.check_call(install_cmd + packages)
106-
except subprocess.CalledProcessError as e:
105+
result = subprocess.run(install_cmd + packages, capture_output=True, text=True)
106+
if result.returncode != 0:
107+
error_output = (result.stderr or "") + (result.stdout or "")
108+
error_msg = f"Failed to install packages with {package_manager}: command exited with code {result.returncode}\n{error_output}"
109+
if "401" in error_output or "Unauthorized" in error_output:
110+
error_msg += (
111+
"\n\nReceived a 401 Unauthorized error from the Azure feed. "
112+
"A pip dependency may not yet be cached. To fix this, follow the authentication steps at: "
113+
"https://github.com/Azure/azure-sdk-for-python/blob/main/CONTRIBUTING.md#authentication-for-upstream-pull-through"
114+
)
115+
raise RuntimeError(error_msg)
116+
except OSError as e:
107117
raise RuntimeError(f"Failed to install packages with {package_manager}: {e}")
108118

109119

0 commit comments

Comments
 (0)