Skip to content

Commit f5c349c

Browse files
committed
feat(cli): deprecate version command in favor of --version flag
Closes #3160
1 parent 1e7f306 commit f5c349c

2 files changed

Lines changed: 38 additions & 2 deletions

File tree

pyiceberg/cli/console.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from pyiceberg.io import WAREHOUSE
3434
from pyiceberg.table import TableProperties
3535
from pyiceberg.table.refs import SnapshotRef, SnapshotRefType
36+
from pyiceberg.utils.deprecated import deprecation_message
3637
from pyiceberg.utils.properties import property_as_int
3738

3839

@@ -54,6 +55,7 @@ def wrapper(*args: Any, **kwargs: Any): # type: ignore
5455

5556

5657
@click.group()
58+
@click.version_option(__version__, message="%(version)s")
5759
@click.option("--catalog")
5860
@click.option("--verbose", type=click.BOOL)
5961
@click.option("--output", type=click.Choice(["text", "json"]), default="text")
@@ -235,7 +237,17 @@ def location(ctx: Context, identifier: str) -> None:
235237
@click.pass_context
236238
@catch_exception()
237239
def version(ctx: Context) -> None:
238-
"""Print pyiceberg version."""
240+
"""Print pyiceberg's installed package number (deprecated, use ``--version`` instead)."""
241+
deprecation_message(
242+
deprecated_in="0.11.0",
243+
removed_in="1.0.0",
244+
help_message="Please use `pyiceberg --version` instead of `pyiceberg version`",
245+
)
246+
click.echo(
247+
"Deprecation warning: the `version` command is deprecated and will be removed in 1.0.0. "
248+
"Please use `pyiceberg --version` instead.",
249+
err=True,
250+
)
239251
ctx.obj["output"].version(__version__)
240252

241253

tests/cli/test_console.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,41 @@ def test_hive_catalog_missing_uri_shows_helpful_error(mocker: MockFixture) -> No
6262
assert "'uri'" not in result.output
6363

6464

65+
@pytest.mark.filterwarnings(
66+
"ignore:Deprecated in 0.11.0, will be removed in 1.0.0. "
67+
"Please use `pyiceberg --version` instead of `pyiceberg version`:DeprecationWarning"
68+
)
6569
def test_version_does_not_load_catalog(mocker: MockFixture) -> None:
6670
mock_load_catalog = mocker.patch("pyiceberg.cli.console.load_catalog", side_effect=Exception("should not be called"))
6771

6872
runner = CliRunner()
6973
result = runner.invoke(run, ["version"])
7074

7175
assert result.exit_code == 0
72-
assert result.output == f"{__version__}\n"
76+
assert __version__ in result.output
7377
mock_load_catalog.assert_not_called()
7478

7579

80+
def test_version_flag() -> None:
81+
runner = CliRunner()
82+
result = runner.invoke(run, ["--version"])
83+
84+
assert result.exit_code == 0
85+
assert result.output == f"{__version__}\n"
86+
87+
88+
def test_version_command_emits_deprecation_warning(mocker: MockFixture) -> None:
89+
mocker.patch("pyiceberg.cli.console.load_catalog")
90+
91+
runner = CliRunner()
92+
with pytest.warns(DeprecationWarning, match="Please use `pyiceberg --version` instead of `pyiceberg version`"):
93+
result = runner.invoke(run, ["version"])
94+
95+
assert result.exit_code == 0
96+
assert "deprecated" in result.output.lower()
97+
assert "pyiceberg --version" in result.output
98+
99+
76100
@pytest.fixture(autouse=True)
77101
def env_vars(mocker: MockFixture) -> None:
78102
mocker.patch.dict(os.environ, MOCK_ENVIRONMENT)

0 commit comments

Comments
 (0)