diff --git a/manageprojects/cli/cli_app.py b/manageprojects/cli/cli_app.py index f2dff75..ba38ed0 100644 --- a/manageprojects/cli/cli_app.py +++ b/manageprojects/cli/cli_app.py @@ -11,6 +11,7 @@ import rich_click as click from bx_py_utils.path import assert_is_dir, assert_is_file from cli_base.cli_tools.subprocess_utils import verbose_check_call +from cli_base.cli_tools.version_info import print_version from rich import print # noqa from rich_click import RichGroup @@ -30,7 +31,6 @@ from manageprojects.data_classes import CookiecutterResult from manageprojects.format_file import format_one_file from manageprojects.utilities.log_utils import log_config -from manageprojects.utilities.version_info import print_version logger = logging.getLogger(__name__) diff --git a/manageprojects/cli/dev.py b/manageprojects/cli/dev.py index 8dacdf8..92562a1 100644 --- a/manageprojects/cli/dev.py +++ b/manageprojects/cli/dev.py @@ -8,6 +8,7 @@ import rich_click as click from bx_py_utils.path import assert_is_file from cli_base.cli_tools.subprocess_utils import verbose_check_call +from cli_base.cli_tools.version_info import print_version from rich import print # noqa; noqa from rich_click import RichGroup @@ -15,7 +16,6 @@ from manageprojects import constants from manageprojects.utilities import code_style from manageprojects.utilities.publish import publish_package -from manageprojects.utilities.version_info import print_version logger = logging.getLogger(__name__) diff --git a/manageprojects/tests/test_version_info.py b/manageprojects/tests/test_version_info.py deleted file mode 100644 index 6ee7d63..0000000 --- a/manageprojects/tests/test_version_info.py +++ /dev/null @@ -1,44 +0,0 @@ -from pathlib import Path -from unittest import TestCase - -from bx_py_utils.test_utils.redirect import RedirectOut - -import manageprojects -from manageprojects import __version__ -from manageprojects.cli.cli_app import PACKAGE_ROOT -from manageprojects.git import Git -from manageprojects.test_utils.logs import AssertLogs -from manageprojects.utilities.temp_path import TemporaryDirectory -from manageprojects.utilities.version_info import print_version - - -class VersionInfoTestCase(TestCase): - maxDiff = None - - def test_temp_content_file(self): - git = Git(cwd=PACKAGE_ROOT) - git_hash = git.get_current_hash(verbose=False) - - with RedirectOut() as buffer: - print_version(module=manageprojects) - - self.assertEqual(buffer.stderr, '') - self.assertEqual(buffer.stdout, f'manageprojects v{__version__} {git_hash} ({PACKAGE_ROOT})\n') - - def test_no_git(self): - with RedirectOut() as buffer: - print_version(module=manageprojects, project_root=Path('foo', 'bar')) - - self.assertEqual(buffer.stderr, '') - self.assertEqual(buffer.stdout, f'manageprojects v{__version__} (No git found for: foo/bar)\n') - - with TemporaryDirectory(prefix='test_no_git') as temp_path: - non_git_path = temp_path / '.git' - non_git_path.mkdir() - - with AssertLogs(self, loggers=('manageprojects',)) as logs, RedirectOut() as buffer: - print_version(module=manageprojects, project_root=temp_path) - - self.assertIn(f'manageprojects v{__version__} ', buffer.stdout) - - logs.assert_in('Error print version', 'Traceback') diff --git a/manageprojects/utilities/version_info.py b/manageprojects/utilities/version_info.py index dbf0002..52ba2a4 100644 --- a/manageprojects/utilities/version_info.py +++ b/manageprojects/utilities/version_info.py @@ -1,35 +1,15 @@ -import logging -from pathlib import Path +import warnings -from rich import print # noqa +from cli_base.cli_tools.version_info import print_version as new_print_version -from manageprojects.git import Git - -logger = logging.getLogger(__name__) - - -def _print_version(module, project_root: Path = None): - print(f'[bold][green]{module.__name__}[/green] v', end='') - print(module.__version__, end=' ') - - if not project_root: - project_root = Path(module.__file__).parent.parent - git_path = project_root / '.git' - if git_path.is_dir(): - git = Git(cwd=git_path) - current_hash = git.get_current_hash(verbose=False) - print(f'[blue]{current_hash}[/blue]', end=' ') - print(f'([white]{git.cwd}[/white])') - else: - print(f'(No git found for: {project_root})') - - -def print_version(module, project_root: Path = None) -> None: - try: - _print_version(module=module, project_root=project_root) - except Exception as err: - logger.exception('Error print version: %s', err) - - # Catch all errors, otherwise the CLI is not usable ;) - print(f'{module} (print version error: {err})') +def print_version(*args, **kwargs) -> None: + """ + DEPRECATED: Migrate to: cli_base.cli_tools.version_info.print_version ! + """ + warnings.warn( + 'Migrate to: cli_base.cli_tools.version_info.print_version !', + DeprecationWarning, + stacklevel=2, + ) + new_print_version(*args, **kwargs) diff --git a/pyproject.toml b/pyproject.toml index e70eb00..c2063e8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,7 +27,7 @@ dependencies = [ "codespell", # https://github.com/codespell-project/codespell "mypy", # https://github.com/python/mypy - "cli-base-utilities", # https://github.com/jedie/cli-base-utilities + "cli-base-utilities>=0.3.0", # https://github.com/jedie/cli-base-utilities "click", # https://github.com/pallets/click/ "rich-click", # https://github.com/ewels/rich-click "rich", # https://github.com/Textualize/rich diff --git a/requirements.dev.txt b/requirements.dev.txt index c4f5c10..9f628ad 100644 --- a/requirements.dev.txt +++ b/requirements.dev.txt @@ -217,9 +217,9 @@ charset-normalizer==3.2.0 \ --hash=sha256:f779d3ad205f108d14e99bb3859aa7dd8e9c68874617c72354d7ecaec2a054ac \ --hash=sha256:f87f746ee241d30d6ed93969de31e5ffd09a2961a051e60ae6bddde9ec3583aa # via requests -cli-base-utilities==0.2.0 \ - --hash=sha256:4fb89f4980c45eeeae69c7d745ddf7449740d42a072a42dd2c46ae1519ad7128 \ - --hash=sha256:5edd26c07063ab031e30712c80fd3b8a2b9dffe33143ebd25cb1bc932a55488e +cli-base-utilities==0.3.0 \ + --hash=sha256:1a59a0a61d853b4d3f4944e7494af139bccb3cca4e7766e94f452c2f131a1d59 \ + --hash=sha256:ca73cf149e5fd10312d450d9919a1ed87222c7bdd6479e94ab670ece4d91e8ba # via manageprojects (pyproject.toml) click==8.1.6 \ --hash=sha256:48ee849951919527a045bfe3bf7baa8a959c423134e1a5b98c05c20ba75a1cbd \ diff --git a/requirements.txt b/requirements.txt index b04c4e5..a0f105b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -137,9 +137,9 @@ charset-normalizer==3.2.0 \ --hash=sha256:f779d3ad205f108d14e99bb3859aa7dd8e9c68874617c72354d7ecaec2a054ac \ --hash=sha256:f87f746ee241d30d6ed93969de31e5ffd09a2961a051e60ae6bddde9ec3583aa # via requests -cli-base-utilities==0.2.0 \ - --hash=sha256:4fb89f4980c45eeeae69c7d745ddf7449740d42a072a42dd2c46ae1519ad7128 \ - --hash=sha256:5edd26c07063ab031e30712c80fd3b8a2b9dffe33143ebd25cb1bc932a55488e +cli-base-utilities==0.3.0 \ + --hash=sha256:1a59a0a61d853b4d3f4944e7494af139bccb3cca4e7766e94f452c2f131a1d59 \ + --hash=sha256:ca73cf149e5fd10312d450d9919a1ed87222c7bdd6479e94ab670ece4d91e8ba # via manageprojects (pyproject.toml) click==8.1.6 \ --hash=sha256:48ee849951919527a045bfe3bf7baa8a959c423134e1a5b98c05c20ba75a1cbd \