sh_cpl/src/cpl_cli/command/version.py

48 lines
1.5 KiB
Python
Raw Normal View History

2021-03-03 19:37:35 +01:00
import os
import pkgutil
import sys
import platform
import pkg_resources
import cpl
import cpl_cli
from cpl.console.console import Console
2021-03-10 20:53:08 +01:00
from cpl.console.foreground_color import ForegroundColor
2021-03-04 17:36:02 +01:00
from cpl_cli.command_abc import CommandABC
2021-03-03 19:37:35 +01:00
2021-03-04 17:36:02 +01:00
class Version(CommandABC):
2021-03-03 19:37:35 +01:00
def __init__(self):
2021-03-04 17:36:02 +01:00
CommandABC.__init__(self)
2021-03-03 19:37:35 +01:00
def run(self, args: list[str]):
2021-03-10 20:53:08 +01:00
Console.set_foreground_color(ForegroundColor.yellow)
2021-03-03 19:37:35 +01:00
Console.banner('CPL CLI')
2021-03-10 20:55:33 +01:00
Console.set_foreground_color(ForegroundColor.default)
2021-03-03 19:37:35 +01:00
if '__version__' in dir(cpl_cli):
2021-03-10 20:55:33 +01:00
Console.write_line(f'Common Python library CLI: ')
2021-03-10 20:53:08 +01:00
Console.write(cpl_cli.__version__)
Console.write_line(f'Python: ')
Console.write(f'{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}')
2021-03-03 19:37:35 +01:00
Console.write_line(f'OS: {platform.system()} {platform.processor()}')
2021-03-10 20:53:08 +01:00
Console.write_line('\nCPL packages:')
2021-03-03 19:37:35 +01:00
packages = []
for importer, modname, is_pkg in pkgutil.iter_modules(cpl.__path__):
module = importer.find_module(modname).load_module(modname)
if '__version__' in dir(module):
packages.append([f'{modname}', module.__version__])
Console.table(['Name', 'Version'], packages)
2021-03-10 20:53:08 +01:00
Console.write_line('\nPython packages:')
2021-03-03 19:37:35 +01:00
packages = []
dependencies = dict(tuple(str(ws).split()) for ws in pkg_resources.working_set)
for p in dependencies:
packages.append([p, dependencies[p]])
Console.table(['Name', 'Version'], packages)