-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathshow_version.py
executable file
·184 lines (166 loc) · 4.82 KB
/
show_version.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/usr/bin/env python
########################################################################
# show_version.py: Show Python Modules Info and Version
#
# Description:
# This script displays detailed information and versions for a list of
# specified Python modules. It also shows the Python version upon request.
# Instead of displaying 'not found' messages immediately, it collects them
# and displays a summary of missing modules at the end.
# It's useful for quickly checking the installed versions of various packages.
#
# Author: id774 (More info: http://id774.net)
# Source Code: https://github.com/id774/scripts
# License: LGPLv3 (Details: https://www.gnu.org/licenses/lgpl-3.0.html)
# Contact: [email protected]
#
# Version History:
# v2.5 2024-01-18
# Refactored function names for clarity.
# Improved comments for better understanding.
# v2.4 2024-01-06
# Added functionality to display a summary of not found modules at the end.
# v2.3 2020-11-05
# Using importlib instead of imp.
# v2.2 2015-09-28
# Refactoring.
# v2.1 2014-03-19
# Show python version.
# v2.0 2014-02-11
# Simple version listing.
# Using -i option for detailed info.
# v1.2 2014-02-10
# Remove install process.
# v1.1 2011-06-29
# Add some packages.
# v1.0 2008-08-15
# Stable.
#
# Usage:
# To display the versions of predefined modules:
# python show_version.py
#
# To display detailed information of predefined modules:
# python show_version.py -i
#
# To display the Python version:
# python show_version.py -p
#
########################################################################
import importlib
import sys
import warnings
class PythonModuleInfo:
def __init__(self, options):
self.info = options.info
self.python = options.python
self.not_found = []
def display_module_help(self, module_name):
""" Display help information for the specified module. """
try:
module = importlib.import_module(module_name)
help(module)
except ImportError:
self.not_found.append(module_name)
def get_module_version(self, module_name):
""" Get and display the version of the specified module. """
try:
obj = importlib.import_module(module_name)
if hasattr(obj, "__version__"):
print(module_name, obj.__version__)
elif hasattr(obj, "VERSION"):
print(module_name, obj.VERSION)
else:
print(module_name, "unknown version")
except ImportError:
self.not_found.append(module_name)
def get_info(self, module_name):
if self.info:
self.display_module_help(module_name)
else:
self.get_module_version(module_name)
def get_python_version(self):
if self.python:
python_version = sys.version
print("Python %(python_version)s" % locals())
def show_not_found(self):
if self.not_found:
print("\nThese modules were not found:")
for module in self.not_found:
print(module)
def main():
from optparse import OptionParser
usage = "usage: %prog [options] file"
parser = OptionParser(usage)
parser.add_option("-i", "--info", help="show detail info",
action="store_true", dest="info")
parser.add_option("-p", "--python", help="show python version",
action="store_true", dest="python")
(options, args) = parser.parse_args()
m = PythonModuleInfo(options)
m.get_python_version()
packages = [
'pip',
'IPython',
'pyflakes',
'flake8',
'pytest',
'autopep8',
'autoflake',
'cython',
'docutils',
'docopt',
'simplejson',
'numpy',
'scipy',
'sklearn',
'matplotlib',
'pandas',
'tensorflow',
'keras',
'joblib',
'dask',
'patsy',
'statsmodels',
'sympy',
'pystan',
'seaborn',
'bokeh',
'twisted',
'flask',
'django',
'sqlalchemy',
'lmdb',
'migrate',
'pygments',
'babel',
'genshi',
'bottle',
'cherrypy',
'bs4',
'lxml',
'requests',
'pysolr',
'html5lib',
'PIL',
'pyper',
'awscli',
'openpyxl',
'simpy',
'networkx',
'fabric',
'talib',
'zipline',
'instaloader',
'nltk',
'MeCab',
'CaboCha'
]
warnings.resetwarnings()
with warnings.catch_warnings():
warnings.simplefilter('ignore')
for p in packages:
m.get_info(p)
m.show_not_found()
if __name__ == '__main__':
main()