|
| 1 | +""" |
| 2 | +Utility methods to print system info for debugging |
| 3 | +
|
| 4 | +adapted from :func:`pandas.show_versions` |
| 5 | +""" |
| 6 | +# License: BSD 3 clause |
| 7 | + |
| 8 | +import os |
| 9 | +import platform |
| 10 | +import sys |
| 11 | +import struct |
| 12 | +import subprocess |
| 13 | +import codecs |
| 14 | +import locale |
| 15 | +import importlib |
| 16 | + |
| 17 | +from .._build_utils import get_blas_info |
| 18 | + |
| 19 | + |
| 20 | +def get_sys_info(): |
| 21 | + "Returns system information as a dict" |
| 22 | + |
| 23 | + blob = [] |
| 24 | + |
| 25 | + # get full commit hash |
| 26 | + commit = None |
| 27 | + if os.path.isdir(".git") and os.path.isdir("sklearn"): |
| 28 | + try: |
| 29 | + pipe = subprocess.Popen('git log --format="%H" -n 1'.split(" "), |
| 30 | + stdout=subprocess.PIPE, |
| 31 | + stderr=subprocess.PIPE) |
| 32 | + so, serr = pipe.communicate() |
| 33 | + except: |
| 34 | + pass |
| 35 | + else: |
| 36 | + if pipe.returncode == 0: |
| 37 | + commit = so |
| 38 | + try: |
| 39 | + commit = so.decode('utf-8') |
| 40 | + except ValueError: |
| 41 | + pass |
| 42 | + commit = commit.strip().strip('"') |
| 43 | + |
| 44 | + blob.append(('commit', commit)) |
| 45 | + |
| 46 | + try: |
| 47 | + (sysname, nodename, release, |
| 48 | + version, machine, processor) = platform.uname() |
| 49 | + blob.extend([ |
| 50 | + ("python", '.'.join(map(str, sys.version_info))), |
| 51 | + ("python-bits", struct.calcsize("P") * 8), |
| 52 | + ("OS", "{sysname}".format(sysname=sysname)), |
| 53 | + ("OS-release", "{release}".format(release=release)), |
| 54 | + ("machine", "{machine}".format(machine=machine)), |
| 55 | + ("processor", "{processor}".format(processor=processor)), |
| 56 | + ("byteorder", "{byteorder}".format(byteorder=sys.byteorder)), |
| 57 | + ("LC_ALL", "{lc}".format(lc=os.environ.get('LC_ALL', "None"))), |
| 58 | + ("LANG", "{lang}".format(lang=os.environ.get('LANG', "None"))), |
| 59 | + ("LOCALE", '.'.join(map(str, locale.getlocale()))), |
| 60 | + ]) |
| 61 | + except: |
| 62 | + pass |
| 63 | + |
| 64 | + return blob |
| 65 | + |
| 66 | + |
| 67 | +def show_versions(as_json=False, with_blas=False): |
| 68 | + sys_info = get_sys_info() |
| 69 | + |
| 70 | + cblas_libs, blas_info = get_blas_info() |
| 71 | + |
| 72 | + deps = [ |
| 73 | + # (MODULE_NAME, f(mod) -> mod version) |
| 74 | + ("pip", lambda mod: mod.__version__), |
| 75 | + ("setuptools", lambda mod: mod.__version__), |
| 76 | + ("numpy", lambda mod: mod.version.version), |
| 77 | + ("scipy", lambda mod: mod.version.version), |
| 78 | + ("Cython", lambda mod: mod.__version__), |
| 79 | + ("pandas", lambda mod: mod.__version__), |
| 80 | + ("matplotlib", lambda mod: mod.__version__), |
| 81 | + # ("sphinx", lambda mod: mod.__version__), |
| 82 | + # ("pytest", lambda mod: mod.__version__), |
| 83 | + # ("patsy", lambda mod: mod.__version__), |
| 84 | + # ("pyarrow", lambda mod: mod.__version__), |
| 85 | + # ("xarray", lambda mod: mod.__version__), |
| 86 | + # ("IPython", lambda mod: mod.__version__), |
| 87 | + # ("dateutil", lambda mod: mod.__version__), |
| 88 | + # ("pytz", lambda mod: mod.VERSION), |
| 89 | + # ("blosc", lambda mod: mod.__version__), |
| 90 | + # ("bottleneck", lambda mod: mod.__version__), |
| 91 | + # ("tables", lambda mod: mod.__version__), |
| 92 | + # ("numexpr", lambda mod: mod.__version__), |
| 93 | + # ("feather", lambda mod: mod.__version__), |
| 94 | + # ("openpyxl", lambda mod: mod.__version__), |
| 95 | + # ("xlrd", lambda mod: mod.__VERSION__), |
| 96 | + # ("xlwt", lambda mod: mod.__VERSION__), |
| 97 | + # ("xlsxwriter", lambda mod: mod.__version__), |
| 98 | + # ("lxml", lambda mod: mod.etree.__version__), |
| 99 | + # ("bs4", lambda mod: mod.__version__), |
| 100 | + # ("html5lib", lambda mod: mod.__version__), |
| 101 | + # ("sqlalchemy", lambda mod: mod.__version__), |
| 102 | + # ("pymysql", lambda mod: mod.__version__), |
| 103 | + # ("psycopg2", lambda mod: mod.__version__), |
| 104 | + # ("jinja2", lambda mod: mod.__version__), |
| 105 | + # ("s3fs", lambda mod: mod.__version__), |
| 106 | + # ("fastparquet", lambda mod: mod.__version__), |
| 107 | + # ("pandas_gbq", lambda mod: mod.__version__), |
| 108 | + # ("pandas_datareader", lambda mod: mod.__version__), |
| 109 | + # ("gcsfs", lambda mod: mod.__version__), |
| 110 | + ] |
| 111 | + |
| 112 | + deps_blob = list() |
| 113 | + for (modname, ver_f) in deps: |
| 114 | + try: |
| 115 | + if modname in sys.modules: |
| 116 | + mod = sys.modules[modname] |
| 117 | + else: |
| 118 | + mod = importlib.import_module(modname) |
| 119 | + ver = ver_f(mod) |
| 120 | + deps_blob.append((modname, ver)) |
| 121 | + except ImportError: |
| 122 | + deps_blob.append((modname, None)) |
| 123 | + |
| 124 | + if (as_json): |
| 125 | + try: |
| 126 | + import json |
| 127 | + except ImportError: |
| 128 | + import simplejson as json |
| 129 | + |
| 130 | + j = dict(system=dict(sys_info), |
| 131 | + dependencies=dict(deps_blob)) |
| 132 | + |
| 133 | + if with_blas: |
| 134 | + blas_info['cblas_libs'] = cblas_libs |
| 135 | + j['blas'] = blas_info |
| 136 | + |
| 137 | + if as_json is True: |
| 138 | + print(j) |
| 139 | + else: |
| 140 | + with codecs.open(as_json, "wb", encoding='utf8') as f: |
| 141 | + json.dump(j, f, indent=2) |
| 142 | + |
| 143 | + else: |
| 144 | + |
| 145 | + print("") |
| 146 | + print('System info') |
| 147 | + print('-----------') |
| 148 | + for k, stat in sys_info: |
| 149 | + print("{k}: {stat}".format(k=k, stat=stat)) |
| 150 | + |
| 151 | + if with_blas: |
| 152 | + print("") |
| 153 | + print('BLAS info') |
| 154 | + print('---------') |
| 155 | + for k, stat in blas_info.items(): |
| 156 | + print("{k}: {stat}".format(k=k, stat=stat)) |
| 157 | + print('CBLAS libs: {libs}'.format(libs=cblas_libs)) |
| 158 | + |
| 159 | + print("") |
| 160 | + print('Python libs info') |
| 161 | + print('----------------') |
| 162 | + for k, stat in deps_blob: |
| 163 | + print("{k}: {stat}".format(k=k, stat=stat)) |
0 commit comments