Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
add the sage-pkg entrypoint
Browse files Browse the repository at this point in the history
  • Loading branch information
vbraun committed Jun 21, 2015
1 parent f034a44 commit bd61b67
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 10 deletions.
24 changes: 24 additions & 0 deletions 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.

11 changes: 11 additions & 0 deletions 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()
9 changes: 0 additions & 9 deletions src/sage_bootstrap/sage-bootstrap

This file was deleted.

87 changes: 87 additions & 0 deletions 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 <vbraun.name@gmail.com>
#
# 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

39 changes: 39 additions & 0 deletions 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 <vbraun.name@gmail.com>
#
# 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'))
2 changes: 1 addition & 1 deletion src/sage_bootstrap/setup.py
Expand Up @@ -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',
)

0 comments on commit bd61b67

Please sign in to comment.