Skip to content

Commit

Permalink
Add version metadata and --version command
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkRx committed Dec 9, 2024
1 parent 39a461b commit 26a5f43
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
5 changes: 3 additions & 2 deletions pr_agent/algo/ai_handlers/litellm_ai_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from pr_agent.algo.ai_handlers.base_ai_handler import BaseAiHandler
from pr_agent.config_loader import get_settings
from pr_agent.log import get_logger
from pr_agent.version import get_version

OPENAI_RETRIES = 5

Expand Down Expand Up @@ -132,7 +133,7 @@ def capture_logs(message):
if "langfuse" in callbacks:
metadata.update({
"trace_name": command,
"tags": [git_provider, command],
"tags": [git_provider, command, f'version:{get_version()}'],
"trace_metadata": {
"command": command,
"pr_url": pr_url,
Expand All @@ -141,7 +142,7 @@ def capture_logs(message):
if "langsmith" in callbacks:
metadata.update({
"run_name": command,
"tags": [git_provider, command],
"tags": [git_provider, command, f'version:{get_version()}'],
"extra": {
"metadata": {
"command": command,
Expand Down
2 changes: 2 additions & 0 deletions pr_agent/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from pr_agent.agent.pr_agent import PRAgent, commands
from pr_agent.config_loader import get_settings
from pr_agent.log import get_logger, setup_logger
from pr_agent.version import get_version

log_level = os.environ.get("LOG_LEVEL", "INFO")
setup_logger(log_level)
Expand Down Expand Up @@ -45,6 +46,7 @@ def set_parser():
To edit any configuration parameter from 'configuration.toml', just add -config_path=<value>.
For example: 'python cli.py --pr_url=... review --pr_reviewer.extra_instructions="focus on the file: ..."'
""")
parser.add_argument('--version', action='version', version=f'pr-agent {get_version()}')
parser.add_argument('--pr_url', type=str, help='The URL of the PR to review', default=None)
parser.add_argument('--issue_url', type=str, help='The URL of the Issue to review', default=None)
parser.add_argument('command', type=str, help='The', choices=commands, default='review')
Expand Down
23 changes: 23 additions & 0 deletions pr_agent/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import os
import sys
from importlib.metadata import version, PackageNotFoundError

from pr_agent.log import get_logger

def get_version() -> str:
# First check pyproject.toml if running directly out of repository
if os.path.exists("pyproject.toml"):
if sys.version_info >= (3, 11):
import tomllib
with open("pyproject.toml", "rb") as f:
data = tomllib.load(f)
return data["project"]["version"]
else:
get_logger().error("Unable to determine local version from pyproject.toml")

# Otherwise get the installed pip package version
try:
return version('pr-agent')
except PackageNotFoundError:
get_logger().error("Unable to find package named 'pr-agent'")
return "unknown"
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "pr-agent"
version = "0.2.4"
version = "0.2.6"

authors = [{ name = "CodiumAI", email = "[email protected]" }]

Expand Down

0 comments on commit 26a5f43

Please sign in to comment.