Skip to content

Commit

Permalink
(feat) add --version to cli (#3924)
Browse files Browse the repository at this point in the history
  • Loading branch information
tobitege authored Sep 18, 2024
1 parent f7ebc1c commit c3117e8
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
28 changes: 28 additions & 0 deletions openhands/__init__.py
Original file line number Diff line number Diff line change
@@ -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'
26 changes: 26 additions & 0 deletions openhands/core/cli.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import argparse
import asyncio
import logging
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 (
Expand Down Expand Up @@ -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'
Expand Down
9 changes: 7 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ reportlab = "*"
[tool.coverage.run]
concurrency = ["gevent"]


[tool.poetry.group.runtime.dependencies]
jupyterlab = "*"
notebook = "*"
Expand Down Expand Up @@ -116,7 +115,6 @@ ignore = ["D1"]
[tool.ruff.lint.pydocstyle]
convention = "google"


[tool.poetry.group.evaluation.dependencies]
streamlit = "*"
whatthepatch = "*"
Expand All @@ -128,3 +126,10 @@ sympy = "*"
gdown = "*"
matplotlib = "*"
seaborn = "*"

[tool.poetry-dynamic-versioning]
enable = true
style = "semver"

[tool.poetry.scripts]
openhands = "openhands.core.cli:main"

0 comments on commit c3117e8

Please sign in to comment.