Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion dargs/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,29 @@
import argparse
import json
import sys
from importlib import import_module
from typing import IO, Any

from dargs._version import __version__
try:
from dargs._version import __version__
except ModuleNotFoundError as exc:
if exc.name != "dargs._version":
raise
try:
get_version = getattr(import_module("setuptools_scm"), "get_version")
except ModuleNotFoundError as scm_exc:
if scm_exc.name != "setuptools_scm":
raise
# Source archives may have neither the generated module nor build tools.
# The CLI should remain usable even when an exact version is unavailable.
__version__ = "0+unknown"
else:
__version__ = get_version(
root="..",
relative_to=__file__,
fallback_version="0+unknown",
)

from dargs.check import check


Expand Down
10 changes: 10 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@


class TestCli(unittest.TestCase):
def test_version_with_python_module(self) -> None:
"""The source checkout exposes a version without generated build files."""
result = subprocess.run(
[sys.executable, "-m", "dargs", "--version"],
capture_output=True,
text=True,
check=True,
)
self.assertTrue(result.stdout.strip())

def test_check(self) -> None:
subprocess.check_call(
[
Expand Down