Skip to content

Commit a2ab472

Browse files
author
Matthias Koeppe
committed
sage --package dependencies: New
1 parent 30b3d78 commit a2ab472

File tree

3 files changed

+107
-0
lines changed

3 files changed

+107
-0
lines changed

build/sage_bootstrap/app.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,39 @@ def properties(self, *package_classes, **kwds):
108108
else:
109109
print("{0}_{1}='{2}'".format(p, package_name, value))
110110

111+
def dependencies(self, *package_classes, types=None, format='plain'):
112+
"""
113+
Find the dependencies given package names
114+
115+
$ sage --package dependencies maxima --runtime --order-only
116+
ecl
117+
info
118+
"""
119+
log.debug('Looking up dependencies')
120+
pc = PackageClass(*package_classes)
121+
if format == 'plain':
122+
if types is None:
123+
types = ['order_only', 'runtime']
124+
deps = []
125+
for package_name in pc.names:
126+
package = Package(package_name)
127+
for t in types:
128+
deps.extend(getattr(package, 'dependencies_' + t))
129+
for dep in sorted(set(deps)):
130+
print(dep)
131+
elif format == 'shell':
132+
if types is None:
133+
types = ['order_only', 'optional', 'runtime', 'check']
134+
for package_name in pc.names:
135+
package = Package(package_name)
136+
for t in types:
137+
# We single-quote the values because dependencies
138+
# may contain Makefile variable substitutions
139+
deps = getattr(package, 'dependencies_' + t)
140+
print("{0}_deps_{1}='{2}'".format(t, package_name, ' '.join(deps)))
141+
else:
142+
raise ValueError('format must be one of "plain" and "shell"')
143+
111144
def name(self, tarball_filename):
112145
"""
113146
Find the package name given a tarball filename

build/sage_bootstrap/cmdline.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,20 @@
9999
"""
100100

101101

102+
epilog_dependencies = \
103+
"""
104+
Print the list of packages that are dependencies of given package.
105+
By default, list the build, order-only, and runtime dependencies.
106+
107+
EXAMPLE:
108+
109+
$ sage --package dependencies maxima --runtime
110+
ecl
111+
$ sage --package dependencies maxima --order-only
112+
info
113+
"""
114+
115+
102116
epilog_name = \
103117
"""
104118
Find the package name given a tarball filename
@@ -286,6 +300,31 @@ def make_parser():
286300
'--format', type=str, default='plain',
287301
help='output format (one of plain and shell; default: plain)')
288302

303+
parser_dependencies = subparsers.add_parser(
304+
'dependencies', epilog=epilog_dependencies,
305+
formatter_class=argparse.RawDescriptionHelpFormatter,
306+
help='Print the list of packages that are dependencies of given packages')
307+
parser_dependencies.add_argument(
308+
'package_class', metavar='[package_name|:package_type:]',
309+
type=str, nargs='+',
310+
help=('package name or designator for all packages of a given type '
311+
'(one of :all:, :standard:, :optional:, and :experimental:)'))
312+
parser_dependencies.add_argument(
313+
'--order-only', action='store_true',
314+
help='list the order-only build dependencies')
315+
parser_dependencies.add_argument(
316+
'--optional', action='store_true',
317+
help='list the optional build dependencies')
318+
parser_dependencies.add_argument(
319+
'--runtime', action='store_true',
320+
help='list the runtime dependencies')
321+
parser_dependencies.add_argument(
322+
'--check', action='store_true',
323+
help='list the check dependencies')
324+
parser_dependencies.add_argument(
325+
'--format', type=str, default='plain',
326+
help='output format (one of plain and shell; default: plain)')
327+
289328
parser_name = subparsers.add_parser(
290329
'name', epilog=epilog_name,
291330
formatter_class=argparse.RawDescriptionHelpFormatter,
@@ -435,6 +474,19 @@ def run():
435474
exclude_dependencies=args.exclude_dependencies)
436475
elif args.subcommand == 'properties':
437476
app.properties(*args.package_class, format=args.format)
477+
elif args.subcommand == 'dependencies':
478+
types = []
479+
if args.order_only:
480+
types.append('order_only')
481+
if args.optional:
482+
types.append('optional')
483+
if args.runtime:
484+
types.append('runtime')
485+
if args.check:
486+
types.append('check')
487+
if not types:
488+
types = None
489+
app.dependencies(*args.package_class, types=types, format=args.format)
438490
elif args.subcommand == 'name':
439491
app.name(args.tarball_filename)
440492
elif args.subcommand == 'tarball':

build/sage_bootstrap/package.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,23 @@ def dependencies_order_only(self):
380380
"""
381381
return self.__dependencies.partition('|')[2].strip().split() + self.__dependencies_order_only.strip().split()
382382

383+
@property
384+
def dependencies_optional(self):
385+
"""
386+
Return a list of strings, the package names of the optional build dependencies
387+
"""
388+
return self.__dependencies_optional.strip().split()
389+
390+
@property
391+
def dependencies_runtime(self):
392+
"""
393+
Return a list of strings, the package names of the runtime dependencies
394+
"""
395+
# after a '|', we have order-only build dependencies
396+
return self.__dependencies.partition('|')[0].strip().split()
397+
398+
dependencies = dependencies_runtime
399+
383400
@property
384401
def dependencies_check(self):
385402
"""
@@ -511,6 +528,11 @@ def _init_dependencies(self):
511528
self.__dependencies_check = f.readline().strip()
512529
except IOError:
513530
self.__dependencies_check = ''
531+
try:
532+
with open(os.path.join(self.path, 'dependencies_optional')) as f:
533+
self.__dependencies_optional = f.readline()
534+
except IOError:
535+
self.__dependencies_optional = ''
514536
try:
515537
with open(os.path.join(self.path, 'dependencies_order_only')) as f:
516538
self.__dependencies_order_only = f.readline()

0 commit comments

Comments
 (0)