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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
|
##############################################################################
# Copyright (c) 2013-2017, Lawrence Livermore National Security, LLC.
# Produced at the Lawrence Livermore National Laboratory.
#
# This file is part of Spack.
# Created by Todd Gamblin, tgamblin@llnl.gov, All rights reserved.
# LLNL-CODE-647188
#
# For details, see https://github.com/llnl/spack
# Please also see the NOTICE and LICENSE files for our notice and the LGPL.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License (as
# published by the Free Software Foundation) version 2.1, February 1999.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and
# conditions of the GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##############################################################################
from __future__ import print_function
import textwrap
from six.moves import zip_longest
from llnl.util.tty.colify import *
import llnl.util.tty.color as color
import spack
import spack.fetch_strategy as fs
import spack.spec
description = 'get detailed information on a particular package'
section = 'basic'
level = 'short'
header_color = '@*b'
plain_format = '@.'
def padder(str_list, extra=0):
"""Return a function to pad elements of a list."""
length = max(len(str(s)) for s in str_list) + extra
def pad(string):
string = str(string)
padding = max(0, length - len(string))
return string + (padding * ' ')
return pad
def setup_parser(subparser):
subparser.add_argument(
'name', metavar='PACKAGE', help='name of package to get info for')
def section_title(s):
return header_color + s + plain_format
def version(s):
return spack.spec.version_color + s + plain_format
def variant(s):
return spack.spec.enabled_variant_color + s + plain_format
class VariantFormatter(object):
def __init__(self, variants, max_widths=(30, 20, 30)):
self.variants = variants
self.headers = ('Name [Default]', 'Allowed values', 'Description')
# Set max headers lengths
self.max_column_widths = max_widths
# Formats
fmt_name = '{0} [{1}]'
# Initialize column widths with the length of the
# corresponding headers, as they cannot be shorter
# than that
self.column_widths = [len(x) for x in self.headers]
# Update according to line lengths
for k, v in variants.items():
candidate_max_widths = (
len(fmt_name.format(k, self.default(v))), # Name [Default]
len(v.allowed_values), # Allowed values
len(v.description) # Description
)
self.column_widths = (
max(self.column_widths[0], candidate_max_widths[0]),
max(self.column_widths[1], candidate_max_widths[1]),
max(self.column_widths[2], candidate_max_widths[2])
)
# Reduce to at most the maximum allowed
self.column_widths = (
min(self.column_widths[0], self.max_column_widths[0]),
min(self.column_widths[1], self.max_column_widths[1]),
min(self.column_widths[2], self.max_column_widths[2])
)
# Compute the format
self.fmt = "%%-%ss%%-%ss%%s" % (
self.column_widths[0] + 4,
self.column_widths[1] + 4
)
def default(self, v):
s = 'on' if v.default is True else 'off'
if not isinstance(v.default, bool):
s = v.default
return s
@property
def lines(self):
if not self.variants:
yield ' None'
else:
yield ' ' + self.fmt % self.headers
yield '\n'
for k, v in sorted(self.variants.items()):
name = textwrap.wrap(
'{0} [{1}]'.format(k, self.default(v)),
width=self.column_widths[0]
)
allowed = textwrap.wrap(
v.allowed_values,
width=self.column_widths[1]
)
description = textwrap.wrap(
v.description,
width=self.column_widths[2]
)
for t in zip_longest(
name, allowed, description, fillvalue=''
):
yield " " + self.fmt % t
def print_text_info(pkg):
"""Print out a plain text description of a package."""
header = section_title(
'{0}: '
).format(pkg.build_system_class) + pkg.name
color.cprint(header)
color.cprint('')
color.cprint(section_title('Description:'))
if pkg.__doc__:
color.cprint(pkg.format_doc(indent=4))
else:
color.cprint(" None")
color.cprint(section_title('Homepage: ') + pkg.homepage)
if len(pkg.maintainers) > 0:
mnt = " ".join(['@@' + m for m in pkg.maintainers])
color.cprint('')
color.cprint(section_title('Maintainers: ') + mnt)
color.cprint('')
color.cprint(section_title("Tags: "))
if hasattr(pkg, 'tags'):
tags = sorted(pkg.tags)
colify(tags, indent=4)
else:
color.cprint(" None")
color.cprint('')
color.cprint(section_title('Preferred version: '))
if not pkg.versions:
color.cprint(version(' None'))
color.cprint('')
color.cprint(section_title('Safe versions: '))
color.cprint(version(' None'))
else:
pad = padder(pkg.versions, 4)
# Here we sort first on the fact that a version is marked
# as preferred in the package, then on the fact that the
# version is not develop, then lexicographically
l = [
(value.get('preferred', False), not key.isdevelop(), key)
for key, value in pkg.versions.items()
]
l = sorted(l)
_, _, preferred = l.pop()
f = fs.for_package_version(pkg, preferred)
line = version(' {0}'.format(pad(preferred))) + str(f)
color.cprint(line)
color.cprint('')
color.cprint(section_title('Safe versions: '))
for v in reversed(sorted(pkg.versions)):
f = fs.for_package_version(pkg, v)
line = version(' {0}'.format(pad(v))) + str(f)
color.cprint(line)
color.cprint('')
color.cprint(section_title('Variants:'))
formatter = VariantFormatter(pkg.variants)
for line in formatter.lines:
color.cprint(line)
color.cprint('')
color.cprint(section_title('Installation Phases:'))
phase_str = ''
for phase in pkg.phases:
phase_str += " {0}".format(phase)
color.cprint(phase_str)
for deptype in ('build', 'link', 'run'):
color.cprint('')
color.cprint(section_title('%s Dependencies:' % deptype.capitalize()))
deps = sorted(pkg.dependencies_of_type(deptype))
if deps:
colify(deps, indent=4)
else:
color.cprint(' None')
color.cprint('')
color.cprint(section_title('Virtual Packages: '))
if pkg.provided:
inverse_map = {}
for spec, whens in pkg.provided.items():
for when in whens:
if when not in inverse_map:
inverse_map[when] = set()
inverse_map[when].add(spec)
for when, specs in reversed(sorted(inverse_map.items())):
line = " %s provides %s" % (
when.colorized(), ', '.join(s.colorized() for s in specs)
)
print(line)
else:
color.cprint(" None")
color.cprint('')
def info(parser, args):
pkg = spack.repo.get(args.name)
print_text_info(pkg)
|