Debian Codegraph @

biom/cli/installation_informer.py

raw
1 # -----------------------------------------------------------------------------
2 # Copyright (c) 2011-2017, The BIOM Format Development Team.
3 #
4 # Distributed under the terms of the Modified BSD License.
5 #
6 # The full license is in the file COPYING.txt, distributed with this software.
7 # -----------------------------------------------------------------------------
8
9
10 import sys
11
12 import click
13
14 from biom.cli import cli
15
16
17 @cli.command(name='show-install-info')
18 def show_install_info():
19 """Provide information about the biom-format installation.
20
21 Provide information about the biom-format installation, including settings
22 pulled from the configuration file. For more details, see
23 http://biom-format.org
24
25 Example usage:
26
27 Display biom-format installation information:
28
29 $ biom show-install-info
30
31 """
32 click.echo(_show_install_info())
33
34
35 def _show_install_info():
36 lines = []
37 lines.extend(_get_formatted_system_info())
38 lines.extend(_get_formatted_dependency_version_info())
39 lines.extend(_get_formatted_package_info())
40 lines.append('')
41 return '\n'.join(lines)
42
43
44 def _get_formatted_system_info():
45 return _format_info(_get_system_info(), 'System information')
46
47
48 def _get_formatted_dependency_version_info():
49 return _format_info(_get_dependency_version_info(), 'Dependency versions')
50
51
52 def _get_formatted_package_info():
53 return _format_info(_get_package_info(), 'biom-format package information')
54
55
56 def _get_system_info():
57 return (("Platform", sys.platform),
58 ("Python version", sys.version.replace('\n', ' ')),
59 ("Python executable", sys.executable))
60
61
62 def _get_dependency_version_info():
63 not_installed_msg = "Not installed"
64
65 try:
66 from click import __version__ as click_lib_version
67 except ImportError:
68 click_lib_version = not_installed_msg
69
70 try:
71 from numpy import __version__ as numpy_lib_version
72 except ImportError:
73 numpy_lib_version = ("ERROR: Not installed - this is required! "
74 "(This will also cause the BIOM library to "
75 "not be importable.)")
76
77 try:
78 from scipy import __version__ as scipy_lib_version
79 except ImportError:
80 scipy_lib_version = not_installed_msg
81
82 try:
83 from h5py import __version__ as h5py_lib_version
84 except ImportError:
85 h5py_lib_version = ("WARNING: Not installed - this is an optional "
86 "dependency. It is strongly recommended for "
87 "large datasets.")
88
89 return (("click version", click_lib_version),
90 ("NumPy version", numpy_lib_version),
91 ("SciPy version", scipy_lib_version),
92 ("h5py version", h5py_lib_version))
93
94
95 def _get_package_info():
96 import_error_msg = ("ERROR: Can't find the BIOM library code (or "
97 "numpy) - is it installed and in your "
98 "$PYTHONPATH?")
99 try:
100 from biom import __version__ as biom_lib_version
101 except ImportError:
102 biom_lib_version = import_error_msg
103
104 return (("biom-format version", biom_lib_version),)
105
106
107 def _format_info(info, title):
108 max_len = _get_max_length(info)
109
110 lines = ['']
111 lines.append(title)
112 lines.append('=' * len(title))
113 for e in info:
114 lines.append("%*s:\t%s" % (max_len, e[0], e[1]))
115
116 return lines
117
118
119 def _get_max_length(info):
120 return max(len(e[0]) for e in info)