Skip to content

Commit fd7ea2b

Browse files
authored
Merge branch 'main' into issue1564
2 parents 503ab82 + 99928f8 commit fd7ea2b

2 files changed

Lines changed: 52 additions & 0 deletions

File tree

openml/cli.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from urllib.parse import urlparse
1212

1313
from openml import config
14+
from openml.__version__ import __version__
1415

1516

1617
def is_hex(string_: str) -> bool:
@@ -332,6 +333,13 @@ def main() -> None:
332333
subroutines = {"configure": configure}
333334

334335
parser = argparse.ArgumentParser()
336+
# Add a global --version flag to display installed version and exit
337+
parser.add_argument(
338+
"--version",
339+
action="version",
340+
version=f"%(prog)s {__version__}",
341+
help="Show the OpenML version and exit",
342+
)
335343
subparsers = parser.add_subparsers(dest="subroutine")
336344

337345
parser_configure = subparsers.add_parser(

tests/test_openml/test_cli.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# License: BSD 3-Clause
2+
from __future__ import annotations
3+
4+
import shutil
5+
import subprocess
6+
import sys
7+
8+
import openml
9+
import pytest
10+
11+
12+
def test_cli_version_prints_package_version():
13+
# Invoke the CLI via module to avoid relying on console script installation
14+
result = subprocess.run(
15+
[sys.executable, "-m", "openml.cli", "--version"],
16+
stdout=subprocess.PIPE,
17+
stderr=subprocess.PIPE,
18+
text=True,
19+
check=False,
20+
)
21+
22+
# Ensure successful exit and version present in stdout only
23+
assert result.returncode == 0
24+
assert result.stderr == ""
25+
assert openml.__version__ in result.stdout
26+
27+
28+
def test_console_script_version_prints_package_version():
29+
# Try to locate the console script; skip if not installed in PATH
30+
console = shutil.which("openml")
31+
if console is None:
32+
pytest.skip("'openml' console script not found in PATH")
33+
34+
result = subprocess.run(
35+
[console, "--version"],
36+
stdout=subprocess.PIPE,
37+
stderr=subprocess.PIPE,
38+
text=True,
39+
check=False,
40+
)
41+
42+
assert result.returncode == 0
43+
assert result.stderr == ""
44+
assert openml.__version__ in result.stdout

0 commit comments

Comments
 (0)