mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-24 05:41:40 +00:00
refactor: fix review findings — remove duplicate imports and deduplicate update command
- banner.py: remove redundant `import json as _json` (json already at module level) - main.py: _cmd_update_pip now delegates to recommended_update_command_for_method instead of duplicating the uv-vs-pip detection logic - main.py: remove redundant `import subprocess as _sp` (subprocess already at module level)
This commit is contained in:
parent
259ae846c8
commit
96917fb74a
2 changed files with 7 additions and 9 deletions
|
|
@ -190,11 +190,10 @@ def _fetch_pypi_latest(package: str = "hermes-agent") -> Optional[str]:
|
||||||
"""Fetch the latest version of a package from PyPI. Returns None on failure."""
|
"""Fetch the latest version of a package from PyPI. Returns None on failure."""
|
||||||
try:
|
try:
|
||||||
import urllib.request
|
import urllib.request
|
||||||
import json as _json
|
|
||||||
url = f"https://pypi.org/pypi/{package}/json"
|
url = f"https://pypi.org/pypi/{package}/json"
|
||||||
req = urllib.request.Request(url, headers={"Accept": "application/json"})
|
req = urllib.request.Request(url, headers={"Accept": "application/json"})
|
||||||
with urllib.request.urlopen(req, timeout=5) as resp:
|
with urllib.request.urlopen(req, timeout=5) as resp:
|
||||||
data = _json.loads(resp.read())
|
data = json.loads(resp.read())
|
||||||
return data.get("info", {}).get("version")
|
return data.get("info", {}).get("version")
|
||||||
except Exception:
|
except Exception:
|
||||||
return None
|
return None
|
||||||
|
|
|
||||||
|
|
@ -7673,20 +7673,19 @@ def cmd_update(args):
|
||||||
|
|
||||||
def _cmd_update_pip(args):
|
def _cmd_update_pip(args):
|
||||||
"""Update Hermes via pip (for PyPI installs)."""
|
"""Update Hermes via pip (for PyPI installs)."""
|
||||||
import subprocess as _sp
|
|
||||||
from hermes_cli import __version__
|
from hermes_cli import __version__
|
||||||
|
from hermes_cli.config import recommended_update_command_for_method
|
||||||
|
|
||||||
print(f"→ Current version: {__version__}")
|
print(f"→ Current version: {__version__}")
|
||||||
print("→ Checking PyPI for updates...")
|
print("→ Checking PyPI for updates...")
|
||||||
|
|
||||||
uv = shutil.which("uv")
|
cmd_str = recommended_update_command_for_method("pip")
|
||||||
if uv:
|
cmd = cmd_str.split()
|
||||||
cmd = [uv, "pip", "install", "--upgrade", "hermes-agent"]
|
if cmd[0] == "pip":
|
||||||
else:
|
cmd = [sys.executable, "-m", "pip"] + cmd[1:]
|
||||||
cmd = [sys.executable, "-m", "pip", "install", "--upgrade", "hermes-agent"]
|
|
||||||
|
|
||||||
print(f"→ Running: {' '.join(cmd)}")
|
print(f"→ Running: {' '.join(cmd)}")
|
||||||
result = _sp.run(cmd)
|
result = subprocess.run(cmd)
|
||||||
if result.returncode != 0:
|
if result.returncode != 0:
|
||||||
print("✗ Update failed")
|
print("✗ Update failed")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue