Skip to content

Commit

Permalink
sage --package properties: New
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Koeppe committed Dec 16, 2023
1 parent e0f8a57 commit 8df0d9f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
21 changes: 21 additions & 0 deletions build/sage_bootstrap/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,27 @@ def dependencies(self, *package_classes, types=None, format='plain'):
else:
raise ValueError('format must be one of "plain" and "shell"')

def properties(self, *package_classes, props=['version', 'type']):
"""
Show the properties of given packages
$ sage --package properties maxima
version_maxima='5.46.0'
type_maxima='standard'
"""
log.debug('Looking up properties')
pc = PackageClass(*package_classes)
for package_name in pc.names:
package = Package(package_name)
for p in props:
value = getattr(package, p)
if value is None:
if p == 'version':
value = 'none'
else:
value = ''
print("{0}_{1}='{2}'".format(p, package_name, value))

def name(self, tarball_filename):
"""
Find the package name given a tarball filename
Expand Down
24 changes: 24 additions & 0 deletions build/sage_bootstrap/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,18 @@
"""


epilog_properties = \
"""
Print properties of given package.
EXAMPLE:
$ sage --package properties maxima
version_maxima='5.46.0'
type_maxima='standard'
"""


epilog_name = \
"""
Find the package name given a tarball filename
Expand Down Expand Up @@ -278,6 +290,16 @@ def make_parser():
'--format', type=str, default='plain',
help='output format (one of plain and shell; default: plain)')

parser_properties = subparsers.add_parser(
'properties', epilog=epilog_properties,
formatter_class=argparse.RawDescriptionHelpFormatter,
help='Print properties of given packages')
parser_properties.add_argument(
'package_class', metavar='[package_name|:package_type:]',
type=str, nargs='+',
help=('package name or designator for all packages of a given type '
'(one of :all:, :standard:, :optional:, and :experimental:)'))

parser_name = subparsers.add_parser(
'name', epilog=epilog_name,
formatter_class=argparse.RawDescriptionHelpFormatter,
Expand Down Expand Up @@ -427,6 +449,8 @@ def run():
if not types:
types = None
app.dependencies(*args.package_class, types=types, format=args.format)
elif args.subcommand == 'properties':
app.properties(*args.package_class)
elif args.subcommand == 'name':
app.name(args.tarball_filename)
elif args.subcommand == 'tarball':
Expand Down

0 comments on commit 8df0d9f

Please sign in to comment.