From bd61b67c486126af2f90104a3fa8a277facd056a Mon Sep 17 00:00:00 2001 From: Volker Braun Date: Sun, 21 Jun 2015 09:12:36 +0200 Subject: [PATCH] add the sage-pkg entrypoint --- src/sage_bootstrap/README | 24 ++++++ src/sage_bootstrap/bin/sage-pkg | 11 +++ src/sage_bootstrap/sage-bootstrap | 9 -- src/sage_bootstrap/sage_bootstrap/cmdline.py | 87 ++++++++++++++++++++ src/sage_bootstrap/sage_bootstrap/env.py | 39 +++++++++ src/sage_bootstrap/setup.py | 2 +- 6 files changed, 162 insertions(+), 10 deletions(-) create mode 100644 src/sage_bootstrap/README create mode 100755 src/sage_bootstrap/bin/sage-pkg delete mode 100755 src/sage_bootstrap/sage-bootstrap create mode 100644 src/sage_bootstrap/sage_bootstrap/cmdline.py create mode 100644 src/sage_bootstrap/sage_bootstrap/env.py diff --git a/src/sage_bootstrap/README b/src/sage_bootstrap/README new file mode 100644 index 00000000000..9ca5362d73d --- /dev/null +++ b/src/sage_bootstrap/README @@ -0,0 +1,24 @@ +Sage-Bootstrap + +This is a utility libary for dealing with third-party tarballs and +building Sage. You should never import anything from the actual Sage +library here, nor should you import anything from sage_bootstrap into +Sage (because this would reconfigure logging). They must be kept +separate. + +Everything here must support Python 2.6, 2.7, and 3.3+. Use tox to +automatically run the tests with all relevant Python versions. Tests +are written as unittest, not as doctests, because the library is not +meant to be used interactively. Note that the library comes with a +setup.py file so that tox can test it, but it is not meant to be +installed to SAGE_LOCAL. + +Command-line utilities must be able to run as part of a pipe | filter +chain. So you have to be careful about what you send to stdout. You +should use: + +* print() for anything that is meant to be sent to the output pipe. + +* log.info() for human-readable messages about the normal program + flow. + diff --git a/src/sage_bootstrap/bin/sage-pkg b/src/sage_bootstrap/bin/sage-pkg new file mode 100755 index 00000000000..648a34fbbfb --- /dev/null +++ b/src/sage_bootstrap/bin/sage-pkg @@ -0,0 +1,11 @@ +#!/usr/bin/env python + +try: + import sage_bootstrap +except ImportError: + import os, sys + sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..')) + import sage_bootstrap + +from sage_bootstrap.cmdline import SagePkgApplication +SagePkgApplication().run() diff --git a/src/sage_bootstrap/sage-bootstrap b/src/sage_bootstrap/sage-bootstrap deleted file mode 100755 index 92cb7d0b635..00000000000 --- a/src/sage_bootstrap/sage-bootstrap +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env python - -import sage_bootstrap - -print('done') - -from sage_bootstrap.config import Configuration - -print(Configuration()) diff --git a/src/sage_bootstrap/sage_bootstrap/cmdline.py b/src/sage_bootstrap/sage_bootstrap/cmdline.py new file mode 100644 index 00000000000..98a4db6bf37 --- /dev/null +++ b/src/sage_bootstrap/sage_bootstrap/cmdline.py @@ -0,0 +1,87 @@ +# -*- coding: utf-8 -*- +""" +Commandline handling + +Note that argparse is not part of Python 2.6, so we cannot rely on it here. +""" + + +#***************************************************************************** +# Copyright (C) 2015 Volker Braun +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# http://www.gnu.org/licenses/ +#***************************************************************************** + +import os +import sys +import logging +log = logging.getLogger() + + + +class CmdlineSubcommands(object): + + def __init__(self, argv=None): + if argv is None: + argv = sys.argv + if len(argv) == 1: + self.print_help() + sys.exit(0) + self.subcommand = argv[1] + self.extra_args = argv[2:] + + def print_help(self): + from textwrap import dedent + print(dedent(self.__doc__).lstrip()) + + def run(self): + try: + method = getattr(self, 'run_{0}'.format(self.subcommand)) + except AttributeError: + log.error('unknown subcommand: {0}'.format(self.subcommand)) + sys.exit(1) + try: + method(*self.extra_args) + except TypeError as err: + log.error('invalid arguments to the {0} subcommand: {1}' + .format(self.subcommand, self.extra_args)) + sys.exit(1) + + +class SagePkgApplication(CmdlineSubcommands): + """ + sage-pkg + -------- + + The package script is used to manage third-party tarballs. + """ + + def run_config(self): + """ + Print the configuration + """ + from sage_bootstrap.config import Configuration + print(Configuration()) + + def run_list(self): + """ + Print a list of all available packages + """ + pass + + def run_name(self, tarball_filename): + """ + Find the package name given a tarball filename + """ + pass + + def run_tarball(self, package_name): + """ + Find the tarball filename given a package name + """ + pass + diff --git a/src/sage_bootstrap/sage_bootstrap/env.py b/src/sage_bootstrap/sage_bootstrap/env.py new file mode 100644 index 00000000000..ae9c9417e16 --- /dev/null +++ b/src/sage_bootstrap/sage_bootstrap/env.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +""" +Environment Variables + +This module defines the following subset of the Sage environment +variables: + +* ``SAGE_ROOT`` +* ``SAGE_SRC`` +""" + + +#***************************************************************************** +# Copyright (C) 2015 Volker Braun +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# http://www.gnu.org/licenses/ +#***************************************************************************** + +import os + + + +try: + SAGE_SRC = os.environ['SAGE_SRC'] +except KeyError: + SAGE_SRC = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) + +try: + SAGE_ROOT = os.environ['SAGE_ROOT'] +except KeyError: + SAGE_ROOT = os.path.dirname(SAGE_SRC) + + +assert os.path.isfile(os.path.join(SAGE_ROOT, 'configure.ac')) +assert os.path.isfile(os.path.join(SAGE_SRC, 'sage_bootstrap', 'setup.py')) diff --git a/src/sage_bootstrap/setup.py b/src/sage_bootstrap/setup.py index 1509a4c3bc5..ce8727c98f5 100755 --- a/src/sage_bootstrap/setup.py +++ b/src/sage_bootstrap/setup.py @@ -8,7 +8,7 @@ author='Volker Braun', author_email='vbraun.name@gmail.com', packages=['sage_bootstrap'], - scripts=['sage-bootstrap'], + scripts=['sage-pkg'], version='1.0', url='https://www.sagemath.org', )