Ticket #10176: 10176_combined.patch

File 10176_combined.patch, 10.1 KB (added by jdemeyer, 11 years ago)

SAGENB patch, replaces all previous

  • sdist

    # HG changeset patch
    # User Jeroen Demeyer <jdemeyer@cage.ugent.be>
    # Date 1292487166 -3600
    # Node ID 46df517bfee802183051dd877afd6c1dc7db1f77
    # Parent  db88b573c08e017dc1c581377cbff2508326611f
    [mq]: 10176
    
    diff -r db88b573c08e -r 46df517bfee8 sdist
    a b  
    1 #!/bin/bash
    2 set -e
     1#!/usr/bin/env bash
    32
     3# Just curious: *Which* 'sage' is supposed to be called here?
     4# Should we check if SAGE_LOCAL or SAGE_ROOT is defined?
     5# ... and perhaps call $SAGE_ROOT/sage or $SAGE_LOCAL/bin/...? -leif
     6
     7# At least check that 'sage' is in the path to specifically catch
     8# one potential error [earlier, with an appropriate error message]:
     9if ! command -v sage >/dev/null; then
     10    echo >&2 "Error: $0 requires 'sage' to be in your PATH"
     11    echo >&2 "Maybe first call 'SAGE_ROOT/sage -sh'"
     12    exit 1
     13fi
     14
     15echo "Trying to commit changes (if any)..."
    416sage -hg ci
     17status=$?
     18if [ $status -eq 1 ]; then
     19    # 'hg ci' returns 1 (!) if there are no changes to commit...
     20    echo "No changes to commit (not an error)"
     21elif [ $status -ne 0 ]; then
     22    echo >&2 "Error: $0: Couldn't commit changes" \
     23             "('hg ci' failed with exit code $status)"
     24    exit 1
     25else
     26    # $status == 0
     27    echo "Successfully committed the changes"
     28fi
    529
     30echo "Running 'python setup.py sdist'..."
    631sage -python setup.py sdist
     32if [ $? -ne 0 ]; then
     33    echo >&2 "Error: $0: 'python setup.py sdist' failed"
     34    exit 1
     35fi
     36
    737
    838echo "**********************************************************"
    939echo "* If this is an official SageNB release, don't forget to *"
  • setup.py

    diff -r db88b573c08e -r 46df517bfee8 setup.py
    a b  
    55import os, sys, time
    66from setuptools import setup
    77
     8
     9import distutils.log
     10
     11if os.environ.get("SAGE_SETUPTOOLS_DEBUG","no")=="yes":
     12    distutils.log.set_threshold(distutils.log.DEBUG)
     13
     14
    815def all_files(dir, lstrip):
    916    """
    1017    Return list of all filenames in the given directory, with lstrip
  • spkg-dist

    diff -r db88b573c08e -r 46df517bfee8 spkg-dist
    a b  
    11#!/usr/bin/env python
    22# Create a new Sage Notebook spkg.
    33
     4# Since the 'sdist' shell script called below requires (at least) 'sage'
     5# to be in the path, we could equally check *here* if it is; SAGE_ROOT
     6# or SAGE_LOCAL don't have to be set, since 'sdist' calls 'sage -hg ...'
     7# and 'sage -python ...'.
     8# (We also later run 'sage -pkg ...' from *this* script.)
     9#
     10# We *might* get import errors earlier if some system-wide Python executes
     11# this script (which is probably not intended), so we could really check
     12# here first if SAGE_LOCAL is defined, which is a strong indication that
     13# we're actually using Sage's Python. -leif
     14
    415import os
    516import sys
    617import stat
     
    1324from setuptools.package_index import PackageIndex
    1425
    1526# Get the version from setup.py.
    16 version_line = [f for f in open('setup.py').readlines() if 'version' in f][0]
     27try:
     28    version_line = [f for f in open('setup.py').readlines() if 'version' in f][0]
     29except IndexError:
     30    sys.stderr.write("Error: Found no version string in 'setup.py'\n")
     31    sys.exit(1)
    1732i = version_line.find("'")
    1833j = version_line.rfind("'")
     34if i==-1 or j==-1 or j-i<3:
     35    sys.stderr.write(
     36      "Error: Illegal version string in 'setup.py':\n    %s\n" % version_line)
     37    sys.stderr.write("Perhaps no single quotes used?\n")
     38    sys.exit(1)
    1939version = version_line[i + 1:j]
     40print "New SageNB version: %s" % version
    2041
    2142# Create the source distribution.
     43print "Creating the new source tarball..."
     44sys.stdout.flush()
    2245proc = subprocess.Popen([os.path.join(os.path.curdir, 'sdist')], shell=True)
    2346if proc.wait():
    24     print "Uncommitted changes in repository.  Stopping."
     47    # The previous error message was most probably inadequate, since
     48    # 'sdist' tries to commit any changes, and 'hg ci' returns 1 (!) (which
     49    # usually indicates an error) if there are *no changes to commit*.
     50    # The other potential error in 'sdist' was that 'python setup.py sdist'
     51    # failed, in which case the error message would have also been wrong.
     52    #print "Uncommitted changes in repository.  Stopping."
     53    sys.stderr.write(
     54      "Error: './sdist' failed. See message(s) above for the specific error.\n")
    2555    sys.exit(1)
    2656
    2757# Create the spkg.
     
    3161    shutil.rmtree(path)
    3262os.makedirs(path)
    3363
    34 file = 'sagenb-%s.tar.gz' % version
    35 print "Extracting %s" % file
     64file = 'sagenb-%s.tar.gz' % version # created by 'sdist' above
     65print "Extracting %s..." % file
     66sys.stdout.flush()
    3667t = tarfile.open(os.path.join('dist', file))
    3768t.extractall(path)
     69print "Finished extraction."
     70sys.stdout.flush()
    3871
    39 os.chdir(path)
     72os.chdir(path) # cd dist/sagenb-x.y.z
    4073os.mkdir('src')
    41 shutil.move(base, os.path.join('src', 'sagenb'))
     74print "Moving new source tree..."
     75sys.stdout.flush()
     76shutil.move(base, os.path.join('src', 'sagenb')) # mv sagenb-x.y.z src/sagenb
    4277
     78print "Copying 'SPKG.txt'..."
     79sys.stdout.flush()
     80shutil.copy(os.path.join(os.path.pardir, os.path.pardir, 'SPKG.txt'),
     81            os.path.curdir) # cp ../../SPKG.txt . (which is dist/sagenb-x.y.z)
     82
     83print "Creating 'spkg-install'..."
     84sys.stdout.flush()
    4385spkg_install = os.path.abspath(os.path.join(os.path.curdir, 'spkg-install'))
    4486spkg_install_fd = open(spkg_install, 'w')
    45 spkg_install_fd.write("cd src\n")
    46 
    47 shutil.copy(os.path.join(os.path.pardir, os.path.pardir, 'SPKG.txt'),
    48             os.path.curdir)
    49 
    5087
    5188
    5289def fetch_packages():
    5390    # This block is here in case we ever need it again.
     91    # XXX Then also make sure the easy_install commands
     92    # XXX get written to the correct part of spkg-install!
     93    # XXX (We currently use a single string for the whole file.)
    5494    print "Fetching the required packages"
    5595    pkg_index = PackageIndex()
    5696
    5797    tmp_dir = mkdtemp()
    5898
    59 
    6099    required_packages = ()
    61100
    62101    pkg_locations = []
     
    73112
    74113    return [os.path.basename(location) for location in pkg_locations]
    75114
    76 os.chdir(os.path.pardir)
    77115
    78 spkg_install_fd.write("""
     116os.chdir(os.path.pardir) # cd .. (now in dist/)
     117
     118# Write the whole file from a single raw Python string:
     119# (The #! has to be on the first line of the script.)
     120spkg_install_fd.write(
     121r"""#!/usr/bin/env bash
     122
     123# spkg-install for SageNB, generated by SageNB's spkg-dist
     124
     125if [ -z "$SAGE_LOCAL" ]; then
     126    echo >&2 "SAGE_LOCAL undefined - exiting..."
     127    exit 1
     128fi
     129
     130cd src
     131
    79132cd sagenb
    80133python setup.py install
    81 
    82 mkdir -p "$SAGE_ROOT/devel"
    83 
    84 echo "Copying SageNB package to '$SAGE_ROOT/devel/sagenb-main'."
    85 if [ -d "$SAGE_ROOT/devel/sagenb-main" ]; then
    86   echo "Copying old SageNB package to '$SAGE_ROOT/devel/sagenb-main-old'."
    87   rm -rf "$SAGE_ROOT/devel/sagenb-main-old"
    88   cp -pr "$SAGE_ROOT/devel/sagenb-main" "$SAGE_ROOT/devel/sagenb-main-old"
     134if [ $? -ne 0 ]; then
     135    echo >&2 "Error running 'setup.py install'."
     136    exit 1
    89137fi
    90138
    91 rm -f "$SAGE_ROOT/devel/sagenb"
     139mkdir -p "$SAGE_ROOT/devel" # Create if it doesn't already exist
     140if [ $? -ne 0 ]; then
     141    echo >&2 "Error creating '$SAGE_ROOT/devel'."
     142    exit 1
     143fi
    92144
    93 cd ..
    94 cp -pr sagenb "$SAGE_ROOT/devel/sagenb-main"
     145echo "Copying SageNB package to '$SAGE_ROOT/devel/sagenb-main'..."
     146
     147if [ -d "$SAGE_ROOT/devel/sagenb-main" ]; then
     148    echo "Moving old SageNB package to '$SAGE_ROOT/devel/sagenb-main-old'..."
     149    rm -rf "$SAGE_ROOT/devel/sagenb-main-old"
     150    mv "$SAGE_ROOT/devel/sagenb-main" "$SAGE_ROOT/devel/sagenb-main-old"
     151    if [ $? -ne 0 ]; then
     152        echo >&2 "Error moving the old 'sagenb-main' branch."
     153        exit 1
     154    fi
     155fi
     156
     157rm -f "$SAGE_ROOT/devel/sagenb" # Delete just the link itself (if it exists)
     158
     159cd .. # Back to sagenb-x.y.z/src/
     160cp -pr sagenb "$SAGE_ROOT/devel/sagenb-main" # Creates new sagenb-main dir
     161if [ $? -ne 0 ]; then
     162    echo >&2 "Error copying the new SageNB package."
     163    exit 1
     164fi
    95165
    96166cd "$SAGE_ROOT/devel"
    97 ln -snf sagenb-main sagenb
     167ln -s sagenb-main sagenb # Create new symbolic link (deleted above)
     168if [ $? -ne 0 ]; then
     169    echo >&2 "Error creating symbolic link to '$SAGE_ROOT/devel/sagenb-main'."
     170    exit 1
     171fi
    98172
    99173# We use relative paths for relocatability.
    100174cd "$SAGE_ROOT/devel/sagenb"
    101175python setup.py develop --egg-path ../../../../devel/sagenb
     176if [ $? -ne 0 ]; then
     177    echo >&2 "Error running 'setup.py develop'."
     178    exit 1
     179fi
    102180
    103181cd "$SAGE_ROOT/local/lib/python/site-packages"
    104 sed 's/^.*sagenb.*$/..\/..\/..\/..\/devel\/sagenb/' easy-install.pth > easy-install.pth.new
    105 mv -f easy-install.pth.new easy-install.pth
     182# Dave says Solaris' non-POSIX grep in the default path
     183# doesn't understand "-q" (which *is* POSIX):
     184if ! grep sagenb easy-install.pth >/dev/null; then
     185    # Ugly work-around, we haven't found the real cause yet (see #10176):
     186    echo "No sagenb path found in 'easy-install.pth'"'!'
     187    echo "Adding relative sagenb path to 'easy-install.pth'..."
     188    sed -e '$ i \../../../../devel/sagenb' easy-install.pth > easy-install.pth.$$
     189    if [ $? -ne 0 ]; then
     190        echo >&2 "Error adding relative sagenb path to 'easy-install.pth'."
     191        exit 1
     192    fi
     193else
     194    echo "Making sagenb path in 'easy-install.pth' relative..."
     195    sed 's/^.*sagenb.*$/..\/..\/..\/..\/devel\/sagenb/' easy-install.pth > easy-install.pth.$$
     196    if [ $? -ne 0 ]; then
     197        echo >&2 "Error patching 'easy-install.pth' to have relative path to SageNB."
     198        exit 1
     199    fi
     200fi
     201if true; then # Aids debugging (cf. #10176)
     202    echo "Old path: \"`grep sagenb easy-install.pth`\""
     203    echo "New path: \"`grep sagenb easy-install.pth.$$`\""
     204fi
     205# The following fails only on wrong file permissions etc.:
     206mv -f easy-install.pth.$$ easy-install.pth
     207if [ $? -ne 0 ]; then
     208    echo >&2 "Error overwriting original 'easy-install.pth'."
     209    exit 1
     210fi
    106211""")
    107212spkg_install_fd.close()
    108213os.chmod(spkg_install, stat.S_IRWXU | stat.S_IRGRP | stat.S_IXGRP |
    109          stat.S_IROTH | stat.S_IXOTH)
     214         stat.S_IROTH | stat.S_IXOTH) # -rwxr-xr-x
    110215
     216# We are still in dist/, now package sagenb-x.y.z/ :
     217print "Running 'sage -pkg %s'..."%base
     218sys.stdout.flush()
    111219subprocess.call(['sage -pkg ' + base], shell=True)
     220# XXX Perhaps also check exit code here... (but 'sage -pkg' is verbose)
     221