Last active
June 27, 2022 08:20
-
-
Save kidpixo/00b849b8f3f59664b7314eb6471c7bf1 to your computer and use it in GitHub Desktop.
Pyhton function to check installed packages version from shell. Pure python, no requirements. Now with CLI colors!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
"""Pyhton function to check installed packages version from shell. Pure python, no requirements. | |
""" | |
# define CLI colors | |
RED = '\033[31m' # mode 31 = red forground | |
GREEN = '\033[1;32m' # mode 32 = green forground | |
CYAN = '\033[34m' # mode 32 = green forground | |
RESET = '\033[0m' # mode 0 = reset | |
import sys | |
print('='*50) | |
version=sys.version.replace('\n','| ') | |
print(f"python intepreter : {sys.executable}") | |
print(f" python version : {version}") | |
print('='*50) | |
import traceback | |
for p in sys.argv[1:]: | |
try: | |
i = __import__(p) | |
print(f'{GREEN}package "{p}:{i.__version__}" present{RESET}') | |
except ImportError: | |
print(f'{RED}ERROR : package "{p}" not importable{RESET}') | |
except AttributeError: | |
print(f'{CYAN}WARNING : package "{p}" imported, but has no "__version__" attribute{RESET}') | |
except: | |
print('Unexpected error in package "{}": {}'.format(p, sys.exc_info()[0])) | |
traceback.print_exc() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment