mirror of
https://github.com/OpenHands/OpenHands.git
synced 2025-12-26 05:48:36 +08:00
(feat) add --version to cli (#3924)
This commit is contained in:
parent
f7ebc1cf1f
commit
c3117e8c39
@ -0,0 +1,28 @@
|
||||
def get_version():
|
||||
try:
|
||||
from importlib.metadata import PackageNotFoundError, version
|
||||
|
||||
try:
|
||||
return version('openhands-ai')
|
||||
except PackageNotFoundError:
|
||||
pass
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
try:
|
||||
from pkg_resources import DistributionNotFound, get_distribution
|
||||
|
||||
try:
|
||||
return get_distribution('openhands-ai').version
|
||||
except DistributionNotFound:
|
||||
pass
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
return 'unknown'
|
||||
|
||||
|
||||
try:
|
||||
__version__ = get_version()
|
||||
except Exception:
|
||||
__version__ = 'unknown'
|
||||
@ -1,3 +1,4 @@
|
||||
import argparse
|
||||
import asyncio
|
||||
import logging
|
||||
from typing import Type
|
||||
@ -5,6 +6,7 @@ from typing import Type
|
||||
from termcolor import colored
|
||||
|
||||
import agenthub # noqa F401 (we import this to get the agents registered)
|
||||
from openhands import __version__
|
||||
from openhands.controller import AgentController
|
||||
from openhands.controller.agent import Agent
|
||||
from openhands.core.config import (
|
||||
@ -61,8 +63,32 @@ def display_event(event: Event):
|
||||
display_command_output(event.content)
|
||||
|
||||
|
||||
def get_parser() -> argparse.ArgumentParser:
|
||||
"""Get the parser for the command line arguments."""
|
||||
parser = argparse.ArgumentParser(description='Run an agent with a specific task')
|
||||
|
||||
# Add the version argument
|
||||
parser.add_argument(
|
||||
'-v',
|
||||
'--version',
|
||||
action='version',
|
||||
version=f'{__version__}',
|
||||
help='Show the version number and exit',
|
||||
)
|
||||
|
||||
return parser
|
||||
|
||||
|
||||
async def main():
|
||||
"""Runs the agent in CLI mode"""
|
||||
|
||||
parser = get_parser()
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.version:
|
||||
print(f'OpenHands version: {__version__}')
|
||||
return
|
||||
|
||||
logger.setLevel(logging.WARNING)
|
||||
config = load_app_config()
|
||||
sid = 'cli'
|
||||
|
||||
@ -85,7 +85,6 @@ reportlab = "*"
|
||||
[tool.coverage.run]
|
||||
concurrency = ["gevent"]
|
||||
|
||||
|
||||
[tool.poetry.group.runtime.dependencies]
|
||||
jupyterlab = "*"
|
||||
notebook = "*"
|
||||
@ -116,7 +115,6 @@ ignore = ["D1"]
|
||||
[tool.ruff.lint.pydocstyle]
|
||||
convention = "google"
|
||||
|
||||
|
||||
[tool.poetry.group.evaluation.dependencies]
|
||||
streamlit = "*"
|
||||
whatthepatch = "*"
|
||||
@ -128,3 +126,10 @@ sympy = "*"
|
||||
gdown = "*"
|
||||
matplotlib = "*"
|
||||
seaborn = "*"
|
||||
|
||||
[tool.poetry-dynamic-versioning]
|
||||
enable = true
|
||||
style = "semver"
|
||||
|
||||
[tool.poetry.scripts]
|
||||
openhands = "openhands.core.cli:main"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user