source: trunk/misc/build_helpers/show-tool-versions.py

Last change on this file was fbbf1cf, checked in by Itamar Turner-Trauring <itamar@…>, at 2023-11-17T15:46:41Z

Stop using pkg_resources

  • Property mode set to 100644
File size: 4.7 KB
Line 
1#! /usr/bin/env python
2
3import locale, os, platform, subprocess, sys, traceback
4from importlib.metadata import version, PackageNotFoundError
5
6
7def foldlines(s, numlines=None):
8    lines = s.split("\n")
9    if numlines is not None:
10        lines = lines[:numlines]
11    return " ".join(lines).replace("\r", "")
12
13
14def print_platform():
15    try:
16        import platform
17        out = platform.platform()
18        print("platform:", foldlines(out))
19        print("machine: ", platform.machine())
20        if hasattr(platform, 'linux_distribution'):
21            print("linux_distribution:", repr(platform.linux_distribution()))
22    except EnvironmentError:
23        sys.stderr.write("\nGot exception using 'platform'. Exception follows\n")
24        traceback.print_exc(file=sys.stderr)
25        sys.stderr.flush()
26
27
28def print_python_ver():
29    print("python:", foldlines(sys.version))
30    print('maxunicode: ' + str(sys.maxunicode))
31
32
33def print_python_encoding_settings():
34    print('filesystem.encoding: ' + str(sys.getfilesystemencoding()))
35    print('locale.getpreferredencoding: ' + str(locale.getpreferredencoding()))
36    try:
37        print('locale.defaultlocale: ' + str(locale.getdefaultlocale()))
38    except ValueError as e:
39        print('got exception from locale.getdefaultlocale(): ', e)
40    print('locale.locale: ' + str(locale.getlocale()))
41
42def print_stdout(cmdlist, label=None, numlines=None):
43    try:
44        if label is None:
45            label = cmdlist[0]
46        res = subprocess.Popen(cmdlist, stdin=open(os.devnull),
47                               stdout=subprocess.PIPE).communicate()[0]
48        print(label + ': ' + foldlines(res.decode('utf-8'), numlines))
49    except EnvironmentError as e:
50        if isinstance(e, OSError) and e.errno == 2:
51            print(label + ': no such file or directory')
52            return
53        sys.stderr.write("\nGot exception invoking '%s'. Exception follows.\n" % (cmdlist[0],))
54        traceback.print_exc(file=sys.stderr)
55        sys.stderr.flush()
56
57
58def print_as_ver():
59    if os.path.exists('a.out'):
60        print("WARNING: a file named a.out exists, and getting the version of the 'as' assembler "
61              "writes to that filename, so I'm not attempting to get the version of 'as'.")
62        return
63    try:
64        stdout, stderr = subprocess.Popen(['as', '-version'], stdin=open(os.devnull),
65                               stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
66        print('as: ' + foldlines(stdout.decode('utf-8') + ' ' + stderr.decode('utf-8')))
67        if os.path.exists('a.out'):
68            os.remove('a.out')
69    except EnvironmentError:
70        sys.stderr.write("\nGot exception invoking '%s'. Exception follows.\n" % ('as',))
71        traceback.print_exc(file=sys.stderr)
72        sys.stderr.flush()
73
74def print_setuptools_ver():
75    try:
76        print("setuptools:", version("setuptools"))
77    except PackageNotFoundError:
78        print('setuptools: DistributionNotFound')
79
80
81def print_py_pkg_ver(pkgname, modulename=None):
82    if modulename is None:
83        modulename = pkgname
84    print()
85    try:
86        print(pkgname + ': ' + version(pkgname))
87    except PackageNotFoundError:
88        print(pkgname + ': DistributionNotFound')
89    try:
90        __import__(modulename)
91    except ImportError:
92        pass
93    else:
94        modobj = sys.modules.get(modulename)
95        print(pkgname + ' module: ' + str(modobj))
96        try:
97            print(pkgname + ' __version__: ' + str(modobj.__version__))
98        except AttributeError:
99            pass
100
101
102print_platform()
103print()
104print_python_ver()
105print_stdout(['virtualenv', '--version'])
106print_stdout(['tox', '--version'])
107print()
108print_stdout(['locale'])
109print_python_encoding_settings()
110print()
111print_stdout(['buildbot', '--version'])
112print_stdout(['buildslave', '--version'])
113if 'windows' in platform.system().lower():
114    print_stdout(['cl'])
115print_stdout(['gcc', '--version'], numlines=1)
116print_stdout(['g++', '--version'], numlines=1)
117print_stdout(['cryptest', 'V'])
118print_stdout(['git', '--version'])
119print_stdout(['openssl', 'version'])
120print_stdout(['flappclient', '--version'])
121print_stdout(['valgrind', '--version'])
122
123print_as_ver()
124
125print_setuptools_ver()
126
127print_py_pkg_ver('cffi')
128print_py_pkg_ver('coverage')
129print_py_pkg_ver('cryptography')
130print_py_pkg_ver('foolscap')
131print_py_pkg_ver('mock')
132print_py_pkg_ver('pyasn1')
133print_py_pkg_ver('pycparser')
134print_py_pkg_ver('cryptography')
135print_py_pkg_ver('pyflakes')
136print_py_pkg_ver('pyOpenSSL', 'OpenSSL')
137print_py_pkg_ver('six')
138print_py_pkg_ver('trialcoverage')
139print_py_pkg_ver('Twisted', 'twisted')
140print_py_pkg_ver('TwistedCore', 'twisted.python')
141print_py_pkg_ver('TwistedWeb', 'twisted.web')
142print_py_pkg_ver('TwistedConch', 'twisted.conch')
143print_py_pkg_ver('zfec')
144print_py_pkg_ver('zope.interface')
Note: See TracBrowser for help on using the repository browser.