diff --git a/GANDLF/entrypoints/debug_info.py b/GANDLF/entrypoints/debug_info.py index 9890e2813..e8bc781a2 100644 --- a/GANDLF/entrypoints/debug_info.py +++ b/GANDLF/entrypoints/debug_info.py @@ -1,6 +1,8 @@ #!usr/bin/env python # -*- coding: utf-8 -*- import platform +import argparse +from pip import main from deprecated import deprecated import click @@ -8,8 +10,11 @@ from GANDLF.entrypoints import append_copyright_to_help from GANDLF.utils import get_git_hash +from GANDLF.cli import copyrightMessage -def _debug_info(): + +def _debug_info(verbose: bool): + """Function to display necessary debugging information.""" print(f"GANDLF version: {__version__}") print(f"Git hash: {get_git_hash()}") print(f"Platform: {platform.platform()}") @@ -21,13 +26,22 @@ def _debug_info(): print(f" Implementation: {platform.python_implementation()}") print(f" Compiler: {platform.python_compiler()}") print(f" Build: {(' ').join(list(platform.python_build()))}") + if verbose: + print(" Installed packages:") + print(main(["list"])) @click.command() +@click.option( + "--verbose", + "-v", + is_flag=True, + help="If passed, prints all packages installed as well", +) @append_copyright_to_help -def new_way(): +def new_way(verbose: bool): """Displays detailed info about system environment: library versions, settings, etc.""" - _debug_info() + _debug_info(verbose=verbose) # main function @@ -37,7 +51,21 @@ def new_way(): + "`gandlf_debugInfo` script would be deprecated soon." ) def old_way(): - _debug_info() + parser = argparse.ArgumentParser( + prog="GANDLF_DebugInfo", + formatter_class=argparse.RawTextHelpFormatter, + description="Generate debugging information for maintainers.\n\n" + + copyrightMessage, + ) + parser.add_argument( + "-v", + "--verbose", + action="store_true", + default=False, + help="If True, prints all packages installed as well.", + ) + args = parser.parse_args() + _debug_info(verbose=args.verbose) if __name__ == "__main__": diff --git a/testing/entrypoints/test_debug_info.py b/testing/entrypoints/test_debug_info.py index 9cf12bed0..9f70f247d 100644 --- a/testing/entrypoints/test_debug_info.py +++ b/testing/entrypoints/test_debug_info.py @@ -16,8 +16,17 @@ test_file_system = [] test_cases = [ CliCase( - should_succeed=True, new_way_lines=[""], old_way_lines=[""], expected_args={} - ) + should_succeed=True, + new_way_lines=[""], + old_way_lines=[""], + expected_args={"verbose": False}, + ), + CliCase( + should_succeed=True, + new_way_lines=["--verbose", "-v"], + old_way_lines=["--verbose", "-v"], + expected_args={"verbose": True}, + ), ]