From 4e4fb5f08db9b20a1b7915945a44f2e8201ecbb8 Mon Sep 17 00:00:00 2001 From: Jacob Lee Date: Tue, 31 Oct 2023 14:50:04 -0700 Subject: [PATCH] Adds version CLI command (#12619) Will be automatically bumped with `poetry version patch`. @efriis @hwchase17 --------- Co-authored-by: Erick Friis --- libs/cli/CONTRIBUTING.md | 3 +++ libs/cli/DOCS.md | 1 + libs/cli/langchain_cli/cli.py | 22 ++++++++++++++++++++++ libs/cli/pyproject.toml | 8 +++++++- 4 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 libs/cli/CONTRIBUTING.md diff --git a/libs/cli/CONTRIBUTING.md b/libs/cli/CONTRIBUTING.md new file mode 100644 index 0000000000000..dcbd2c06b2401 --- /dev/null +++ b/libs/cli/CONTRIBUTING.md @@ -0,0 +1,3 @@ +# Contributing to langchain-cli + +Update CLI versions with `poe bump` to ensure that version commands display correctly. diff --git a/libs/cli/DOCS.md b/libs/cli/DOCS.md index 47f4d6647f76b..d08ba956aa5e2 100644 --- a/libs/cli/DOCS.md +++ b/libs/cli/DOCS.md @@ -9,6 +9,7 @@ $ langchain [OPTIONS] COMMAND [ARGS]... **Options**: * `--help`: Show this message and exit. +* `-v, --version`: Print current CLI version. **Commands**: diff --git a/libs/cli/langchain_cli/cli.py b/libs/cli/langchain_cli/cli.py index 119209c1d88fb..9751a503851af 100644 --- a/libs/cli/langchain_cli/cli.py +++ b/libs/cli/langchain_cli/cli.py @@ -6,6 +6,8 @@ from langchain_cli.namespaces import app as app_namespace from langchain_cli.namespaces import template as template_namespace +__version__ = "0.0.11" + app = typer.Typer(no_args_is_help=True, add_completion=False) app.add_typer( template_namespace.package_cli, name="template", help=template_namespace.__doc__ @@ -13,6 +15,26 @@ app.add_typer(app_namespace.app_cli, name="app", help=app_namespace.__doc__) +def version_callback(show_version: bool) -> None: + if show_version: + typer.echo(f"langchain-cli {__version__}") + raise typer.Exit() + + +@app.callback() +def main( + version: bool = typer.Option( + False, + "--version", + "-v", + help="Print the current CLI version.", + callback=version_callback, + is_eager=True, + ), +): + pass + + @app.command() def serve( *, diff --git a/libs/cli/pyproject.toml b/libs/cli/pyproject.toml index 9fc827408b55f..e92ddea0807d3 100644 --- a/libs/cli/pyproject.toml +++ b/libs/cli/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "langchain-cli" -version = "0.0.10" +version = "0.0.11" description = "CLI for interacting with LangChain" authors = ["Erick Friis "] readme = "README.md" @@ -44,9 +44,15 @@ select = [ [tool.poe.tasks] test = "poetry run pytest" watch = "poetry run ptw" +version = "poetry version --short" +bump = ["_bump_1", "_bump_2"] lint = ["_lint", "_check_formatting"] format = ["_lint_fix", "_format"] +_bump_2.shell = """sed -i "" "/^__version__ =/c\\ \n__version__ = \\"$version\\"\n" langchain_cli/cli.py""" +_bump_2.uses = { version = "version" } + +_bump_1 = "poetry version patch" _check_formatting = "poetry run ruff format . --diff" _lint = "poetry run ruff ." _format = "poetry run ruff format ."