Version
All CLI applications should have the basic ability to check the installed version; i.e.:
$ my-application --version
7.5.8
By default, Cyclopts adds a command, --version:, that does exactly this.
Cyclopts try's to reasonably figure out your package's version by itself.
The resolution order for determining the version string is as follows:
An explicitly supplied version string or callable to the root Cyclopts application:
from cyclopts import App app = App(version="7.5.8") app()
If a callable is provided, it will be invoked when running the
--versioncommand:from cyclopts import App def get_my_application_version() -> str: return "7.5.8" app = App(version=get_my_application_version) app()
The invoking-package's Distribution Package's Version Number via importlib.metadata.version. Cyclopts attempts to derive the package module that instantiated the
Appobject by traversing the call stack.The invoking-package's defacto PEP8 standard
__version__string. Cyclopts attempts to derive the package module that instantiated theAppobject by traversing the call stack.# mypackage/__init__.py __version__ = "7.5.8" # mypackage/__main__.py # ``App`` will use ``mypackage.__version__``. app = cyclopts.App()
The default version string
"0.0.0"will be displayed.
In short, if your CLI application is a properly structured python package, Cyclopts will automatically derive the correct version.
The --version flag can be changed to a different name(s) via the version_flags parameter.
app = cyclopts.App(version_flags="--show-version")
app = cyclopts.App(version_flags=["--version", "-v"])
To disable the --version flag, set version_flags to an empty string or iterable.
app = cyclopts.App(version_flags="")
app = cyclopts.App(version_flags=[])