Skip to content

Commit acf481e

Browse files
authored
Merge pull request #74 from mxstack/feature/version-option
Add --version command-line option
2 parents c836484 + c34f647 commit acf481e

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## 5.0.2 (2025-10-23)
44

5+
- 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.
6+
[jensens]
57
- 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.
68
[jensens]
79
- 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.

src/mxdev/main.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
from .processing import write
1111
from .state import State
1212

13+
14+
try:
15+
from ._version import __version__
16+
except ImportError:
17+
__version__ = "unknown (not installed)"
18+
1319
import argparse
1420
import logging
1521
import sys
@@ -48,6 +54,11 @@
4854
)
4955
parser.add_argument("-s", "--silent", help="Reduce verbosity", action="store_true")
5056
parser.add_argument("-v", "--verbose", help="Increase verbosity", action="store_true")
57+
parser.add_argument(
58+
"--version",
59+
action="version",
60+
version=f"%(prog)s {__version__}",
61+
)
5162

5263

5364
def supports_unicode() -> bool:

tests/test_main.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,39 @@ def test_parser_verbose():
9393
assert args.verbose is True
9494

9595

96+
def test_parser_version(capsys):
97+
"""Test --version prints version and exits."""
98+
from mxdev.main import __version__
99+
from mxdev.main import parser
100+
101+
import pytest
102+
103+
with pytest.raises(SystemExit) as exc_info:
104+
parser.parse_args(["--version"])
105+
106+
# Verify clean exit
107+
assert exc_info.value.code == 0
108+
109+
# Verify output contains version string
110+
captured = capsys.readouterr()
111+
assert __version__ in captured.out
112+
assert "." in captured.out # Version has dots (X.Y.Z)
113+
114+
115+
def test_version_format():
116+
"""Test version format is valid."""
117+
from mxdev.main import __version__
118+
119+
# Version should not be the fallback
120+
assert __version__ != "unknown (not installed)"
121+
122+
# Version should contain dots (semantic versioning)
123+
assert "." in __version__
124+
125+
# Version should be a string
126+
assert isinstance(__version__, str)
127+
128+
96129
def test_supports_unicode_with_utf8():
97130
"""Test supports_unicode returns True for UTF-8 encoding."""
98131
from mxdev.main import supports_unicode

0 commit comments

Comments
 (0)