Add kumacli version and link it into setup.py
This commit is contained in:
16
setup.py
16
setup.py
@@ -1,13 +1,27 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import os
|
||||
import re
|
||||
from setuptools import setup, find_packages
|
||||
|
||||
# Read version directly from version.py file without importing
|
||||
def get_version():
|
||||
version_file = os.path.join(os.path.dirname(__file__), 'src', 'kumacli', 'cmd', 'version.py')
|
||||
with open(version_file, 'r', encoding='utf-8') as f:
|
||||
content = f.read()
|
||||
version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", content, re.M)
|
||||
if version_match:
|
||||
return version_match.group(1)
|
||||
raise RuntimeError("Unable to find version string.")
|
||||
|
||||
__version__ = get_version()
|
||||
|
||||
with open("README.md", "r", encoding="utf-8") as fh:
|
||||
long_description = fh.read()
|
||||
|
||||
setup(
|
||||
name="kumacli",
|
||||
version="1.3.0",
|
||||
version=__version__,
|
||||
author="Uptime Kuma CLI",
|
||||
description="A command-line interface for Uptime Kuma",
|
||||
long_description=long_description,
|
||||
|
@@ -2,10 +2,10 @@
|
||||
KumaCLI - A command-line interface for Uptime Kuma
|
||||
"""
|
||||
|
||||
__version__ = "1.0.0"
|
||||
from kumacli.kumacli import main
|
||||
from kumacli.cmd.version import __version__
|
||||
|
||||
__author__ = "KumaCLI Team"
|
||||
__email__ = "info@kumacli.com"
|
||||
|
||||
from kumacli.kumacli import main
|
||||
|
||||
__all__ = ["main"]
|
||||
|
16
src/kumacli/cmd/version.py
Normal file
16
src/kumacli/cmd/version.py
Normal file
@@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Version command implementations for Uptime Kuma CLI."""
|
||||
|
||||
__version__ = "1.4.0"
|
||||
|
||||
|
||||
def setup_version_parser(subparsers):
|
||||
"""Setup version command parser"""
|
||||
version_parser = subparsers.add_parser("version", help="Show version information")
|
||||
return version_parser
|
||||
|
||||
|
||||
def handle_version_command(args, client): # pylint: disable=unused-argument
|
||||
"""Handle version command execution"""
|
||||
print(f"kumacli {__version__}")
|
||||
return True
|
@@ -11,6 +11,7 @@ try:
|
||||
from .cmd.monitor import setup_monitor_parser, handle_monitor_command
|
||||
from .cmd.maintenance import setup_maintenance_parser, handle_maintenance_command
|
||||
from .cmd.info import setup_info_parser, handle_info_command
|
||||
from .cmd.version import setup_version_parser, handle_version_command
|
||||
except ImportError:
|
||||
# Running directly, add parent directory to path
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
@@ -21,6 +22,7 @@ except ImportError:
|
||||
handle_maintenance_command,
|
||||
)
|
||||
from kumacli.cmd.info import setup_info_parser, handle_info_command
|
||||
from kumacli.cmd.version import setup_version_parser, handle_version_command
|
||||
|
||||
|
||||
def main():
|
||||
@@ -44,6 +46,7 @@ def main():
|
||||
setup_monitor_parser(subparsers)
|
||||
setup_maintenance_parser(subparsers)
|
||||
setup_info_parser(subparsers)
|
||||
setup_version_parser(subparsers)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
@@ -75,6 +78,8 @@ def main():
|
||||
success = handle_maintenance_command(args, client)
|
||||
elif args.resource == "info":
|
||||
success = handle_info_command(args, client)
|
||||
elif args.resource == "version":
|
||||
success = handle_version_command(args, client)
|
||||
else:
|
||||
parser.print_help()
|
||||
sys.exit(1)
|
||||
|
31
tests/test_version.py
Normal file
31
tests/test_version.py
Normal file
@@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import pytest
|
||||
from unittest.mock import Mock
|
||||
|
||||
from kumacli.cmd.version import handle_version_command, __version__
|
||||
|
||||
|
||||
class TestVersionCommand:
|
||||
def test_handle_version_command(self, mock_client, capsys):
|
||||
"""Test version command handler"""
|
||||
# Setup
|
||||
mock_args = Mock()
|
||||
|
||||
# Execute
|
||||
result = handle_version_command(mock_args, mock_client)
|
||||
|
||||
# Verify
|
||||
assert result is True
|
||||
captured = capsys.readouterr()
|
||||
assert f"kumacli {__version__}" in captured.out
|
||||
|
||||
def test_version_is_defined(self):
|
||||
"""Test that version is properly defined"""
|
||||
assert __version__ is not None
|
||||
assert isinstance(__version__, str)
|
||||
assert len(__version__) > 0
|
||||
# Version should follow semantic versioning pattern (e.g., "1.4.0")
|
||||
parts = __version__.split(".")
|
||||
assert len(parts) >= 2 # At least major.minor
|
||||
assert all(part.isdigit() for part in parts) # All parts should be numeric
|
Reference in New Issue
Block a user