Skip to content

Add -v/--version to optimum-cli - #2530

Open
manunicholasjacob wants to merge 1 commit into
huggingface:mainfrom
manunicholasjacob:cli-version-flag
Open

manunicholasjacob wants to merge 1 commit into
huggingface:mainfrom
manunicholasjacob:cli-version-flag

Conversation

@manunicholasjacob

Copy link
Copy Markdown

What does this PR do?

Adds -v / --version to optimum-cli, as requested in huggingface/optimum-intel#1447, where @IlyasMoutawwakil suggested opening a PR for it.

The flag prints the optimum version, then one line per installed optimum-* package, and exits:

$ optimum-cli --version
optimum 2.4.0.dev0
optimum-onnx 0.1.0

I used a small custom argparse Action instead of action="version" for two reasons. The built-in action reflows its text onto a single line, so the per-package lines get joined. It also needs the string when the parser is built, which would mean scanning installed distributions on every CLI start. The custom action only does the lookup when the flag is passed.

This is separate from #2188 (optimum.__version__ attribute) and does not touch it.

How I tested

WSL2 Ubuntu, Python 3.12.13, optimum main at 0df84f2.

  • New test tests/cli/test_cli.py::TestCLI::test_version_flag: fails on main (optimum-cli --version exits with status 2, unrecognized argument) and passes with this change. test_env_commands still passes.
  • ruff==0.1.5 and black~=23.1 (the versions pinned in setup.py) report no changes on both files.
  • Ran it by hand with and without optimum-onnx installed: one line without it, two lines with it. optimum-cli --help now lists the new flag.

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests?

Who can review?

@IlyasMoutawwakil

AI-assisted (Claude); I reviewed the change and ran the tests above.

Prints the optimum version and the version of each installed optimum-* subpackage, then exits.
Requested in huggingface/optimum-intel#1447.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant