Skip to content

Commit 27f2384

Browse files
CopilotMic92
andcommitted
qwen-code: refactor update.py to use common helper infrastructure
- Use `run_command` from updater.nix for running prefetch-npm-deps and nix-update - Use `fetch_text` from updater.http for downloading files from GitHub - Add GITHUB_TOKEN support for authenticated GitHub API requests - Replace direct subprocess calls with helper functions for consistency This addresses code review feedback to use existing helpers instead of custom implementations. Co-authored-by: Mic92 <[email protected]>
1 parent 122d903 commit 27f2384

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

packages/qwen-code/update.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33

44
"""Update script for qwen-code package."""
55

6-
import subprocess
6+
import os
77
import sys
88
from pathlib import Path
9-
from urllib.request import urlretrieve
109

1110
sys.path.insert(0, str(Path(__file__).parent.parent.parent / "scripts"))
1211

13-
from updater import NixCommandError, nix_eval
12+
from updater import fetch_text
13+
from updater.nix import NixCommandError, nix_eval, run_command
1414

1515
SCRIPT_DIR = Path(__file__).parent
1616
PACKAGE_NAME = "qwen-code"
@@ -23,9 +23,21 @@ def download_package_lock(version: str) -> bool:
2323
url = f"https://raw.githubusercontent.com/{GITHUB_OWNER}/{GITHUB_REPO}/v{version}/package-lock.json"
2424
dest = SCRIPT_DIR / "package-lock.json"
2525

26+
# Add GitHub token to request if available
27+
github_token = os.environ.get("GITHUB_TOKEN")
2628
print(f"Downloading package-lock.json from {url}...")
2729
try:
28-
urlretrieve(url, dest)
30+
# fetch_text handles authentication via urllib
31+
if github_token:
32+
import urllib.request
33+
req = urllib.request.Request(url)
34+
req.add_header("Authorization", f"token {github_token}")
35+
with urllib.request.urlopen(req) as response:
36+
content = response.read().decode("utf-8")
37+
else:
38+
content = fetch_text(url)
39+
40+
dest.write_text(content)
2941
print("Successfully downloaded package-lock.json")
3042
return True
3143
except Exception as e:
@@ -37,11 +49,10 @@ def calculate_npm_deps_hash() -> str:
3749
"""Calculate npmDepsHash using prefetch-npm-deps."""
3850
package_lock = SCRIPT_DIR / "package-lock.json"
3951
print("Calculating npmDepsHash...")
40-
result = subprocess.run(
52+
result = run_command(
4153
["prefetch-npm-deps", str(package_lock)],
42-
capture_output=True,
43-
text=True,
4454
check=True,
55+
capture_output=True,
4556
)
4657
return result.stdout.strip()
4758

@@ -50,7 +61,7 @@ def run_nix_update(args: list[str]) -> None:
5061
"""Run nix-update with given arguments."""
5162
cmd = ["nix-update", "--flake", PACKAGE_NAME] + args
5263
print(f"Running: {' '.join(cmd)}")
53-
result = subprocess.run(cmd, capture_output=True, text=True)
64+
result = run_command(cmd, check=False, capture_output=True)
5465
if result.returncode != 0:
5566
raise NixCommandError(f"nix-update failed: {result.stderr}")
5667
print(result.stdout)
@@ -94,7 +105,7 @@ def main() -> None:
94105
try:
95106
npm_deps_hash = calculate_npm_deps_hash()
96107
print(f"npmDepsHash: {npm_deps_hash}")
97-
except subprocess.CalledProcessError as e:
108+
except NixCommandError as e:
98109
print(f"ERROR: Failed to calculate npmDepsHash: {e}")
99110
return
100111

0 commit comments

Comments
 (0)