Skip to content

Commit

Permalink
install_test_stress: support for cleaning installed version
Browse files Browse the repository at this point in the history
  • Loading branch information
strohel committed Nov 7, 2010
1 parent 513274d commit 84810e0
Showing 1 changed file with 40 additions and 15 deletions.
55 changes: 40 additions & 15 deletions examples/install_test_stress.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@

"""Install PyBayes and run tests and stresses"""

from distutils.dist import Distribution
from distutils.sysconfig import get_python_lib
from optparse import OptionParser
from os import chdir, getcwd
from os.path import abspath, dirname, exists, join, realpath
from string import join as str_join
import os
import shutil
from string import join
from subprocess import call, check_call


def parse_options():
def_pybayes_dir = abspath(dirname(dirname(realpath(__file__))))
def_data_dir = join(def_pybayes_dir, 'examples', 'stress_data')
def_pybayes_dir = os.path.abspath(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
def_data_dir = os.path.join(def_pybayes_dir, 'examples', 'stress_data')

parser = OptionParser(description='Install, test and stress possible multiple ' +
'variants of PyBayes in one go')
Expand All @@ -23,7 +25,11 @@ def parse_options():
parser.add_option('-m', '--mode', dest='modes', action='append', type='choice',
choices=('p', 'c', 'a'),
help='which mode to build & test PyBayes in; may be specified multiple times; ' +
'valid modes are: p[ython], c[ython], a[uto]; default: a')
'valid modes are: p[ython], c[ython], a[uto]; default: -m c -m a')
parser.add_option('-c', '--clean', dest='clean', action='store_true',
default=False, help='clean installed PyBayes before build. May be DANGEROUS as it ' +
'deletes PyBayes directory and everything underneath it; if you mix cython & python ' +
'build, you should however enable this; default: do not remove anything')
parser.add_option('-f', '--force-rebuild', dest='force_rebuild', action='store_true',
default=False, help='force recython & rebuild even if fresh built objects exist; ' +
'default: reuse built objects if up-to-date')
Expand All @@ -45,6 +51,22 @@ def parse_options():
exit(1)
return options

def clean(options):
orig_dir = os.getcwd()
os.chdir(options.pybayes_dir) # so that distutils can source setup.cfg if it exists

dist = Distribution()
dist.parse_config_files()
prefix = dist.get_option_dict("install")["prefix"][1] # get prefix out of parsed options
install_dir = os.path.join(get_python_lib(False, False, prefix), "pybayes") # we don't know if we should use plat_specific or no (depends on previous PyBayes install)
del dist

if os.path.isdir(install_dir):
print "Recursively deleting {0}".format(install_dir)
shutil.rmtree(install_dir)

os.chdir(orig_dir)

def install(mode, options):
modes = {'p':['--use-cython=no'],
'c':['--use-cython=yes'],
Expand All @@ -53,7 +75,7 @@ def install(mode, options):
False:['--profile=no'],
None:[]}

if not exists(options.pybayes_dir):
if not os.path.isdir(options.pybayes_dir):
raise RuntimeError('{0} does not exist!'.format(setup_py))

args = ['./setup.py']
Expand All @@ -65,31 +87,34 @@ def install(mode, options):
commands.append('clean')
commands.append('install')

orig_dir = getcwd()
chdir(options.pybayes_dir)
orig_dir = os.getcwd()
os.chdir(options.pybayes_dir)
for command in commands:
cmdargs = args[:]
cmdargs.append(command)
print(str_join(cmdargs, ' '))
print(join(cmdargs, ' '))
check_call(cmdargs)
chdir(orig_dir)
os.chdir(orig_dir)

def run_tests(options):
run_tests = join(options.pybayes_dir, 'examples', 'run_tests.py')
run_tests = os.path.join(options.pybayes_dir, 'examples', 'run_tests.py')
args = [run_tests]
print(str_join(args, ' '))
print(join(args, ' '))
call(args)

def run_stresses(options):
run_tests = join(options.pybayes_dir, 'examples', 'run_stresses.py')
run_tests = os.path.join(options.pybayes_dir, 'examples', 'run_stresses.py')
args = [run_tests, '-d', options.data_dir]
print(str_join(args, ' '))
print(join(args, ' '))
call(args)

def main():
options = parse_options()

for mode in options.modes:
if options.clean:
clean(options)

install(mode, options)

if options.run_tests:
Expand Down

0 comments on commit 84810e0

Please sign in to comment.