fix(win): Python detection and proxy support#9
Conversation
- _common.ps1: prefer 'py' over 'python' to avoid Microsoft Store shim; accept Python 3.7+ (tested working) instead of hard 3.8+ requirement - gh-api.py: add _install_proxy_handler() to read HTTP_PROXY/HTTPS_PROXY and configure urllib ProxyHandler explicitly Tested on Windows 10 + PS5.1 + Python 3.7.2 via py launcher.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 44388d70e8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| foreach ($c in $candidates) { | ||
| $cmd = Get-Command $c -ErrorAction SilentlyContinue | ||
| if (-not $cmd) { continue } | ||
| $verOutput = & $cmd --version 2>&1 |
There was a problem hiding this comment.
Probe the py launcher with a Python 3 qualifier
When $c is py, this calls the Windows launcher without a version qualifier; the Python launcher docs describe bare py as using its configured default, while py -3/python3 selects the latest Python 3.x. In Windows environments where PY_PYTHON/py.ini or an older launcher default points to Python 2 and no python3.exe is on PATH, this wrapper still rejects py even though a supported Python 3 is installed, so all Windows commands fail. Please probe and later invoke the launcher with an explicit -3 qualifier for the py candidate.
Useful? React with 👍 / 👎.
| os.environ.get("HTTPS_PROXY") | ||
| or os.environ.get("https_proxy") |
There was a problem hiding this comment.
Honor lowercase proxy overrides
When both uppercase and lowercase proxy variables are present, this manual lookup always chooses HTTPS_PROXY over https_proxy, whereas Python's normal urllib proxy discovery intentionally lets lowercase values override uppercase ones. In environments where an infrastructure-level uppercase proxy is stale or blocked and the user sets lowercase https_proxy for this command, the new handler sends GitHub API requests through the wrong proxy and the wrapper fails; preserving urllib's precedence or delegating to getproxies() avoids that regression.
Useful? React with 👍 / 👎.
|
已推送 处理内容:
实际测试:
|
There was a problem hiding this comment.
Pull request overview
This PR improves Windows compatibility for the PowerShell wrappers by making Python discovery more reliable (avoiding the Microsoft Store shim / unintended Python 2 via py defaults) and adds proxy support to the Python urllib backend so requests can flow through standard proxy configuration.
Changes:
- Update Windows wrappers to prefer
py -3(fallbackpython) and relax the minimum supported Python version to 3.7+. - Add proxy discovery/handling in
gh-api.pyviaurllib.request.getproxies()and aProxyHandleropener. - Improve Windows PowerShell 5.1 compatibility by writing temp JSON payload files as UTF-8 without BOM via a .NET helper.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| SKILL.md | Documents Windows Python invocation guidance (py -3 then python). |
| scripts/windows/gh-pr.ps1 | Uses UTF-8 no-BOM writer for temp JSON payload files. |
| scripts/windows/gh-issue.ps1 | Uses UTF-8 no-BOM writer for temp JSON payload files. |
| scripts/windows/_common.ps1 | Implements Python discovery preferring py -3, and adds Write-Utf8NoBomFile. |
| scripts/linux/gh-api.py | Installs urllib proxy handler based on discovered proxies. |
| scripts/gh-api.py | Installs urllib proxy handler based on discovered proxies. |
| README.md | Updates platform requirements/docs (Python 3.7+, Windows invocation, proxy note, Windows compile check). |
| CHANGELOG.md | Records Windows Python detection change, proxy discovery change, and UTF-8 no-BOM write fix. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| def _install_proxy_handler(): | ||
| """Install urllib's standard proxy handler when proxy env vars are set.""" | ||
| proxies = urllib.request.getproxies() | ||
| if proxies: | ||
| handler = urllib.request.ProxyHandler(proxies) | ||
| opener = urllib.request.build_opener(handler) | ||
| urllib.request.install_opener(opener) |
| def _install_proxy_handler(): | ||
| """Install urllib's standard proxy handler when proxy env vars are set.""" | ||
| proxies = urllib.request.getproxies() | ||
| if proxies: | ||
| handler = urllib.request.ProxyHandler(proxies) | ||
| opener = urllib.request.build_opener(handler) | ||
| urllib.request.install_opener(opener) |
Changes
Tested
Windows 10 + PS5.1 + Python 3.7.2 via py launcher, proxy 127.0.0.1:10808