Skip to content

Commit

Permalink
sage --package dependencies: Support --format=rst, improve --format=p…
Browse files Browse the repository at this point in the history
…lain; use in sage-spkg-info
  • Loading branch information
Matthias Koeppe committed Feb 20, 2024
1 parent 1ded6d2 commit 5053453
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 43 deletions.
21 changes: 3 additions & 18 deletions build/bin/sage-spkg-info
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ if [ -n "$OUTPUT_RST" ]; then
issue () { echo ":issue:\`$1\`"; }
code () { echo "\`\`$*\`\`"; }
tab () { echo ".. tab:: $1"; }
FORMAT=rst
else
ref () { echo "$1"; }
spkg () { echo "$1"; }
issue () { echo "https://github.com/sagemath/sage/issues/$1"; }
code () { echo "$1"; }
tab () { echo "$1:"; }
FORMAT=plain
fi
if ! props=$(${SAGE_PACKAGE-sage-package} properties --format=shell $PKG_BASE 2> /dev/null); then
echo >&2 "sage-spkg-info: unknown package $PKG_BASE"
Expand Down Expand Up @@ -49,24 +51,7 @@ echo
echo "Dependencies"
echo "------------"
echo
eval $(${SAGE_PACKAGE-sage-package} properties --format=shell :all:)
for dep in $(${SAGE_PACKAGE-sage-package} dependencies $PKG_BASE); do
case "$dep" in
# Suppress dependencies on source files, e.g. of the form $(SAGE_ROOT)/..., $(SAGE_SRC)/...
*/*) ;;
# Suppress FORCE
FORCE) ;;
# Dependencies like $(BLAS)
\$\(*) echo "- $dep";;
# Looks like a package
*) if eval test -r "\$path_$dep/SPKG.rst"; then
# This RST label is set in src/doc/bootstrap
echo "- $(spkg $dep)"
else
echo "- $dep"
fi;;
esac
done
${SAGE_PACKAGE-sage-package} dependencies --format=$FORMAT $PKG_BASE
echo
echo "Version Information"
echo "-------------------"
Expand Down
78 changes: 58 additions & 20 deletions build/sage_bootstrap/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ def properties(self, *package_classes, **kwds):
pc = PackageClass(*package_classes)
for package_name in pc.names:
package = Package(package_name)
if format == 'plain':
print("{0}:".format(package_name))
if len(pc.names) > 1:
if format == 'plain':
print("{0}:".format(package_name))
for p in props:
value = getattr(package, p)
if value is None:
Expand All @@ -112,36 +113,73 @@ def dependencies(self, *package_classes, **kwds):
"""
Find the dependencies given package names
$ sage --package dependencies maxima --runtime --order-only
ecl
info
$ sage --package dependencies maxima --runtime --order-only --format=shell
order_only_deps_maxima='info'
runtime_deps_maxima='ecl'
"""
types = kwds.pop('types', None)
format = kwds.pop('format', 'plain')
log.debug('Looking up dependencies')
pc = PackageClass(*package_classes)
if format == 'plain':
if format in ['plain', 'rst']:
if types is None:
types = ['order_only', 'runtime']
deps = []
for package_name in pc.names:
package = Package(package_name)
for t in types:
deps.extend(getattr(package, 'dependencies_' + t))
for dep in sorted(set(deps)):
print(dep)
typesets = [['order_only', 'runtime']]
else:
typesets = [[t] for t in types]
elif format == 'shell':
if types is None:
types = ['order_only', 'optional', 'runtime', 'check']
for package_name in pc.names:
package = Package(package_name)
for t in types:
typesets = [[t] for t in types]
else:
raise ValueError('format must be one of "plain", "rst", and "shell"')

if format == 'plain':
indent1 = " "
indent2 = " "
elif format == 'rst':
indent1 = ""
indent2 = " "

for package_name in pc.names:
package = Package(package_name)
if len(pc.names) > 1:
if format == 'plain':
print("{0}:".format(package_name))
elif format == 'rst':
print("\n{0}\n{1}\n".format(package_name, "~" * len(package_name)))

for typeset in typesets:
if len(typesets) > 1:
if format == 'plain':
print(indent1 + "{0}: ".format('/'.join(typeset)))
elif format == 'rst':
print("\n" + indent1 + ".. tab:: {0}\n".format('/'.join(typeset)))

deps = []
for t in typeset:
deps.extend(getattr(package, 'dependencies_' + t))
deps = sorted(set(deps))

if format in ['plain', 'rst']:
for dep in deps:
if '/' in dep:
# Suppress dependencies on source files, e.g. of the form $(SAGE_ROOT)/..., $(SAGE_SRC)/...
continue
if dep == 'FORCE':
# Suppress FORCE
continue
if dep.startswith('$('):
# Dependencies like $(BLAS)
print(indent2 + "- {0}".format(dep))
elif format == 'rst' and Package(dep).has_file('SPKG.rst'):
# This RST label is set in src/doc/bootstrap
print(indent2 + "- :ref:`spkg_{0}`".format(dep))
else:
print(indent2 + "- {0}".format(dep))
elif format == 'shell':
# We single-quote the values because dependencies
# may contain Makefile variable substitutions
deps = getattr(package, 'dependencies_' + t)
print("{0}_deps_{1}='{2}'".format(t, package_name, ' '.join(deps)))
else:
raise ValueError('format must be one of "plain" and "shell"')

def name(self, tarball_filename):
"""
Expand Down
15 changes: 10 additions & 5 deletions build/sage_bootstrap/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,19 @@
epilog_dependencies = \
"""
Print the list of packages that are dependencies of given package.
By default, list the build, order-only, and runtime dependencies.
By default, list a summary of the build, order-only, and runtime
dependencies.
EXAMPLE:
$ sage --package dependencies maxima openblas
maxima:
- ecl
- info
openblas:
- gfortran
$ sage --package dependencies maxima --runtime
ecl
$ sage --package dependencies maxima --order-only
info
- ecl
"""


Expand Down Expand Up @@ -323,7 +328,7 @@ def make_parser():
help='list the check dependencies')
parser_dependencies.add_argument(
'--format', type=str, default='plain',
help='output format (one of plain and shell; default: plain)')
help='output format (one of plain, rst, and shell; default: plain)')

parser_name = subparsers.add_parser(
'name', epilog=epilog_name,
Expand Down

0 comments on commit 5053453

Please sign in to comment.