diff --git a/CHANGES.md b/CHANGES.md index 025654a..3bc2a65 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,8 @@ ## 5.0.2 (2025-10-23) +- Feature: Added `--version` command-line option to display the current mxdev version. The version is automatically derived from git tags via hatch-vcs during build. Example: `mxdev --version` outputs "mxdev 5.0.1" for releases or "mxdev 5.0.1.dev27+g62877d7" for development versions. + [jensens] - Fix #70: HTTP-referenced requirements/constraints files are now properly cached and respected in offline mode. Previously, offline mode only skipped VCS operations but still fetched HTTP URLs. Now mxdev caches all HTTP content in `.mxdev_cache/` during online mode and reuses it during offline mode, enabling true offline operation. This fixes the inconsistent behavior where `-o/--offline` didn't prevent all network activity. [jensens] - Improvement: Enhanced help text for `-n/--no-fetch`, `-f/--fetch-only`, and `-o/--offline` command-line options to better explain their differences and when to use each one. diff --git a/src/mxdev/main.py b/src/mxdev/main.py index eb591e4..0b0717e 100644 --- a/src/mxdev/main.py +++ b/src/mxdev/main.py @@ -10,6 +10,12 @@ from .processing import write from .state import State + +try: + from ._version import __version__ +except ImportError: + __version__ = "unknown (not installed)" + import argparse import logging import sys @@ -48,6 +54,11 @@ ) parser.add_argument("-s", "--silent", help="Reduce verbosity", action="store_true") parser.add_argument("-v", "--verbose", help="Increase verbosity", action="store_true") +parser.add_argument( + "--version", + action="version", + version=f"%(prog)s {__version__}", +) def supports_unicode() -> bool: diff --git a/tests/test_main.py b/tests/test_main.py index 68ddbf9..fc5128f 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -93,6 +93,39 @@ def test_parser_verbose(): assert args.verbose is True +def test_parser_version(capsys): + """Test --version prints version and exits.""" + from mxdev.main import __version__ + from mxdev.main import parser + + import pytest + + with pytest.raises(SystemExit) as exc_info: + parser.parse_args(["--version"]) + + # Verify clean exit + assert exc_info.value.code == 0 + + # Verify output contains version string + captured = capsys.readouterr() + assert __version__ in captured.out + assert "." in captured.out # Version has dots (X.Y.Z) + + +def test_version_format(): + """Test version format is valid.""" + from mxdev.main import __version__ + + # Version should not be the fallback + assert __version__ != "unknown (not installed)" + + # Version should contain dots (semantic versioning) + assert "." in __version__ + + # Version should be a string + assert isinstance(__version__, str) + + def test_supports_unicode_with_utf8(): """Test supports_unicode returns True for UTF-8 encoding.""" from mxdev.main import supports_unicode