From f5f4b18798b399459b27e197c1c8c1fe1d74f8ef Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Fri, 15 Dec 2023 23:10:21 -0800 Subject: [PATCH 1/6] sage --package properties: New --- build/sage_bootstrap/app.py | 21 +++++++++++++++++++++ build/sage_bootstrap/cmdline.py | 24 ++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/build/sage_bootstrap/app.py b/build/sage_bootstrap/app.py index 19ca74b6a68..47d9776a76a 100644 --- a/build/sage_bootstrap/app.py +++ b/build/sage_bootstrap/app.py @@ -77,6 +77,27 @@ def list_cls(self, *package_classes, **filters): for pkg_name in pc.names: print(pkg_name) + 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 diff --git a/build/sage_bootstrap/cmdline.py b/build/sage_bootstrap/cmdline.py index e95e56cafb8..e14759beb5e 100644 --- a/build/sage_bootstrap/cmdline.py +++ b/build/sage_bootstrap/cmdline.py @@ -83,6 +83,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 @@ -257,6 +269,16 @@ def make_parser(): '--exclude-dependencies', action='store_true', help='exclude (ordinary) dependencies of the packages recursively') + 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, @@ -404,6 +426,8 @@ def run(): exclude=args.exclude, include_dependencies=args.include_dependencies, exclude_dependencies=args.exclude_dependencies) + elif args.subcommand == 'properties': + app.properties(*args.package_class) elif args.subcommand == 'name': app.name(args.tarball_filename) elif args.subcommand == 'tarball': From 02dfaa9e18b3219bcdc69b9edc26fb69598e2668 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 16 Dec 2023 00:09:00 -0800 Subject: [PATCH 2/6] sage --package properties: Add path, source, trees --- build/sage_bootstrap/app.py | 2 +- build/sage_bootstrap/package.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/build/sage_bootstrap/app.py b/build/sage_bootstrap/app.py index 47d9776a76a..17349812957 100644 --- a/build/sage_bootstrap/app.py +++ b/build/sage_bootstrap/app.py @@ -77,7 +77,7 @@ def list_cls(self, *package_classes, **filters): for pkg_name in pc.names: print(pkg_name) - def properties(self, *package_classes, props=['version', 'type']): + def properties(self, *package_classes, props=['path', 'version', 'type', 'source', 'trees']): """ Show the properties of given packages diff --git a/build/sage_bootstrap/package.py b/build/sage_bootstrap/package.py index 9363138a457..ef403a278f3 100644 --- a/build/sage_bootstrap/package.py +++ b/build/sage_bootstrap/package.py @@ -48,6 +48,7 @@ def __init__(self, package_name): self._init_type() self._init_install_requires() self._init_dependencies() + self._init_trees() def __repr__(self): return 'Package {0}'.format(self.name) @@ -300,6 +301,31 @@ def type(self): """ return self.__type + @property + def source(self): + """ + Return the package source type + """ + if self.has_file('requirements.txt'): + return 'pip' + if self.tarball_filename: + if self.tarball_filename.endswith('.whl'): + return 'wheel' + return 'normal' + if self.has_file('spkg-install') or self.has_file('spkg-install.in'): + return 'script' + return 'none' + + @property + def trees(self): + if self.__trees is not None: + return self.__trees + if self.__install_requires is not None: + return 'SAGE_VENV' + if self.has_file('requirements.txt'): + return 'SAGE_VENV' + return 'SAGE_LOCAL' + @property def distribution_name(self): """ @@ -466,3 +492,10 @@ def _init_dependencies(self): self.__dependencies_order_only = f.readline() except IOError: self.__dependencies_order_only = '' + + def _init_trees(self): + try: + with open(os.path.join(self.path, 'trees.txt')) as f: + self.__trees = f.readline().partition('#')[0].strip() + except IOError: + self.__trees = None From 55241d7b54bc7992572465066ca17c3a5733b152 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 16 Dec 2023 16:20:49 -0800 Subject: [PATCH 3/6] Fix handling of SPKGs with patchlevel --- build/sage_bootstrap/app.py | 9 ++++++--- build/sage_bootstrap/package.py | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/build/sage_bootstrap/app.py b/build/sage_bootstrap/app.py index 17349812957..c4fda8301c7 100644 --- a/build/sage_bootstrap/app.py +++ b/build/sage_bootstrap/app.py @@ -77,13 +77,16 @@ def list_cls(self, *package_classes, **filters): for pkg_name in pc.names: print(pkg_name) - def properties(self, *package_classes, props=['path', 'version', 'type', 'source', 'trees']): + def properties(self, *package_classes, props=['path', 'version_with_patchlevel', 'type', 'source', 'trees']): """ Show the properties of given packages $ sage --package properties maxima - version_maxima='5.46.0' + path_maxima='........./build/pkgs/maxima' + version_with_patchlevel_maxima='5.46.0' type_maxima='standard' + source_maxima='normal' + trees_maxima='SAGE_LOCAL' """ log.debug('Looking up properties') pc = PackageClass(*package_classes) @@ -92,7 +95,7 @@ def properties(self, *package_classes, props=['path', 'version', 'type', 'source for p in props: value = getattr(package, p) if value is None: - if p == 'version': + if p.startswith('version'): value = 'none' else: value = '' diff --git a/build/sage_bootstrap/package.py b/build/sage_bootstrap/package.py index ef403a278f3..0c41c86489f 100644 --- a/build/sage_bootstrap/package.py +++ b/build/sage_bootstrap/package.py @@ -294,6 +294,23 @@ def patchlevel(self): """ return self.__patchlevel + @property + def version_with_patchlevel(self): + """ + Return the version, including the Sage-specific patchlevel + + OUTPUT: + + String. + """ + v = self.version + if v is None: + return v + p = self.patchlevel + if p < 0: + return v + return "{0}.p{1}".format(v, p) + @property def type(self): """ From eadb3d58f571b5f9b12466b1d9d67dfb3fb3af17 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 27 Dec 2023 11:46:07 -0800 Subject: [PATCH 4/6] build/sage_bootstrap/package.py: Add doc --- build/sage_bootstrap/package.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/build/sage_bootstrap/package.py b/build/sage_bootstrap/package.py index 0c41c86489f..ca0357b278b 100644 --- a/build/sage_bootstrap/package.py +++ b/build/sage_bootstrap/package.py @@ -335,6 +335,13 @@ def source(self): @property def trees(self): + """ + Return the installation trees for the package + + OUTPUT: + + A white-space-separated string of environment variable names + """ if self.__trees is not None: return self.__trees if self.__install_requires is not None: From 3e5c66b42cd46d714d3e7c33d2321b6ffaa164a5 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 11 Jan 2024 20:59:30 -0800 Subject: [PATCH 5/6] sage --package properties: Add option --format, change default to 'plain' --- build/sage_bootstrap/app.py | 10 ++++++++-- build/sage_bootstrap/cmdline.py | 5 ++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/build/sage_bootstrap/app.py b/build/sage_bootstrap/app.py index c4fda8301c7..28dc3a70d97 100644 --- a/build/sage_bootstrap/app.py +++ b/build/sage_bootstrap/app.py @@ -77,7 +77,8 @@ def list_cls(self, *package_classes, **filters): for pkg_name in pc.names: print(pkg_name) - def properties(self, *package_classes, props=['path', 'version_with_patchlevel', 'type', 'source', 'trees']): + def properties(self, *package_classes, props=['path', 'version_with_patchlevel', 'type', 'source', 'trees'], + format='plain'): """ Show the properties of given packages @@ -92,6 +93,8 @@ def properties(self, *package_classes, props=['path', 'version_with_patchlevel', pc = PackageClass(*package_classes) for package_name in pc.names: package = Package(package_name) + if format == 'plain': + print("{0}:".format(package_name)) for p in props: value = getattr(package, p) if value is None: @@ -99,7 +102,10 @@ def properties(self, *package_classes, props=['path', 'version_with_patchlevel', value = 'none' else: value = '' - print("{0}_{1}='{2}'".format(p, package_name, value)) + if format == 'plain': + print(" {0:28} {1}".format(p + ":", value)) + else: + print("{0}_{1}='{2}'".format(p, package_name, value)) def name(self, tarball_filename): """ diff --git a/build/sage_bootstrap/cmdline.py b/build/sage_bootstrap/cmdline.py index e14759beb5e..5a0364df4e0 100644 --- a/build/sage_bootstrap/cmdline.py +++ b/build/sage_bootstrap/cmdline.py @@ -278,6 +278,9 @@ def make_parser(): type=str, nargs='+', help=('package name or designator for all packages of a given type ' '(one of :all:, :standard:, :optional:, and :experimental:)')) + parser_properties.add_argument( + '--format', type=str, default='plain', + help='output format (one of plain and shell; default: plain)') parser_name = subparsers.add_parser( 'name', epilog=epilog_name, @@ -427,7 +430,7 @@ def run(): include_dependencies=args.include_dependencies, exclude_dependencies=args.exclude_dependencies) elif args.subcommand == 'properties': - app.properties(*args.package_class) + app.properties(*args.package_class, format=args.format) elif args.subcommand == 'name': app.name(args.tarball_filename) elif args.subcommand == 'tarball': From 8ff9e85463978ed5bb34ad706ab9373a0c98f047 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 11 Jan 2024 21:04:17 -0800 Subject: [PATCH 6/6] sage --package properties: Update help --- build/sage_bootstrap/app.py | 2 +- build/sage_bootstrap/cmdline.py | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/build/sage_bootstrap/app.py b/build/sage_bootstrap/app.py index 28dc3a70d97..863c55c7302 100644 --- a/build/sage_bootstrap/app.py +++ b/build/sage_bootstrap/app.py @@ -82,7 +82,7 @@ def properties(self, *package_classes, props=['path', 'version_with_patchlevel', """ Show the properties of given packages - $ sage --package properties maxima + $ sage --package properties --format shell maxima path_maxima='........./build/pkgs/maxima' version_with_patchlevel_maxima='5.46.0' type_maxima='standard' diff --git a/build/sage_bootstrap/cmdline.py b/build/sage_bootstrap/cmdline.py index 5a0364df4e0..f11c26adb28 100644 --- a/build/sage_bootstrap/cmdline.py +++ b/build/sage_bootstrap/cmdline.py @@ -90,8 +90,12 @@ EXAMPLE: $ sage --package properties maxima - version_maxima='5.46.0' - type_maxima='standard' + maxima: + path: /.../build/pkgs/maxima + version_with_patchlevel: 5.46.0 + type: standard + source: normal + trees: SAGE_LOCAL """