You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@polaris.apache.org by yz...@apache.org on 2026/05/18 05:58:39 UTC
(polaris) branch main updated: CLI: Add display version support for CLI (#4463)
This is an automated email from the ASF dual-hosted git repository.
MonkeyCanCode pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/polaris.git
The following commit(s) were added to refs/heads/main by this push:
new 36fabf8a67 CLI: Add display version support for CLI (#4463)
36fabf8a67 is described below
commit 36fabf8a67be2417c181ea5e678c9d5069e4d97e
Author: Yong Zheng <yo...@gmail.com>
AuthorDate: Mon May 18 00:58:35 2026 -0500
CLI: Add display version support for CLI (#4463)
* Add version support for cli
* Add version support for cli
* Ensure openapi generator doesn't overwrite __init__.py
* Remove extra import
---
CHANGELOG.md | 1 +
client/python/.openapi-generator-ignore | 1 +
client/python/apache_polaris/__init__.py | 6 ++++++
client/python/apache_polaris/cli/options/parser.py | 6 ++++++
client/python/tests/test_parser_basic.py | 4 ++++
5 files changed, 18 insertions(+)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 59f48916bb..0311e50c2b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -51,6 +51,7 @@ request adding CHANGELOG notes for breaking (!) changes and possibly other secti
- Changed deprecated APIs in JUnit 5. This change will force downstream projects that pull in the Polaris test packages to adopt JUnit 6.
- Added client id collision check during reset.
- The `nosql maintenance-run` admin command now rejects a new run when the latest recorded maintenance run is still unfinished, unless the operator explicitly passes `--supersede-run=<run-id>`.
+- Added version option to Polaris CLI.
### Deprecations
- The configuration option `polaris.event-listener.type` is deprecated and will be removed later. Please use `polaris.event-listener.types` instead.
diff --git a/client/python/.openapi-generator-ignore b/client/python/.openapi-generator-ignore
index 36d9b89a6e..8eff2d47e2 100644
--- a/client/python/.openapi-generator-ignore
+++ b/client/python/.openapi-generator-ignore
@@ -30,6 +30,7 @@ LICENSE
NOTICE
# Source code
+apache_polaris/__init__.py
apache_polaris/cli/
# Tests
diff --git a/client/python/apache_polaris/__init__.py b/client/python/apache_polaris/__init__.py
index d8a500d9d8..08f84bdfbd 100644
--- a/client/python/apache_polaris/__init__.py
+++ b/client/python/apache_polaris/__init__.py
@@ -17,3 +17,9 @@
# under the License.
#
+from importlib.metadata import version, PackageNotFoundError
+
+try:
+ __version__ = version("apache_polaris")
+except PackageNotFoundError:
+ __version__ = "unknown"
diff --git a/client/python/apache_polaris/cli/options/parser.py b/client/python/apache_polaris/cli/options/parser.py
index 6d606c0b06..c38a2be9e8 100644
--- a/client/python/apache_polaris/cli/options/parser.py
+++ b/client/python/apache_polaris/cli/options/parser.py
@@ -19,6 +19,7 @@
import argparse
from typing import List, Optional, Dict, Any, Union
+from apache_polaris import __version__
from apache_polaris.cli.constants import Arguments, DEFAULT_HEADER
from apache_polaris.cli.exceptions import CliError
from apache_polaris.cli.options.option_tree import OptionTree, Option, Argument
@@ -147,6 +148,11 @@ class Parser(object):
usage="polaris [-h] [options] COMMAND ...",
formatter_class=PolarisHelpFormatter,
)
+ parser.add_argument(
+ "--version",
+ action="version",
+ version=f"%(prog)s {__version__}",
+ )
Parser._add_arguments(parser, Parser._ROOT_ARGUMENTS, "Global Options")
def recurse_options(
diff --git a/client/python/tests/test_parser_basic.py b/client/python/tests/test_parser_basic.py
index a90ea452f7..06bcbda5b7 100644
--- a/client/python/tests/test_parser_basic.py
+++ b/client/python/tests/test_parser_basic.py
@@ -18,6 +18,7 @@
#
import unittest
+from apache_polaris import __version__
from cli_test_utils import CLITestBase, INVALID_ARGS
from apache_polaris.cli.exceptions import CliError
from apache_polaris.cli.command import Command
@@ -149,6 +150,9 @@ class TestParserBasic(CLITestBase):
lambda: Parser.parse(["catalogs", "create", "something", "--help"])
)
+ def test_version(self) -> None:
+ self.check_usage_output(lambda: Parser.parse(["--version"]), needle=f"polaris {__version__}")
+
def test_global_flag_anywhere(self) -> None:
# Test that global flags work when placed after subcommands
options = Parser.parse(["catalogs", "list", "--host", "my-host"])